76c2f5a9de
(-> future method for converting tiles -> V3 values)
229 lines
4.1 KiB
C#
229 lines
4.1 KiB
C#
using System;
|
|
using System.Threading;
|
|
//using System.Threading.Tasks;
|
|
using OpenTK;
|
|
using OpenTK.Audio;
|
|
using OpenTK.Audio.OpenAL;
|
|
|
|
|
|
|
|
namespace nhengine.Audio
|
|
{
|
|
public class nhPlayer
|
|
{
|
|
|
|
private int _source = AL.GenSource();
|
|
public int source
|
|
{
|
|
get
|
|
{return _source;}
|
|
}
|
|
|
|
|
|
private static int _playerNumber;
|
|
public int number
|
|
{
|
|
get
|
|
{ return _playerNumber;}
|
|
}
|
|
|
|
//private static EffectsExtension _efx;
|
|
//private int _filter;
|
|
|
|
|
|
|
|
private float _gain = 1.0f;
|
|
public float gain
|
|
{
|
|
set
|
|
{
|
|
if (value <= 0.0f)
|
|
{
|
|
_gain = 0.0f;
|
|
}
|
|
else if (value >= 1.0f)
|
|
{
|
|
_gain = 1.0f;
|
|
}else
|
|
{
|
|
_gain = value;
|
|
}
|
|
}
|
|
get
|
|
{return _gain;}
|
|
}
|
|
|
|
public Vector3 position = new Vector3(0.0f, 0.0f, 0.0f);
|
|
public Vector3 velocity = new Vector3(0.0f, 0.0f, 0.0f);
|
|
//public bool loop = false;
|
|
|
|
private float _rollOf = 2.0f;
|
|
private float _refDist = 0.0f;
|
|
private float _maxDist = 100.0f;
|
|
|
|
|
|
private int _state;
|
|
|
|
|
|
//private int[] _seqBuffer = { };
|
|
|
|
|
|
|
|
public nhPlayer()
|
|
{
|
|
|
|
//_filter = _efx.GenFilter();
|
|
//_efx.BindFilterToSource(_source, _filter);
|
|
|
|
AL.Source(_source, ALSourcef.RolloffFactor, _rollOf);
|
|
AL.Source(_source, ALSourcef.ReferenceDistance, _refDist);
|
|
AL.Source(_source, ALSourcef.MaxDistance, _maxDist);
|
|
//AL.Source(_source, ALSourcei.EfxDirectFilter, _filter);
|
|
//AL.Source(_source, ALSourcei.EfxDirectFilter, )
|
|
|
|
|
|
//_filterEfx.Filter(_filter, EfxFilteri.FilterType, EfxFilterType.Lowpass);
|
|
//_efx.Filter(_filter, EfxFilterf.LowpassGainHF, 0.5f);
|
|
Interlocked.Increment(ref _playerNumber);
|
|
|
|
}
|
|
|
|
|
|
//>>>>>>>>>>>>>>>>>METHODS
|
|
|
|
public bool state()
|
|
{
|
|
AL.GetSource(_source, ALGetSourcei.SourceState, out _state);
|
|
|
|
if ((ALSourceState)_state == ALSourceState.Playing)
|
|
{
|
|
return true;
|
|
}else if((ALSourceState)_state == ALSourceState.Stopped)
|
|
{
|
|
return false;
|
|
}else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
|
|
}
|
|
public void play(int buffer = 0, float gain = 1.0f, bool loop = false)
|
|
{
|
|
|
|
_gain = gain;
|
|
AL.Source(_source, ALSourcef.RolloffFactor, _rollOf);
|
|
AL.Source(_source, ALSourcef.ReferenceDistance, _refDist);
|
|
AL.Source(_source, ALSourcef.MaxDistance, _maxDist);
|
|
|
|
if (buffer != 0)
|
|
{
|
|
AL.Source(_source, ALSourcei.Buffer, buffer);
|
|
}else{
|
|
throw new NotSupportedException("Not existing Buffer.");
|
|
}
|
|
|
|
AL.Source(_source, ALSourceb.Looping, loop);
|
|
AL.SourcePlay(_source);
|
|
AL.Source(_source, ALSourcef.Gain, _gain);
|
|
AL.Source(_source, ALSource3f.Position, position.X, position.Y, position.Z);
|
|
AL.Source(_source, ALSource3f.Velocity, velocity.X, velocity.Y, velocity.Z);
|
|
|
|
}
|
|
|
|
|
|
public void stop()
|
|
{
|
|
AL.SourceStop(_source);
|
|
}
|
|
|
|
public void setDistanceAttenuation(float rollOf = 2.0f, float refDistance = 1.0f, float maxDistance = 100.0f)
|
|
{
|
|
_rollOf = rollOf;
|
|
_refDist = refDistance;
|
|
_maxDist = maxDistance;
|
|
}
|
|
|
|
public void setPosition(Vector3 position)
|
|
{
|
|
this.position = position;
|
|
}
|
|
|
|
public void setVelocity(Vector3 velocity)
|
|
{
|
|
this.velocity = velocity;
|
|
}
|
|
|
|
|
|
/*
|
|
|
|
|
|
public void playSeq(int buffer01, int buffer02, int buffer03)
|
|
{
|
|
_seqBuffer[0] = buffer01;
|
|
_seqBuffer[1] = buffer02;
|
|
_seqBuffer[2] = buffer03;
|
|
|
|
Thread _playThread = new Thread(_playSeq);
|
|
_playThread.Start();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void _playSeq()
|
|
{
|
|
|
|
|
|
int _buffersToProcess = 3;
|
|
|
|
AL.Source(_source, ALSourcei.Buffer, _buffer);
|
|
AL.Source(_source, ALSourceb.Looping, loop);
|
|
|
|
AL.SourceQueueBuffers(_source, 3, _seqBuffer);
|
|
|
|
|
|
AL.SourcePlay(_source);
|
|
//_isplaying = true;
|
|
|
|
AL.Source(_source, ALSourcef.Gain, _gain);
|
|
AL.Source(_source, ALSource3f.Position, position[0], position[1], position[2]);
|
|
AL.Source(_source, ALSource3f.Velocity, velocity[0], velocity[1], velocity[2]);
|
|
|
|
|
|
do
|
|
{
|
|
Thread.Sleep(16);
|
|
AL.GetSource(_source, ALGetSourcei.SourceState, out _state);
|
|
AL.GetSource(_source, ALGetSourcei.BuffersProcessed, out _buffersToProcess);
|
|
|
|
while(_buffersToProcess != 0)
|
|
{
|
|
//AL.SourceUnqueueBuffers(_source, 1, );
|
|
}
|
|
|
|
}
|
|
while ((ALSourceState)_state == ALSourceState.Playing);
|
|
|
|
|
|
AL.SourceStop(_source);
|
|
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
public void deletePlayer()
|
|
{
|
|
AL.DeleteSource(_source);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|