Resampling question

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.

  1. Define the resamling ratio:
    float ratio = (float) samplerate / session_samplerate;
  2. 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.
  3. I define the new buffer to write resampled data:
    juce::AudioBuffer<float> * output_buffer = new juce::AudioBuffer <float> (channels, output_frames_count);
  4. 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);
}
  1. 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?

Juce’s interpolators define ratio as “the number of input samples to use for each output sample”, whereas your ratio is the inverse of this.

Thank you! But it crashes ( Now I decided to use speex resampler instead…