Re: [LAD] Possible snd_pcm_hw_params_set_buffer_time_near() gotcha

2009-12-13 Thread Mario Lang
Victor Lazzarini victor.lazzar...@nuim.ie writes: I guess the problem is that none of the right side variables/constant is unsigned in: unsigned buffer_time = 100*period*nperiods/rate; so regardless of storing it in an unsigned, it overflows before you try to store it, and so it

[LAD] Possible snd_pcm_hw_params_set_buffer_time_near() gotcha

2009-12-07 Thread Mario Lang
Hi. I just happened to stumble about a (what I call) pretty subtle bug in typical ALSA PCM code: r...@fzidpc73:/tmp# cat test.c #include stdio.h int main() { int period = 1024; int nperiods = 3; int rate = 96000; unsigned buffer_time = 100*period*nperiods/rate; printf(%d\n,

Re: [LAD] Possible snd_pcm_hw_params_set_buffer_time_near() gotcha

2009-12-07 Thread Victor Lazzarini
I guess the problem is that none of the right side variables/constant is unsigned in: unsigned buffer_time = 100*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