andrewrk / libsoundio

C library for cross-platform real-time audio input and output
http://libsound.io/
MIT License
1.92k stars 229 forks source link

Use IAudioClock for calculating actual latency on WASAPI #232

Open shangjiaxuan opened 4 years ago

shangjiaxuan commented 4 years ago

The current implementation uses the buffer size as software latency for WASAPI. This is not true for shared mode stream, and a better calculation should use IAudioClock interface to get the time since last reset of stream, and use that and the current writing frame number to calculate the actual latency.

On my win10 computer, when working on 10ms time frame in callback based shared mode (total buffer size is around 22ms), latency evaluated in this way amounts to something around 38ms, which should be much more precise.