jero2rome
jero2rome

Reputation: 1568

Naudio playback in memory samples produces delays and unaesthetic gaps in the sound

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.

Upvotes: 1

Views: 730

Answers (1)

Mark Heath
Mark Heath

Reputation: 49482

A better choice here would be RawSourceWaveStream rather than BufferedWaveProvider, which would allow you to play directly from a MemoryStream containing the full audio.

Upvotes: 1

Related Questions