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@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@fzidpc73:/tmp# ./test
> -12739
> root@fzidpc73:/tmp# sed -i -e 's/int rate/unsigned int rate/' test.c
> root@fzidpc73:/tmp# gcc -o test test.c
> root@fzidpc73:/tmp# ./test
> 32000
>
> I.e., don't trust this boilerplate formula blindly.
>
> --
> CYa,
> ⡍⠁⠗⠊⠕
> _______________________________________________
> Linux-audio-dev mailing list
> Linux-audio-dev@lists.linuxaudio.org
> http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@lists.linuxaudio.org
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
Received on Tue Dec 8 00:15:04 2009
This archive was generated by hypermail 2.1.8 : Tue Dec 08 2009 - 00:15:05 EET