[sdiy] help understanding circular buffers for delay line

Martin Klang mars at pingdynasty.com
Sat Mar 3 21:40:15 CET 2012


On 3 Mar 2012, at 20:00, Ove Ridé wrote:

> I would feel "safer" using code that doesn't rely on a single value.
> What if inpos for whatever weird reason got bigger than length?

Well, if you've written the program: _what_ weird reason?

It's like saying, What if the buffer got shorter and was no longer 2^n long? What if length went negative?

If you (or I) feel safer using belt and braces that's fine. But if the trousers fit, you don't have to.

Now if you (or I) like to use logical bit operators to conditionally increment pointers then yes, weird shit can and sometimes does happen.
Now let me think, what's the word length on this mcu, that toolchain...

Not that I'm saying that this:
buffer [index & (length - 1)]
is wrong (keep length at one less and you save on the subtraction).
It's just that it is right only in a narrow context.

None of this, of course, is about circular buffers. Sorry Dan!

/m


More information about the Synth-diy mailing list