Search code examples
audiowasapi

Audio latency versus reliability


Is there any tradeoff between latency and reliability in an audio stream on Windows using WASAPI?

That is, if I'm programming a WASAPI application and I want the minimum latency, will the audio stream be subject to more pops and clicks and audio disturbances than if I use a higher latency? Is using the lowest latency possible a "free lunch", or something that comes with caveats?


Solution

  • Latency is a function of the buffer size (e.g. bufferSize/sampleRate). By increasing the buffer size you reduce the chance that say a D/A converter is going to consume the current buffer of samples before the OS has given your application a chance to fill the next buffer. The downside is that the latency is increased. The effect of the increased latency is that changes you make during playback (e.g. increasing the volume) won't be heard until the next buffer is played. At the extreme you could imagine a 1 sample buffer between your application and the sound card. You'd have zero latency but there is no way the Windows scheduler would service you regularly enough to prevent drop outs.

    There is no such thing as a free lunch but as computers have continued to speed up the chances of buffer underruns have decreased quite a bit.