Heinz is right. The existing code would work correctly only if
(a) it were a signed integer, which it isn't, and
(b) the C % operator were defined as "modulo" in the mathematical sense i.e. always resulting in a value between 0 and (rhs-1), which it doesn't have to be, see https://stackoverflow.com/questions/4003232/how-to-code-a-modulo-operator-in-c-c-obj-c-that-handles-negative-numbers
Thus another correct fix is
if(!fifo) offset = (offset + nsam - 1) % nsam;
Heinz is right. The existing code would work correctly only if
(a) it were a signed integer, which it isn't, and
(b) the C % operator were defined as "modulo" in the mathematical sense i.e. always resulting in a value between 0 and (rhs-1), which it doesn't have to be, see https:/ /stackoverflow. com/questions/ 4003232/ how-to- code-a- modulo- operator- in-c-c- obj-c-that- handles- negative- numbers
Thus another correct fix is
if(!fifo)
offset = (offset + nsam - 1) % nsam;