Playing WAV with BufferedWaveProvider

Dec 30, 2010 at 11:50 AM


i try to use the BufferedWaveProvider to play adio data received from network.

Everytime when i am recieving data i call AddSamples to add a new audio block to the queue. But it doesnt play.

The Read method of BufferedWaveProvider is only called 3 times. After having called AddSamples 100 time i get the Exception

"Too many queued buffers".

The waveformat is 8000, 16, 1.

So no buffer is dequed.

Why does this happen?






Dec 30, 2010 at 11:53 AM


Can you please post the code you are trying to use?


Dec 30, 2010 at 12:02 PM


i will post the Init and the AddSamples-Part. The whole File would be too large:

public static BufferedWaveProvider PlayBuffer;

public static WaveOut waveOut;


/* Init Part */

// BufferedWaveProvider

PlayBuffer = new BufferedWaveProvider(new WaveFormat(8000, 16, 1));

// waveOut

waveOut = new WaveOut();




/* Method which is called when data from network is Received */

// recbuffer contains alsways 1600 bytes pf pcm data with the waveformat 8000,16,1

PlayBuffer.AddSamples(recbuffer, 0, recbuffer.Length);












Dec 30, 2010 at 12:17 PM
Edited Dec 30, 2010 at 12:18 PM

Hi Tobias,

I wrote an enhanced version of BufferedWaveProvider, but I encountered the same problem you are facing.

Basically, the BufferedWaveProvider has an upper limit on the number of buffers it is holding.

It is a typical producer-consumer problem.

If you produce too many buffers, then the consumer (BufferedWaveProvider) can't hold them.

You could change it to a higher value, but it is not really a good solution as (1) it might still break (2) it wastes lots of memory (3) is raises the latency (response time) of the playback

The correct solution, IMO, is to only add buffers to the queue when the queue is not full.

When the queue is full then the client simply doesn't add buffers.

You could look at how I implemented it in my application (Practice#).

I have a dedicated audio processing thread that keeps producing buffer, and adds them to AdvancedBufferedWaveProvider only when needed.

Edit: Of course make sure you actually start playing...otherwise indeed the buffer would never get dequeued, with or without queue monitoring logic.



Dec 30, 2010 at 12:20 PM
Edited Dec 30, 2010 at 12:24 PM

Hi Yuval,


thanks for your help. I have already increased the number of buffers.

But this is not my main problem. i can avoid this.

But why is the Read method of BufferedWaveProvider not periodically called? Only three times and then it stops?





BTW: your practicesharp looks really cool

Dec 30, 2010 at 12:26 PM

probably you are using a windowed callback with a console application. try using function callbacks


Dec 30, 2010 at 12:38 PM

Hi Mark,


I didnt pass the window handle to my waveout device (the device is created in a thread context).

This solved the problem.