On 3/11/13 11:19 AM, Phil Burk wrote:
Regarding power-of-2 sized circular buffers, here is a handy way to
verify that a bufferSize parameter is actually a power-of-2:

int init_circular_buffer( int bufferSize, ... )
{
assert( (bufferSize & (bufferSize-1)) == 0 )
...



might be silly, but a way to force the caller to constrain it to a power of 2 is:

init_circular_buffer( int logBufferSize, ... )
{
unsigned long bufferSize = 1L << logBufferSize;
unsigned long indexMask = bufferSize - 1;
...


On 3/11/13 2:59 AM, Nigel Redmon wrote:
Also a note that the modulo-by-AND indexing is built into some processors—the 
56K family, at least, as Robert knows well…buffers are the next power of two 
higher than the space needed, and the masking happens for free…

actually the 56K and other DSPs (like the SHArC) can do buffers of any size below 32K. the 56K has a restriction that the base address of the buffer must be an integer multiple of a power of 2 that is at least as big as the bufferSize. the modulo arithmetic doesn't really happen for free. choosing to use a DSP over a cheap ARM chip or something similar has both advantages and disadvantages. and they have to put a bunch of logic on the chip for the modulo. even the 563xx chip has that 32K restriction, even though the address space increased to 16M. such a shame. you have minutes of addressing space, but your modulo delay lines are still limited to less than a second at any decent sampling rate.

but what you can do with C where you might have a bunch of different delay lines (like in a Shroeder/Jot reverb), all running at the same sampling rate, is create a *single* circular buffer that has length that is a power of 2. then each little delay line can have a piece of that buffer allocated, but all of the allocations move at the same rate. the various delay line allocations are "stationary" relative to each other.

it can be compared to an analog tape delay like this. you have a fixed amount of tape media but as many record and playback heads as your heart desires. so instead of cutting a separate loop of tape (which has to be of length equal to a power of two) and connect that up to a record and playback head, you create one big loop of tape and put a record/playback head pair for each delay on the tape loop at different locations.

that way you can efficiently allocate a delay line of 129 or 257 or 4097 samples long along with a bunch of others. only the whole big buffer need be of length 2^p .

--

r b-j                  r...@audioimagination.com

"Imagination is more important than knowledge."



--
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