[sdiy] help understanding circular buffers for delay line
dan snazelle
subjectivity at hotmail.com
Fri Mar 2 01:56:59 CET 2012
lately i have been spending a lot of time in XCODE trying to understand programming for audio.
I am trying hard to understand how to make a delay line or echo, flanger, etc.
I even found some example code but usually, the code doesnt show how to get your ADC input into the code and your DAC output out
can anyone here help me understand the basics of writing a circular buffer delay line?
I have heard that this is an application where pointers can be very useful
thanks for any help
example code below:
float vdelay_tick(VDELAY* vdelay, float input, double vlength)
{
unsigned long readpos, vlength_samps;
float output;
float* buf = vdelay->buffer;
/* calculate delay length from stored sample rate */
vlength_samps = (unsigned long)(vlength * vdelay->srate);
/* find required readpos from supplied vlength */
readpos = vdelay->writepos + vlength_samps;
/* wrap around buffer as usual */
if(readpos >= vdelay->maxlenth)
readpos -= vdelay->maxlength;
output = buf[readpos];
/* add in new input with the usual wrap-around */
buf[vdelay->writepos++] = input;
if(vdelay->writepos == vdelay->maxlength)
vdelay->writepos = 0;
return output;
}
More information about the Synth-diy
mailing list