Victor Lazzarini <Victor.Lazzarini(a)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,
⡍⠁⠗⠊⠕