private unsafe static void AudioStreamCallback(IntPtr buff, Int32 size)
{
byte[] samples = new byte[size];
Marshal.Copy(buff, samples, 0, size);
waveProvider.AddSamples(samples, 0, size);
bytes_played += size;
}
In the above code, buff is returned from a native dll written in C. For logging, I have printed the number of bytes added to sample. Based on this log, I am getting the below mentioned error after playing about 2.4 Mb samples.
Unhandled Exception: System.InvalidOperationException: Buffer full at NAudio.Wave.BufferedWaveProvider.AddSamples(Byte[] buffer, Int32 offset, Int32 count)
Do I need to free some buffer or make sure to flush the old entries before adding new samples? I looked at the source code, but didn’t find anything related to buffer size. Am I missing some thing.
Thanks for your help.
BufferedWaveProvideris backed by a fixed size circular buffer. Once it is full it throws an exception (newer versions of NAudio allow you to configure whether an exception is thrown or whether audio is silently discarded). The latest code also allows you to setBufferDurationbefore your first call toAddSamplesto increase the buffer size from the default of 5 seconds worth of audio.