[sdiy] help understanding circular buffers for delay line

Tom Wiltshire tom at electricdruid.net
Sat Mar 3 23:17:50 CET 2012


On 3 Mar 2012, at 19:56, Matthew Smith wrote:

> Quoth Martin Klang at 04/03/12 05:45...
>> 
>> why not use modulus?
>> inpos = (inpos + 1)  % length ;
> 
> Personally, I try to avoid any form of division (other than ^2 shifts,) when working with low-end micros. I see these as "expensive" operations and try to keep to additions, shifts, and logical operations. (And multiplications, if the device happens to have a hardware multiplier. But not common on low-end devices.)

Absolutely agree. The simple AND masking operation that you can do if it's a power of two makes that definitely preferable. I don't know if the compiler would take advantage (it bloody well ought to) but I'm certain that *I* would.
Like Matthew, I stay away from any division that you can't with shifts, and multiplication is something for dsPICs where you've got a powerful MPY or MAC instruction.

T.




More information about the Synth-diy mailing list