Hello! I’m completely stuck with the JUCE interpolators (
Before that I used libsamplerate.
I need to resample the buffer of floats from sound file’s samplerate to DAW session’s sample rate.
So I have the source buffer (loaded from the reader):
juce::AudioBuffer<float> *buffer = new juce::AudioBuffer<float>;
If the buffer’s samplerate != session’s samplerate I need to resample.
My steps are.
- Define the resamling ratio:
float ratio = (float) samplerate / session_samplerate;
- Calculate the output frames (samples) count for each channels:
size_t output_frames_count = ratio * length_in_samples;
length_in_samples is the length of the source buffer, in samples, for the any of the channels. - I define the new buffer to write resampled data:
juce::AudioBuffer<float> * output_buffer = new juce::AudioBuffer <float> (channels, output_frames_count);
- Then I process:
for (int i = 0; i < channels; i++)
{
juce::LinearInterpolator interpolator;
int result = interpolator.process (ratio,
buffer->getReadPointer(i),
output_buffer->getWritePointer(i),
output_frames_count);
}
- It works, but It makes samples high-pitched (in my test I resample 44100 to 48000, and 16000 to 44100 or 48000). How to fix it?