public override bool IsPlaying() { AlNative.alGetSourcei(_source, AlNative.AL_SOURCE_STATE, out int state); bool playing = state == AlNative.AL_PLAYING; return(playing); }
protected override void PlatformDispose() { mutex.WaitOne(); if (usingResource == 1) { if (_context != IntPtr.Zero) { AlNative.alcSuspendContext(_context); checkAlcError(); } AlNative.alcMakeContextCurrent(IntPtr.Zero); checkAlcError(); if (_context != IntPtr.Zero) { AlNative.alcDestroyContext(_context); checkAlcError(); _context = IntPtr.Zero; AlNative.alcCloseDevice(_device); checkAlcError(); _device = IntPtr.Zero; } usingResource = 0; } mutex.ReleaseMutex(); }
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 void QueueBuffer(AudioBuffer buffer) { RemoveProcessed(); var alBuffer = (ALBuffer)buffer; AlNative.alSourceQueueBuffers(_source, 1, new uint[] { alBuffer.Buffer }); ALEngine.checkAlError(); }
private void checkAlcError() { int error = AlNative.alcGetError(_device); if (error != AlNative.ALC_NO_ERROR) { throw new SharpAudioException("OpenAL Error: " + error); } }
internal static void checkAlError() { int error = AlNative.alGetError(); if (error != AlNative.AL_NO_ERROR) { throw new SharpAudioException("OpenAL Error: " + error); } }
protected override void PlatformDispose() { AlNative.alcMakeContextCurrent((IntPtr)0); checkAlcError(); AlNative.alcDestroyContext(_context); checkAlcError(); AlNative.alcCloseDevice(_device); checkAlcError(); }
public ALEngine(AudioEngineOptions options) { _device = AlNative.alcOpenDevice(null); checkAlcError(); _context = AlNative.alcCreateContext(_device, null); checkAlcError(); AlNative.alcMakeContextCurrent(_context); checkAlcError(); _floatSupport = AlNative.alIsExtensionPresent("AL_EXT_FLOAT32"); }
private void checkAlcError() { int error = AlNative.alcGetError(_device); if (error != AlNative.ALC_NO_ERROR) { string formatErrMsg = string.Format("OpenALc Error: {0} - {1}", Marshal.PtrToStringAuto(AlNative.alcGetString(_device, error)), AlNative.alcGetCurrentContext().ToString()); throw new SharpAudioException(formatErrMsg); } }
internal static void checkAlError() { int error = AlNative.alGetError(); if (error != AlNative.AL_NO_ERROR) { string formatErrMsg = string.Format("OpenAL Error: {0} - {1}", Marshal.PtrToStringAuto(AlNative.alGetString(error)), AlNative.alcGetCurrentContext().ToString()); throw new SharpAudioException(formatErrMsg); } }
public ALCapture(AudioCaptureOptions options) { mutex.WaitOne(); usingResource++; if (usingResource == 1) { // opens the default device. _device = AlNative.alcCaptureOpenDevice(null, (uint)options.SampleRate, AlNative.AL_FORMAT_MONO16, 128); checkAlcError(); } mutex.ReleaseMutex(); }
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 ALEngine(AudioEngineOptions options) { mutex.WaitOne(); usingResource++; if (usingResource == 1) { int[] argument = new int[] { AlNative.ALC_FREQUENCY, options.SampleRate }; // opens the default device. _device = AlNative.alcOpenDevice(null); checkAlcError(); _context = AlNative.alcCreateContext(_device, argument); checkAlcError(); // AlNative.alcMakeContextCurrent(_context); checkAlcError(); _floatSupport = AlNative.alIsExtensionPresent("AL_EXT_FLOAT32"); checkAlError(); } mutex.ReleaseMutex(); }
public override void Dispose() { AlNative.alDeleteBuffers(1, new uint[] { Buffer }); }
public override void Dispose() { AlNative.alDeleteBuffers(1, new uint[] { Buffer }); ALEngine.checkAlError(); }
public override void Stop() { AlNative.alSourceStop(_source); ALEngine.checkAlError(); }
protected override void PlatformDispose() { AlNative.alcDestroyContext(_context); AlNative.alcCloseDevice(_device); }
public override void Play() { AlNative.alSourcePlay(_source); 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.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(); }