[LAD] Possible snd_pcm_hw_params_set_buffer_time_near() gotcha

Mario Lang mlang at delysid.org
Sun Dec 13 09:31:41 UTC 2009


Victor Lazzarini <Victor.Lazzarini at nuim.ie> writes:

> 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

Not quite.  unsigned will just give us one bit more, but
it still can easily overflow around the 4G limit.  For instance
if period_size is 2048 and nperiods is 4...

So casting the first multiplier to uint64_t seems more robust:

1000000*(uint64_t)period*nperiods/rrate

-- 
CYa,
  ⡍⠁⠗⠊⠕



More information about the Linux-audio-dev mailing list