protected void Dispose(bool disposing) { if (this.isDisposed) { return; } OpenAL.DebugFormat("Freeing OpenALPlaybackProvider. Disposing: ", disposing); if (disposing) { this.pool.Dispose(); if (this.device != null) { this.device.Dispose(); } } SourceBuffer.Clear(); OpenALRunner.RemoveUser(); OpenALRunner.RemovePlaybackProvider(this); this.pool = null; this.device = null; this.isDisposed = true; }
public void QueuePlayback(AudioSource audioSource, byte[] data) { if (this.isDisposed) { throw new ObjectDisposedException("OpenALPlaybackProvider"); } if (audioSource == null) { throw new ArgumentNullException("audioSource"); } Stack <SourceBuffer> bufferStack; if (!this.buffers.TryGetValue(audioSource, out bufferStack)) { this.buffers[audioSource] = bufferStack = new Stack <SourceBuffer>(); } lock (this.pool.SyncRoot) { Source source = this.pool.RequestSource(audioSource); Tuple <float, float> gain; if (this.gains.TryGetValue(audioSource, out gain)) { source.Gain = gain.Item2; } else { source.Gain = this.normalGain; } const int bufferLen = 4; if (data.Length == 0) { return; } if (!source.IsPlaying) { OpenAL.DebugFormat("{0} bound to {1} isn't playing, inserting silent buffers", audioSource, source); RequireBuffers(bufferStack, source, bufferLen); for (int i = 0; i < bufferLen; ++i) { OpenALAudioFormat format = audioSource.CodecSettings.ToOpenALFormat(); SourceBuffer wait = bufferStack.Pop(); wait.Buffer(new byte[format.GetBytes((uint)audioSource.CodecSettings.FrameSize)], format, (uint)audioSource.CodecSettings.SampleRate); source.QueueAndPlay(wait); } } RequireBuffers(bufferStack, source, 1); SourceBuffer buffer = bufferStack.Pop(); buffer.Buffer(data, audioSource.CodecSettings.ToOpenALFormat(), (uint)audioSource.CodecSettings.SampleRate); source.QueueAndPlay(buffer); } }
public void FreeSource(AudioSource source) { if (this.isDisposed) { throw new ObjectDisposedException("OpenALPlaybackProvider"); } if (source == null) { throw new ArgumentNullException("source"); } OpenAL.DebugFormat("Freeing source {0}", source); lock (this.gains) this.gains = this.gains.Where(kvp => kvp.Key != source).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); buffers.Remove(source); pool.FreeSource(source); }
protected void Dispose (bool disposing) { if (this.disposed) return; OpenAL.DebugFormat ("Freeing OpenALCaptureProvider. Disposing: {0}", disposing); if (disposing) { if (IsCapturing) EndCapture(); if (this.device != null) this.device.Dispose(); } this.device = null; this.disposed = true; }