[LAD] Possible snd_pcm_hw_params_set_buffer_time_near() gotcha
Victor Lazzarini
Victor.Lazzarini at nuim.ie
Mon Dec 7 19:38:15 UTC 2009
I guess the problem is that none of the right side variables/constant
is unsigned in:
> unsigned buffer_time = 1000000*period*nperiods/rate;
so regardless of storing it in an unsigned, it overflows before you
try to store it, and so it messes up everything.
Note that you could also prevent this by using the correct constant
10000000U
Victor
On 7 Dec 2009, at 19:22, Mario Lang wrote:
> Hi.
>
> I just happened to stumble about a (what I call) pretty subtle
> bug in typical ALSA PCM code:
>
> root at fzidpc73:/tmp# cat test.c
> #include <stdio.h>
> int main() {
> int period = 1024;
> int nperiods = 3;
> int rate = 96000;
> unsigned buffer_time = 1000000*period*nperiods/rate;
> printf("%d\n", buffer_time);
> }
> root at fzidpc73:/tmp# ./test
> -12739
> root at fzidpc73:/tmp# sed -i -e 's/int rate/unsigned int rate/' test.c
> root at fzidpc73:/tmp# gcc -o test test.c
> root at fzidpc73:/tmp# ./test
> 32000
>
> I.e., don't trust this boilerplate formula blindly.
>
> --
> CYa,
> ⡍⠁⠗⠊⠕
> _______________________________________________
> Linux-audio-dev mailing list
> Linux-audio-dev at lists.linuxaudio.org
> http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
More information about the Linux-audio-dev
mailing list