AudioSampleBuffer : block filtering over buffer size


#1

I have to find a way to store the samples up until I get enough samples to process it with the filter function (due to fft size and lengthy filters) and then send it back in the processor loop.
Here’s basicaly what I’m doing. It seems to work except I keep getting some click.
Since we don’t have control on the buffer size (this is the host app. “decision” right ?), I assume we can send the samples block back looping with the buffer.copyFrom function.

void MyPlugin::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{

	int i; 
	niSamples=buffer.getNumSamples()
	

	// We are adding the samples to our fromInput Buffer up until we get enough samples to filter it
	numAccumulationDone += 1;

	// Put the content of buffer at the end of fromInput
	memcpy(&fromInput[niSamples*(numAccumulationDone-1)],buffer.getSampleData(0,0),niSamples*sizeof(float));

	
	if (numAccumulationDone == numAccumulationToDo)
	{
     		processFiltering(fromInput, filteredBuffer);
	
	// Copy the filteredBuffer to the buffer niSamples by niSamples
	// Since it doesn't accept block size bigger than buffer.getNumSamples() 
	
	for (i=0; i<numAccumulationDone; i++ ) buffer.copyFrom	(0, 0, &filterBuffer[niSamples*i], niSamples);
	
	// On remet à zéro le compteur d'accumulation
	numAccumulationDone = 0;
	
	};//end if

}

Any other way to do it ?
Thanks,
Bruno


#2

I’m not sure if I quite understand everything in your code, because one time it’s “filteredBuffer” and another time it’s “filterBuffer” written there.

I see 2 problems in your code:

  1. You are using the numAccumulationToDo variable - this variable means that each N inputs, the processed data is put out. This then also means, that the “big block” of data to be filtered is always a (integer) multiple of the input buffer size - is that true? For most things like FFT, the size is always 2^N, which is not necessarely a multiple on the soundcard’s buffer size.

  2. Your code takes in each and every input buffer, but only outputs valid data every numAccumulationToDo’th time. This makes no sense at all. If numAccumulationToDo was 5, this would amount to passing 4 times the unfiltered signal, then 1 time the filtered signal, then again 4 times the unfiltered signal and so forth…

Basically what you have to do is to use a circular buffer.


#3

Thanks for your detailed answer. Sorry for the mispelled variable. This code was just intended to explain what I’m doing. Actually were are processing several chanels using fft-overlapped filtering methods. The block size of the buffer are as far as I have tested several host-asio driver configuration always 2^N.

I understand the concept of circular buffer but I don’t see how to implement it with the juce Audioprocessor architecture. Any code sample that would give me some hint.