[RDD] Fixing ALSA playback on weird cards

Karl Koscher supersat at uwave.fm
Mon Jan 6 02:52:23 EST 2014

I sent this earlier to rivendell-prog but never got a reply. Perhaps it was
the holidays, or maybe that mailing list is deprecated?

---------- Forwarded message ----------
From: Karl Koscher <supersat at uwave.fm>
Date: Wed, Dec 25, 2013 at 2:11 AM
Subject: Fixing ALSA playback on weird cards
To: rivendell-prog at lists.rivendellaudio.org

For whatever reason, one of our ALSA playback cards reports a sampling rate
of 44099 instead of the usual 44100. Any playback on this device quickly
gets distorted, and though some debugging, I found that a byte was being
dropped. The culprit is the code in FillAlsaOutputStream that adjusts the
amount of data it reads in if the card's playback rate is not the same as
the stream's. The amount of data to read is divided by the ratio between
the card's playback rate and the stream's rate. If the playback ringbuffer
is empty, this increases the amount of data to read beyond the capacity of
the ringbuffer. In that case, the ringbuffer code takes the first 2^18-1
bytes, which causes the samples to become misaligned.

I'm trying to figure out the purpose of this code. FillAlsaOutputStream
will always fill the ringbuffer, so the rate that it's filled doesn't need
to be adjusted. It could also be to do a form of poor resampling by
dropping samples periodically, but this only works if the playback rate is
lower than the stream's sample rate, and it doesn't do this resampling when
the ringbuffer is initially filled. Is there a reason for this code, or can
it be pulled out?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://caspian.paravelsystems.com/pipermail/rivendell-dev/attachments/20140105/5388d7ec/attachment.html>

More information about the Rivendell-dev mailing list