]> git.alsa-project.org Git - alsa-utils.git/commit
alsaloop: reduce cumulative error caused by non-atomic samples calculation
authorRuslan Bilovol <ruslan.bilovol@gmail.com>
Mon, 9 Mar 2020 20:29:54 +0000 (22:29 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 11 Mar 2020 08:45:10 +0000 (09:45 +0100)
commitec8717d58891b18e27ac3f0e220a2a7060512870
tree08550b4676b623a21a07f84a1ab8c22a87b713b5
parentf31f5df42a0f354619119ccc7f187d7a3ea52598
alsaloop: reduce cumulative error caused by non-atomic samples calculation

When doing loopback between two audio card with
same sampling frequency, I noticed slow increase
of pitch_diff.

When I changed order of get_queued_playback_samples()
vs get_queued_capture_samples(), I noticed same drift
of pitch_diff but if was decreasing this time.

This seems to be caused by non-atomic consecutive
snd_pcm_delay() invocation for playback then for
capture. snd_pcm_delay() measures delay between
read/write call and actual ADC/DAC operation.

So while we get this value for playback path in
get_queued_playback_samples(), next call to
get_queued_capture_samples() will happen a little
bit later so snd_pcm_delay() may return incorrect
value.

Be interleaving get_queued_{playback,capture}_samples()
order, we divide this small error between playback
and capture paths. I do not see any issues anymore
with one-way drift of pitch_diff.

Signed-off-by: Ruslan Bilovol <ruslan.bilovol@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
alsaloop/pcmjob.c