[LAD] Possible snd_pcm_hw_params_set_buffer_time_near() gotcha

Mario Lang mlang at delysid.org
Mon Dec 7 19:22:29 UTC 2009


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,
  ⡍⠁⠗⠊⠕



More information about the Linux-audio-dev mailing list