This project has moved. For the latest updates, please go here.

Changes to BufferedWaveProvider for my real-time audio streaming

Mar 20, 2011 at 6:51 PM

Hi all!

Here are some minor changes that i've implemented to BufferedWaveProvider in order to obtain a better performance for my real-time audio streaming:

1 - Add a new property called DiscardOverrunedBuffers.

/// <summary>
/// Whether we should discard the overruned buffers in order to get lower latency.
/// </summary>
public bool DiscardOverrunedBuffers { get; set; }

2 - Use this property whithin the AddBuffers method, replacing the line:

throw new InvalidOperationException("Too many queued buffers");

by these lines:

if (DiscardOverrunedBuffers)
        this.queue.Dequeue();
else
        throw new InvalidOperationException("Too many queued buffers");

That's it! Now you just need to set the DiscardOverrunedBuffers = true and adjust the property MaxQueuedBuffers accordingly to your needs and then the audio will never get more delayed than your "max queued buffers" (the actual time may vary accordingly to the wave format that you're using). Please notice that some chunks may get lost using this technique. Although, I've achieved VERY nice results using this modification.

Coordinator
Mar 21, 2011 at 5:08 PM

I like this idea, thanks for sharing.

Coordinator
Apr 9, 2011 at 7:37 AM

its in the latest source code