This project has moved. For the latest updates, please go here.

WaveOut NumberOfBuffers and DesiredLatency

Jul 17, 2012 at 8:46 AM
Edited Jul 17, 2012 at 9:17 AM


I've just started using NAudio for my project and thanks to all who contribute to this project.

My problem is that I need to be very specific about the number of buffers and length of the buffers. So, in order to set WaveOut to use 4 buffers that are all 20 msec long, I need to initialize it as:

waveOut = new WaveOut() 
  NumberOfBuffers = 4,
  DesiredLatency = 77
waveProvider = new BufferedWaveProvider(waveFormat)
  BufferDuration = TimeSpan.FromMilliseconds(80) 

It's all fine except when I want to set the DesiredLatency, I need to reverse the formula that is used to calculate the buffer size, and work it out to get a value, which happens to produce the buffer length I need.

I am going to use it in my code as above, but I think it would be better if I don't have to refer to the WaveOut.cs file whenever I want to initialize a WaveOut in code, or write a function which takes the actual "DesiredLatency" value and converts it into NAudio units.

Jul 30, 2012 at 2:00 PM

yes, I agree that the DesiredLatency property isn't ideal for those who want exact control over buffer sizes. I don't want to break existing code, but I will have a think about how I can make it easier to do this.