wasapisrc: Fix glitching and clock skew issues
authorNirbheek Chauhan <nirbheek@centricular.com>
Mon, 25 Nov 2019 15:30:14 +0000 (21:00 +0530)
committerTim-Philipp Müller <tim@centricular.com>
Thu, 28 Nov 2019 10:43:27 +0000 (10:43 +0000)
commit96956cf4f2a761fd1de91a953c35147b9d13c62a
treeea35c8f5909594edfaf97d5d79d6d8187ed4ea6f
parent8a0ab82444d3fa823e0514fed06a0e8aa9895567
wasapisrc: Fix glitching and clock skew issues

We were miscalculating the device period, i.e. the number of frames
we'll get from WASAPI in each IAudioClient::GetBuffer call, due to
a calculation mistake (truncate instead of round).

For example, on my machine when the aux input is set to 44.1KHz, the
reported device period is 101587, which comes out to 447.998 frames
per ::GetBuffer call. In reality we will, of course, get 448 frames
per call, but we were truncating, so we expected 447 and were
discarding one frame every time. This led to glitching, and skew over
time.

Interestingly, I can only see this with 44.1Khz. 48Khz/96Khz are fine,
because the device period is a more 'even' number.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/806
sys/wasapi/gstwasapiutil.c