[sdiy] help understanding circular buffers for delay line
Matthew Smith
matt at smiffytech.com
Fri Mar 2 06:52:05 CET 2012
Quoth Andrew Simper at 02/03/12 14:37...
> If you are using a power of 2 buffer length then just use an "&" of
> the length - 1 for starters as this will be much easier to code, worry
> about optimisation later:
>
> buffer [index& (length - 1)]
>
> so for a fixed integer sample delay you would have:
>
> inpos = (inpos + 1)& (length - 1);
> buffer [inpos] = input;
> output = buffer [(inpos - delay)& ( length - 1)];
>
> and make sure delay is less than length - 1
Cool, thanks for that little optimisation.
Logical operation should mean that the process will take a more
predictable time to execute, unlike using conditionals.
--
Matthew Smith
Business: http://www.smiffytech.com
Blog: http://www.smiffysplace.com
Linkedin: http://www.linkedin.com/in/smiffy
Flickr: http://www.flickr.com/photos/msmiffy
Twitter: http://twitter.com/smiffy
More information about the Synth-diy
mailing list