Using BufferedWaveProvider
for playback of audio samples which are stored in database as double[]
_bufferedWaveProvider = new BufferedWaveProvider(Format)
{
DiscardOnBufferOverflow = true,
BufferDuration = TimeSpan.FromSeconds(5)
};
public void Consume(double[] samples, int offset, int count)
{
samples.Paginate<double, float>(offset, count)
.ForEach(x =>
{
byte[] consumeBuffer = x.ToBytes(ref _consumeBuffer);
_bufferedWaveProvider.AddSamples(consumeBuffer, 0, _consumeBuffer.Length);
});
}
The audio when played back is producing gaps in sound. Samples are sent inside Consume()
method for every 100ms. Is there a problem that the WaveOut()
is playing faster than we call Consume()
method ? How do we synchronize this reading and playback.
A better choice here would be
RawSourceWaveStream
rather thanBufferedWaveProvider
, which would allow you to play directly from aMemoryStream
containing the full audio.