Downsampling using interpolators

Hi guys,

for a project I’m working on, I need to process a signal at a fixed sample rate. I’m trying to resample the incoming buffer with either Lagrange or Catmull-Rom interpolators, but the result shows an heavy aliasing/discontinuities, even if I play a 100Hz sine.

I have a buffer to store the decimated samples and, for each channel, two interpolators (one to lower the sample rate and another to bring it back to the system’s one).

In prepareToPlay:

const double decimRatio = sampleRate / 18000.0;
const int decimNumSamples = static_cast<int>(samplesPerBlock / decimRatio);

lowResBuffer.setSize(2, decimNumSamples);

//here the interpolators are reset

Then, I have a method to perform the resampling. For testing purposes, I do both the decimation and upsampling in the same place.

void MyProject::ResampleBuffer(AudioBuffer<float>& inBuffer)
	//Decimate to target SR
	const float** inputs = inBuffer.getArrayOfReadPointers();
	float** outputs = lowResBuffer.getArrayOfWritePointers();
	const double decimRatio = getSampleRate() / 18000.0;

	for(int chan = 0; chan < inBuffer.getNumChannels(); ++chan)
		decimator[chan]->process(decimRatio, inputs[chan], outputs[chan], lowResBuffer.getNumSamples());

	//Upsample to original SR
	const float** inputs = lowResBuffer.getArrayOfReadPointers();
	float** outputs = inBuffer.getArrayOfWritePointers();
	const double upsampRatio = 18000.0 / getSampleRate();

	for(int chan = 0; chan < inBuffer.getNumChannels(); ++chan)
		upsampler[chan]->process(upsampRatio, inputs[chan], outputs[chan], inBuffer.getNumSamples(), lowResBuffer.getNumSamples(), true);

It sounds like the output samples produced are not the same as the expected, but AFAIK the interpolator methods won’t return the number of samples produced.

Any hints?

In which way does the result differ from the input?