# Change pitch of voice

I am programming a voice changer (in c++). I need only to change the pitch of the voice. Unfortunately, I absolutely lack theoretical knowledge and hence I could not find information on the Internet :( I am asking after theory (mathematics?) lying under pitch changing. Consider, I already have .wav audiofile converted into array of samples. Thanks in advance!

P.S. After changing the pitch, the duration of the audiofile should remain the same.

• Well, if it's a single human voice, you shouldn't need to do this with a phase vocoder. How far are you shifting the pitch of the vocal track? If less than 200 cents, then you won't need to do formant-preserving pitch shifting (which requires a damn good pitch detector). Otherwise, if you're shifting the pitch by a third or fourth or fifth, you need to implement Lent's algorithm (also credited to Hamon). That requires a really good pitch detector. Commented Oct 18, 2023 at 19:52
• @robertbristow-johnson thanks for theoretical hints! Yes, it is a single human voice. Mainly, I am interested in making the voice lower or higher. For example: female -> male / male -> female. According to your comment, should I study Lent's algorithm and implement a really good pitch detector? Commented Oct 18, 2023 at 20:42
• I think you'll need to shift pitch and formants independently. A quarter century ago, I had developed DSP code for a product called PurePitch in which there were separate controls for pitch shift amount and formant shift. We had presets called "estrogen" and "testosterone" that were meant for changing the apparent gender of the speaker. We also had a control for reducing or increasing expression. We could turn your voice into a monotone. And could increase inflections of pitch also. Commented Oct 19, 2023 at 14:14
• @robertbristow-johnson thanks, your experience and PurePitch description are relevant. So, TODO list: 1) decompose the signal into frequences (Fourier transform) and formants 2) shift the frequences (Lent's algorithm) and shift the formants 3) Somehow compose the signal back. I could use Inverse Fourier transform for frequences, but how to deal with formants? Unfortunatelly, I have never worked with formants Commented Oct 19, 2023 at 15:47
• PurePitch did not do that. What you're describing is sinusoidal modeling, which you can do. Lent's algorithm is NOT frequency-domain. It's a time-domain algorithm, so no Fourier Transform. But you need a really good pitch detector. Commented Oct 19, 2023 at 17:49