On 10/03/2013 05:23, robert bristow-johnson wrote:
..
ANDing with 2^p - 1 is a well-known and oft-used technique in C.
probably the best way to do it in C.

...

if it's a wavetable and you're doing linear interpolation, a simple
trick is to copy x[0] to x[256] (make a 256 point wavetable a 257
element array) do the AND only for the first sample in the linear
interpolation, the follow sample will always just follow and you need
not AND the index for that second sample.



There are useful examples of this in the Csound codebase, specifically the "oscili" family of opcodes, based on reading a function table where the extra element at the end is called a "guard point". For various reasons, Csound was extended a while back to allow non power-of-two table sizes, but the original opcodes are preserved. I included an discussion (with some standalone code) of the Csound oscillator in the Audio Programming Book, in the context of the description of the C bitwise operators. The "oscili" opcode is also interesting for the way it handles the fractional part of the interpolation using integer operations in the manner of a fixed-point computation; all of the above conspiring to make the Csound oscillator famously fast. There are reasons enough to have conditional tests inside a per-sample loop, but where they can be avoided, significant speedups can be achieved.

Richard Dobson

--
dupswapdrop -- the music-dsp mailing list and website:
subscription info, FAQ, source code archive, list archive, book reviews, dsp 
links
http://music.columbia.edu/cmc/music-dsp
http://music.columbia.edu/mailman/listinfo/music-dsp

Reply via email to