Is it possible to downsample well using LagrangeInterpolator?
I’m trying to create a very simple class to load a short buffer upon initialisation of the plugin, and then loop it forever. I have files in 96kHz wav so am wanting to be able to downsample these to loop. However, when this happens I get some whining (at different frequencies depending on sample rate). I tried to filter the wav before processing it with my LagrangeInterpolator as I was getting the same effect with my own non filtered 6 point Lagrange interpolator class. Adding a filter didn’t seem to remove the whining much.
Any glaringly obvious things I am doing wrong?
class SamplePlayer
{
public:
SamplePlayer()
{
currentSample = 0;
}
void initialise(double fileSampleRate, double newSampleRate, const float *inputBuffer, int numSamplesInFile)
{
store.setSize(1, (numSamplesInFile / fileSampleRate) * newSampleRate);
store.clear();
double speed = fileSampleRate / newSampleRate;
auto output = store.getWritePointer(0);
rateConvert.process(speed, inputBuffer, output, (numSamplesInFile / fileSampleRate) * newSampleRate);
}
float getNextSample()
{
++currentSample;
if (currentSample >= store.getNumSamples()) {
currentSample = 0;
}
auto read = store.getReadPointer(0);
return read[currentSample];
}
void processBuffer(float* const inputBuffer, int numSamples) {
for (int i=0; i < numSamples; i++)
{
inputBuffer[i] = getNextSample();
}
}
~SamplePlayer()
{
}
private:
int currentSample;
LagrangeInterpolator rateConvert;
AudioBuffer<float> store;
};
Thanks,
David
EDIT: Have implemented the r8brain resampler and it works as expected.
