[sdiy] help understanding circular buffers for delay line

John Speth jspeth at avnera.com
Fri Mar 2 02:33:41 CET 2012


> can anyone here help me understand the basics of writing a circular
buffer
> delay line?

In C, the code emitted are usually the same when it applies to indexed
arrays (like val = array[i++]) and pointers (line val *ptr++).  Various
compiler/chip combos probably vary but the good ones don't.

A circular buffer is just a block of memory for storing your samples.
You make it "circular" by "wrapping" the index as it goes past the end
of the buffer proceeding through it (as in "i++; if (i >= SIZE) i = 0;).


Your delay line will have a put index and a take index.  The put index
will point to the sample array position to which you'll store your ADC
sample.  The take index will point to the sample array position from
which you'll read out your delayed sample.  Usually these put and take
operations happen at the same time (synchronously).  In delay lines, the
take index always chases the put index (but never catches up).  Put and
take indices will always increment by 1 for each put and take (taking
into account wrapping).

You need to take it from concept to building blocks to a final useful C
module.  I think your example was a bit too much for simplicity (the
VDELAY structure) but it had all the important elements.

The fun with delay lines happens when you have more than one take index
and you sum scaled take samples back into the put sample (echo, reverb,
etc).  Vary the take rate and you get vibrato.  Feedback that and you
get flanging.

JJS





More information about the Synth-diy mailing list