HELP! Resampling Effect (Halftime) using Interpolators

Hi guys! I’m trying to code a plugin that changes sound in a similar way as Half-Time does. It is the same effect as when you resample a sound using a lower samplerate.
I tried to use JUCE Interpolators to resample every buffer in the processBlock. Here is the code I´m trying to make it work:

void RESAMPLINGAudioProcessor::processBlock (juce::AudioBuffer& buffer, juce::MidiBuffer& midiMessages)
juce::ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();

juce::LagrangeInterpolator Resampler;
juce::AudioBuffer<float> bufferResampleado(totalNumInputChannels,buffer.getNumSamples()/2); //buffer of 128 samples and two channels

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

for (int channel = 0; channel < totalNumInputChannels; ++channel)
    auto* channelData = bufferResampleado.getWritePointer (channel);
    auto* channelDataRead = buffer.getReadPointer(channel);

    Resampler.process(1.378125, channelDataRead, channelData, bufferResampleado.getNumSamples());

    buffer = bufferResampleado;


I’m doing something wrong as the only thing I hear when I load my plugin are my sounds being crushed with distortion.

Anyone has some idea? Do you think I’m goin the right way?

One thing that jumps out at me from the docs:

And like with any other stateful filter, if you’re resampling multiple channels, make sure each one uses its own LagrangeInterpolator object.

Try creating a left and a right resampler and see how that works?

1 Like

the resampler and its buffer likely need to be member variables, because they are stateful

1 Like