|
From: Tim M. <or...@ac...> - 2008-03-04 15:29:13
|
When using the "play" utility of sox-14.0.1, I sometimes notice a short
repeat at the end of playback of a small fragment of the previously
played audio material. My test files are 8-bit .wav and 8-bit .au
files, both sampled at 8k and both around 40k long. The problem doesn't
occur with "aplay" (alsa-1.0.14a).
What I have also noticed is that 14.0.1/src/alsa.c contains code to pad
the alsa buffer with frames of silence. This code was apparently
introduced in 2007-05-17 to fix bug #1720683 but has now been disabled
(line 652):
while (0 && frames_of_silence > 0) {
Re-enabling the code stops the repeats, but brings up another minor
problem at line 650
memset(alsa->buf, 0, frames_of_silence * ft->signal.size *
ft->signal.channels);
Zero does not represent silence for unsigned formats, so stuffing the
buffer with zeros can result in a noticeable "ker-chunk" at the end of
playback. I found that for these files, inserting 128's instead of
zeros solves the problem. At least this seems to work for low-quality
.wav files that use an unsigned 8-bit format. (I don't know if unsigned
16-bit formats will ever be an issue.)
This is what I have done to make my own installation work:
--- src/alsa.c 2007-11-04 08:28:29.000000000 -0800
+++ src/alsa.c 2008-02-23 17:25:11.000000000 -0800
@@ -647,9 +647,12 @@
* whole periods to the hardware */
snd_pcm_uframes_t frames_of_silence = alsa->period_size -
alsa->frames_this_period;
- memset(alsa->buf, 0, frames_of_silence * ft->signal.size *
ft->signal.channels);
+ if (ft->signal.encoding == SOX_ENCODING_UNSIGNED)
+ memset(alsa->buf, 128, frames_of_silence * ft->signal.size *
ft->signal.channels);
+ else
+ memset(alsa->buf, 0, frames_of_silence * ft->signal.size *
ft->signal.channels);
- while (0 && frames_of_silence > 0) {
+ while (frames_of_silence > 0) {
int err;
err = snd_pcm_writei(alsa->pcm_handle,
alsa->buf,
Hope this helps someone.
Tim
|