Silly assertion using AudioSampleBuffer copyFrom


#1

I am doing some overlap and save functions to make my filter give realtime playback of windowed buffers. To do this I have to construct a new buffer that is twice as long as the one sent in by the Host. I construct the "processBuffer" copying from the last buffer received by the processBlock(), then appending the current buffer given to the processBlock(). like this:

processBuffer = new AudioSampleBuffer (2, blockSize*2);

processBuffer->copyFrom(channelIndex, 0, *lastInputBuffer, channelIndex, 0, blockSize);

processBuffer->copyFrom(channelIndex, blockSize, buffer, channelIndex, 0, blockSize);

After building successfully I get this assertion on the first of the above lines:

jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);

...which is totally correct. But I only want to copy into the first half of processBuffer, not fill it to the end. In the next line, the "destStartSample" is at the index half way through the processBuffer.

In Matlab I would just do this with: 

processBuffer = [lastInputBuffer; buffer;]; %for a column vector

Is there a better way to join two sample buffers end to end into another AudioSampleBuffer?


#2

Allocating and copying buffers like that in realtime isn't really feasible - you should be using a circular fifo instead for managing a rolling window.


#3


The size of the window I need to process is always twice the blockSize given by the Host. At any given processing frame, the output of the processor is actually the result of the previous frame. So, the First frame in is the first one out, but its always one frame later. My Circular fifo consists of two buffers, the first one in, followed by the newer one:  [ | lastInput | newInput | ]


I am trying to construct the "ring" by copying samples from 2 AudioSampleBuffers into the "processBuffer". Is there a better way to write these audio samples to a "ring" than using copyFrom? Should I abandon the AudioSampleBuffer type and store them in a vector instead? I am trying to store Audio Samples, afterall. For the meantime, I just commented out the assertion and it is copying samples into the buffer correctly. I can see why you would assert to let someone know that the source data doesn't fill the destination, but I can't think of a simpler way to construct a buffer for overlap/save processing.


As for the allocation you mentioned: "processBuffer" is a ScopedPointer that, by its nature, will be deleted before each new call to processBlock(). Then reallocated for each subsequent call. I suppose that I could make it a regular pointer instead, then allocate the pointer during prepareToPlay() instead of reallocating with each new processBlock(). Next, I could set it to nullptr during releaseResources(). Each new block would just overwrite the data left over from the last time. I did this to my code, and it seems to be working without problems. But maybe I just need to tinker with it all more to get the most efficient result.