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); } }
/// <summary> /// Opens the capture device with the specified <paramref name="frequency"/> and <paramref name="format"/>. /// </summary> /// <param name="frequency">The frequency to open the capture device with.</param> /// <param name="format">The audio format to open the device with.</param> /// <returns>Returns <c>this</c>.</returns> public CaptureDevice Open(uint frequency, OpenALAudioFormat format) { ThrowIfDisposed(); OpenAL.DebugFormat("Opening capture device {0} at {1} {2}", Name, frequency, format); this.Format = format; this.Frequency = frequency; uint bufferSize = format.GetBytes(format.GetSamplesPerSecond(frequency)) * 2; this.Handle = alcCaptureOpenDevice(this.Name, frequency, format, (int)bufferSize); OpenAL.ErrorCheck(this); pcm = new byte[bufferSize]; return(this); }
/// <summary> /// Opens the capture device with the specified <paramref name="frequency"/> and <paramref name="format"/>. /// </summary> /// <param name="frequency">The frequency to open the capture device with.</param> /// <param name="format">The audio format to open the device with.</param> /// <returns>Returns <c>this</c>.</returns> public CaptureDevice Open(uint frequency, OpenALAudioFormat format) { ThrowIfDisposed(); OpenAL.DebugFormat ("Opening capture device {0} at {1} {2}", Name, frequency, format); this.Format = format; this.Frequency = frequency; uint bufferSize = format.GetBytes (format.GetSamplesPerSecond (frequency)) * 2; this.Handle = alcCaptureOpenDevice (this.Name, frequency, format, (int)bufferSize); OpenAL.ErrorCheck (this); pcm = new byte[bufferSize]; return this; }