Regression playing 24bit/96kHz audio on USB audio interface between 5.10.94 and 5.15.21
Ruud van Asseldonk
ruud at veniogames.com
Fri Dec 30 19:42:24 CET 2022
After diving into this some more, I managed to create a minimal
reproducing C program. I discovered:
* The bit depth is not relevant.
* It is not a problem with 96 kHz, but a problem with switching
sample rates.
If I call snd_pcm_hw_params, the first call always succeeds. But when I
first call it with hw_params with rate 44100 and then again with 48000
or 96000, the second call fails. If I call it with 96000 first and then
with 44100, the first call for 96000 succeeds and changing to 44100
fails. I'll add the full program at the end of this mail. Changing the
bit depth does succeed by the way, to it’s not that the hw_params can’t
be changed at all.
Thorsten Leemhuis wrote:
>> Sorry for your troubles. You could use "git bisect" to try to pinpoint
>> the exact commit that introduces failure for you.
>
> Yeah, that would be helpful. But 5.15 is quite old by now. Before going
> down that route you might want to try the latest kernel (e.g. Linux
> 6.1), as the problem might have been fixed in between, without the fix
> being backported.
> You also talk about a "rpi-" kernel. Is that a vanilla kernel, or at
> least close to it?
It is not vanilla, it is from
https://github.com/raspberrypi/linux/tree/rpi-5.15.y. However, in
addition to the Raspberry Pi I also have an x86_64 laptop that runs a
vanilla 6.1.1 kernel, and the minimal reproducing program below does
fail here as well with an UMC204HD. When I downgrade to 5.10.16 (also
vanilla), the program does succeed. So it’s unrelated to the Raspberry
Pi. This should also make it a lot easier for me to bisect this as I
don’t have to do it on the Raspberry. I will try to bisect next then.
Jaroslav Kysela wrote:
> It seems like a problem in the hw_params constraints / refining. There
> are lot of changes in the USB audio driver between 5.10/5.15. There is
> also HW_CONST_DEBUG define in sound/usb/pcm.c which enables the debug
> output for the refining.
>
> Just curious: What's behind the value 513 (period size)? It does not
> match the time (5.34ms for 96kHz) nor a binary value. I would use 480
> (5ms) or so.
I think I put this in at some point trying to see if it made a
difference, in my main application I was using different values. After
some more trying, it looks like the period size and buffer size are not
relevant for reproducing, see also the program below.
> And the final note: I gave a quick test with UMC204HD with the 6.0.9
> kernel and it appears that this problem is not present in the recent
> kernel:
After writing the reproducer, it looks like the failure only happens
when changing the sample rate, so it makes sense that aplay would not
reproduce it.
> I would also use S32_LE native format in your app, the S24_3LE is not
> supported with your hw directly. The alsa-lib does conversion.
Thanks for the heads-up! Yeah I am being lazy, I am also relying on
alsa-lib to expand the channels from 2 to 4 (since the UCM404 only
supports 4 channels).
Minimal reproducing program:
#include <assert.h>
#include <alsa/asoundlib.h>
void set_format(snd_pcm_t* pcm, unsigned int rate) {
int err;
snd_pcm_hw_params_t* hwp;
err = snd_pcm_hw_params_malloc(&hwp);
assert(err == 0);
err = snd_pcm_hw_params_any(pcm, hwp);
assert(err == 0);
err = snd_pcm_hw_params_set_rate(pcm, hwp, rate, 0);
assert(err == 0);
err = snd_pcm_hw_params(pcm, hwp);
assert(err == 0);
}
int main(void) {
int err;
snd_pcm_t* pcm;
int mode = 0;
err = snd_pcm_open(&pcm, "hw:U192k", SND_PCM_STREAM_PLAYBACK, mode);
assert(err == 0);
set_format(pcm, 44100);
printf("44.1k ok\n");
set_format(pcm, 96000);
printf("96k ok\n");
}
Kind regards,
Ruud
More information about the Alsa-devel
mailing list