Re: [LAD] Possible snd_pcm_hw_params_set_buffer_time_near() gotcha

From: Mario Lang <mlang@email-addr-hidden>
Date: Sun Dec 13 2009 - 11:31:41 EET

Victor Lazzarini <Victor.Lazzarini@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,
  ⡍⠁⠗⠊⠕
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@lists.linuxaudio.org
http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev
Received on Sun Dec 13 12:15:02 2009

This archive was generated by hypermail 2.1.8 : Sun Dec 13 2009 - 12:15:02 EET