I suspect that calling Waveout.Play()
multiple times is the problem. You only need to call Play()
once, then feed samples into the source wave provider (your BufferedWaveProvider
instance) and the library will take care of the rest. When the wave provider is empty the WaveOut
object will continue to play silence until you provide more samples.
This can all be achieved in a single thread, incidentally. Create the WaveOut
instance, create a BufferedWaveProvider
as a sample buffer and set it running. Then when the audio data is available all you have to do is add the data to the BufferedWaveProvider
and it will be played.
The BufferedWaveProvider
uses a thread-safe internal buffer, so it's safe to add from a different thread if you feel that you really need to do so.