So, I’m trying to oversample the audio input for a plugin in order to run it through a filter. I found some information about the CatmullRomInterpolator, now I want to figure out how to use it.
I read they are stateful, so each channel needs to be processed through an individual instance, and they need to be set outside of processBlock(). Did that, added a private CatmullRomInterpolator variable to the AudioProcessor.h file.
Going by the documentation/information I could find (incl. Class Reference), it seems to me that I should be doing this in the processBlock():
- get a writePointer for the input stream
- set up a stream for the oversampled signal and get a writePointer
- upsample from input to oversampled stream
- run oversampled stream through the filter
- downsample from oversampled to input (well, output) writePointer
I figure the (important part of the) code in processBlock should look like this:
/* sample block size */
const int numSamples = buffer.getNumSamples();
/* if at least one channel is present */
if(totalNumInputChannels>0)
{
/* get input stream */
float *inputLeft = buffer.getWritePointer (0);
/* set up temporary stream for oversampled data */
AudioSampleBuffer leftOversampled;
leftOversampled.setSize(1,numSamples*2); /* Oversampling by 2, therefore twice numSamples */
/* fetch write pointer for oversampling stream */
float *oversampledLeft = leftOversampled.getWritePointer(0);
/* upsample from input to oversampled stream by factor 2
resampler1 is a variable of type CatmullRomInterpolator */
resampler1.process(2, inputLeft, oversampledLeft, numSamples*2);
/* set up the filter
hostSampleRate: variable set in prepareToPlay()
filterCutoffFreq: variable set/updated from slider (20-20k, default 1k)
cutoff1: variable of type IIRFilter */
IIRCoefficients coefficients=IIRCoefficients::makeHighPass(hostSampleRate*2,filterCutoffFreq);
cutoff1.setCoefficients(coefficients);
/* run oversampled stream through filter */
cutoff1.processSamples (oversampledLeft, numSamples*2);
/* downsample fom oversampled stream back to i/o write pointer by factor 1/2 */
resampler1.process(0.5, oversampledLeft, inputLeft, numSamples);
}
The thing creates output and filters alright, but there are constant clicks and farts, which leads me to assume I’m doing something wrong with the buffering, some samples are dropped instead of processed or something like that.
I tried resetting the CatmullRomInterpolator (resampler1) and/or AudioSampleBuffer before each processing step, but that didn’t help.
What am I doing wrong? Can anyone point me in the right direction?
Many thanks in advance!
Cheers,
Rob