Pitch shifting in JUCE

Hi, I’m writing a program to manipulate audio files. Specifically I need to change tempo of a song and change its pitch (independently of one another). I looked in DSP module but it seems that there no JUCE class to do this. Surfing the net I found that SoundTouch library is able to do this.

Is there any way to implement tempo/pitch change independently using only JUCE framework? In alternative, is it possible to combine JUCE and SoundTouch?

Thanks in advance

There’s no pitch shifting or TCE as part of JUCE, there’s another discussion summarising the various options here:

I’ve had some good results with Rubberband myself.

Thank you! I’ll give that a look

if your audio is stored in a buffer like a double array, you could use an int idx to index through all samples in normal tempo, then use an int modIdx = int(idx*tune), while float tune is the factor of pitchshifting (1 == normal, <1 == slow, >1 == fast). doing it like this i noticed that things can become pretty grainy when slowing down the sample because it has to repeat one sample sometimes due to the rounding to integer-values-thing. what you can do about that is write an interpolation-method that uses float values to index stuff and then does some computing to mix 2 samples with each other to the degree of this float’s fraction. it may sound complicated and mathy but it’s actually quite fun to write

FAUST has an implementation of this pitch-shifting algorithm (aka overlap-add) in (ef.)transpose , with the addition of some cross-fading to stop the audio from clicking when the buffer index wraps around. It compiles to C++ and is GPL 2.0 licensed, so pretty easy to drop in to a JUCE project!

4 Likes

Thanks, I’ll surely try this method!

Check out tracktion_engine. It has Pitch Shifter plugin which uses SoundTouch library.

1 Like