public override void SetSourcePosition(AudioSource source, Vector3 position) { ALSource alSource = (ALSource)source; AlNative.alSource3f(alSource._source, AlNative.AL_POSITION, position.X, position.Y, position.Z); ALEngine.checkAlError(); }
public ALBuffer() { var buffers = new uint[1]; AlNative.alGenBuffers(1, buffers); ALEngine.checkAlError(); Buffer = buffers[0]; }
public ALSource() { var sources = new uint[1]; AlNative.alGenSources(1, sources); ALEngine.checkAlError(); _source = sources[0]; }
public override bool IsPlaying() { AlNative.alGetSourcei(_source, AlNative.AL_SOURCE_STATE, out int state); ALEngine.checkAlError(); bool playing = state == AlNative.AL_PLAYING; return(playing); }
public override void QueueBuffer(AudioBuffer buffer) { RemoveProcessed(); var alBuffer = (ALBuffer)buffer; AlNative.alSourceQueueBuffers(_source, 1, new uint[] { alBuffer.Buffer }); ALEngine.checkAlError(); }
private void RemoveProcessed() { //before querying new data check if sth was processed already: AlNative.alGetSourcei(_source, AlNative.AL_BUFFERS_PROCESSED, out int processed); ALEngine.checkAlError(); while (processed > 0) { var bufs = new uint[] { 1 }; AlNative.alSourceUnqueueBuffers(_source, 1, bufs); processed--; } }
public override unsafe void BufferData(IntPtr ptr, int sizeInBytes, AudioFormat format) { int fmt = (format.Channels == 2) ? AlNative.AL_FORMAT_STEREO8 : AlNative.AL_FORMAT_MONO8; if (format.BitsPerSample == 16) { fmt++; } AlNative.alBufferData(Buffer, fmt, ptr, sizeInBytes, format.SampleRate); ALEngine.checkAlError(); _format = format; }
public override unsafe void BufferData <T>(T[] buffer, AudioFormat format) { int fmt = (format.Channels == 2) ? AlNative.AL_FORMAT_STEREO8 : AlNative.AL_FORMAT_MONO8; int sizeInBytes = sizeof(T) * buffer.Length; if (format.BitsPerSample == 16) { fmt++; } var handle = GCHandle.Alloc(buffer); IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0); AlNative.alBufferData(_buffer, fmt, ptr, sizeInBytes, format.SampleRate); ALEngine.checkAlError(); handle.Free(); _format = format; }
public ALSubmixer(ALEngine engine) { }
public override void Stop() { AlNative.alSourceStop(_source); ALEngine.checkAlError(); }
public override void Play() { AlNative.alSourcePlay(_source); ALEngine.checkAlError(); }
public override void Dispose() { AlNative.alDeleteSources(1, new uint[] { _source }); ALEngine.checkAlError(); }
public override void SetListenerOrientation(Vector3 top, Vector3 front) { float[] listenerOri = new float[] { front.X, front.Y, front.Z, top.X, top.Y, top.Z }; AlNative.alListenerfv(AlNative.AL_ORIENTATION, listenerOri); ALEngine.checkAlError(); }
public override void SetListenerPosition(Vector3 position) { AlNative.alListener3f(AlNative.AL_POSITION, position.X, position.Y, position.Z); ALEngine.checkAlError(); }
public override void Dispose() { AlNative.alDeleteBuffers(1, new uint[] { Buffer }); ALEngine.checkAlError(); }