Issues with FFT for pitch manipulation

Hello there!
I am at the very first attempt in patch development, and i am stuck in a problem that concern the Fast Fourier Transform.
As i am not really confident with C++ and my math background is not so detailed (i know a bit of theory but the implementation is far from my possibilities), maybe that is one of the reasons why i am not getting the patch working, but i am reasonably sure that this is the right way to make this patch (if it isn’t i beg you to explain me a better way T_T )

Here is my problem: i want to make a “Whammy”-like patch, and to manipulate the pitch i’m trying to use the FFT using the C++ API. At the current state the patch is only applying the direct fft to the buffer when the first parameter (A) is greater than 0.5, and nothing else, and that seems to work. I’m actually using for debugging to mute the sound putting the first parameter (A) to zero. But when i try to do the inverse FFT the “debugging” trick does not work anymore and i suppose somehow goes in error when the inverse is applied (if you try to comment the line with the inverse FFT it works perfectly).
Regardless of whether or not I modify the buffer before applying the inverse FFT seems not to work at all.

Here is my patch:
https://hoxtonowl.com/patch-library/patch/WhammyPatch/

Can someone help me to figure out where I’m wrong?

Thank you!

I don’t see anything glaringly wrong with this. In what way does it not work as you’d expect?

I would never trust a float to be equal to anything, so I’d change this line
if(tone == 0){
to
if(tone < 0.01){

Keep in mind that the FFT is initialised to your blocksize, so with the default blocksize of 128 you will have a very low resolution representation of the signal. Try turning the blocksize up to 512 or even 1024 in OwlControl.

And at some point you should definitely do some windowing :slight_smile: or overlap-add :smile:

FFTs are a lot of fun but it can be difficult to get good results. Here’s a good summary to why that might be: bjorg: Why EQ Is Done In the Time Domain

Hi, thank you for the quick answer!
Well now i am testing in the browser and not with the OWL actually… because i wasn’t be able to make the patch work so i supposed that with OWL wouldn’t be different, but maybe i’m wrong (i am wondering if can be a browser issue. I tried with Google Chrome, MS Edge, Firefox).
Anyway trying in the browser i noticed that after the Inverse FFT if i put the buffer to zero, for instance, it not work. I’m expecting that if i set A parameter > 0.5 i hear no sound, and that is not what is happening. (i edited the code uncommenting a line after the IFFT).
Furthermore the “check” with A parameter < 0.01 that should work in any case is not working anymore after the first time i try to go over 0.5.
I hope the explanation is more clear.

Anyway the link you posted is very interesting, thanks a lot! I will definitely study it

Are FFTs the right tool to make this patch possible in C++? I mean, to make a simple pitch shifter that shift the frequency in input according to a parameter (I don’t even need to keep the original signal). In other words, may I do this in time domain? (I know these questions may seem very trivial but I’m new to the world of DSP)

There’s a few pitch shifters in the library:
https://hoxtonowl.com/patch-library/patch/DualPitchShifter
https://hoxtonowl.com/patch-library/patch/Multi_PitchShifter
https://hoxtonowl.com/patch-library/patch/Pitch_Shifter
https://hoxtonowl.com/patch-library/patch/StereoFreqShifter

I’ve put together a simple FFT through patch which uses an FFT window twice the blocksize. Try it out on the pedal with different blocksizes to hear the sort of artefacts you get this way. If you like it then you can start messing with the signal in the frequency domain.

https://hoxtonowl.com/patch-library/patch/FFT_Through

It takes less than 20% CPU for the forward and reverse FFT plus windowing, so still gives you plenty room to do fun spectral stuff.

Here’s a version where you can set a multiplier M for the FFT size, works with 2x and 4x the blocksize.
It implements basic pitch shifting by moving the magnitudes up
https://hoxtonowl.com/patch-library/patch/Spectral_Shift

I don’t think it runs in every browser but try it out on the pedal with blocksize 128 or more.

Wow! I’m really speechless!
Thank you very much for the help, I really appreciated a lot this work.
Seems a lot clearer, after a first analysis.
Now I’m going to look deeper and trying to understand at best of my capabilities.

Thank you again!