I am attempting to create an application similar to the network chat demo in NAudio.
On the receiving/listening end however, I am buffering my received audio packets until I get 2 of them before calling WaveProvider.addSamples(). I have experimented with not buffering at all, buffering a large amount, etc. but the issue remains so I don't think this is the explicit cause.
The issue that I am having is that no matter how fast I attempt to addSamples, the WaveProvider is getting exhausted (BufferedBytes == 0) repeatedly when the audio is playing. I ran some tests, and my debug output goes something like this:
- 0.690s WaveProvider Empty
- 0.695s Samples are added to WaveProvider
- 0.871s WaveProvider Empty
- 0.875s Samples added to WaveProvider
- 1.013s WaveProvider Empty
... etc.
the WaveProvider does not display "empty" until a every 150 ms or so, which makes sense as the addSamples call adds data corresponding to 100ms of audio data.
The interesting part is the 4ms to 5ms of time between the moment the WaveProvider is empty and the next addSamples is attempted. No change in buffer size or effort to addSamples faster seems to decrease this gap and thus the audio played back always has these tiny gaps of silence which sound like pops/breaks.
I was wondering if this tiny time delay might be caused by the WaveProvider being locked when the waveOut device is playing from it, and thus I am being locked out from addingSamples to the WaveProvider until it is finished playing? Is there any way to rectify this?
My initialization code is as follows: (they should be normal I hope)
WaveProvider = new BufferedWaveProvider(new WaveFormat(16000, 1));
WaveProvider.BufferDuration = new TimeSpan(0, 0, 10);
AudioPlayer = new WaveOut(WaveCallbackInfo.FunctionCallback());
AudioPlayer.Init(WaveProvider);
I would appreciate any help on the matter. Thank you