LagrangeInterpolator for Realtime Resampling


Hi there,

I am making a plugin that is supposed to resample audio in realtime i.e. from 44.1 -> 22.05 -> ~11 -> ~5.5 and back again.

I understand this is effectively a low-pass filter, however producer Noah Shebib swears by lowering the sample rate of audio to achieve the “underwater” effect thats found in a lot of Drake’s music.

My first crack was trying to mod the rate at which audio was let out of the process block (pseudocode):

for ( samp : numSamps) 
    if samp_index % someVariable == 0 { L/R output = 0}
    else { L/R output = L/R output}

but this was effectively bitcrushing the audio as I learned that numSamps provided by the host was the 512 buffer and not the 44.1 rate I had expected.

Looking around the JUCE API I came across the LagrangeInterpolator but am confused on how to use it exactly and where. Right now my process block looks like:

void AudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages) {
const int totalNumInputChannels  = getTotalNumInputChannels();
const int totalNumOutputChannels = getTotalNumOutputChannels();

for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
    buffer.clear (i, 0, buffer.getNumSamples());

float *left = buffer.getWritePointer(0);
float *right = buffer.getWritePointer(1);
const int numSamps = buffer.getNumSamples();

for (int samp=0; samp < numSamps; samp++){
    left[samp] = left[samp];
    right[samp] = right[samp];

which effectively does nothing but let the audio pass through. If I wanted to use the lagrange interpolator where/how could I specify that I wanted the left/right samples to be outputted at a lower sample rate (effectively low passing the content)

In the meantime I’ll just code this up as a LPF with a slider tied to static freq cutoff points.



I think a lot of the magic is in the algorithm. Early samplers were famous and had that distinct ‘sound’ because of less-than-perfect resampling (read: linear/truncation). Multiple decimation passes will increase the desired artifacts of the algorithms.

If you look at it from an engineering pov, it is simply a brickwall lowpass filter, as you said.


Got it I think you’re right + I don’t think the avg listener would be able to discern the difference.