Hi all, I’ve been stuck for days in this. I already posted it in kvraudio but maybe I’ll have more luck here as it does involve the JUCE FFT and may be doing something wrong with it.
I’m trying to recreate this additive resynthesis to experiment a bit with sounds. Basically it analyzes the frequencies, amplitudes and phases of a sample and sets some sine oscillators to reproduce it.
So my approach is:
- Each block load N samples (usually 128-256, depending on the blockSize) from the file/sample into an array, apply windowing to it (multiplyWithWindowingTable), and then zero pad to 1024 or 2048 into another array. That array is 2 * fftSize, and the window type is Hann or Hamming
- In each block, FFT that array with performRealOnlyForwardTransform. That should give interleaved [real, imaginary] float values that I take to calculate magnitudes, phases, and frequencies (SampleRate * index / fftSize). I calculate magnitudes and phases like pizzafilms does. I have also tried calculating manually with sqrt(re * re + im * im) for magnitudes and atan2 for phases, but nothing
- In each block, set those magnitudes, phases and frequencies to sine oscillators, transitioning with linear interpolation. Setting the amplitudes and frequencies helps achieveing a sound that resembles the original sample, but in a really distorted way. Setting phases doesn’t help at all, and I think I may be mishandling that. If a phase is to say something -1.5 and next phase is 1.0, that would be going 2.5 upwards in phase/wavetable position, so that plus the phase incremental due to the frequency oscillator may be creating the FM-ish noise I hear?
I’ve tried aswell going for a full 1024-2048 FFT instead of small blocks, and interpolating the transition (freq., amplitudes, phases) from big block go big block in each small block, as it would give much better resolution (thought 128-256 may not be enough?) but it didn’t solve anything, sounds even worse.
Any thoughts? I thought I may be doing something wrong with how I get the FFT magnitudes, frequencies and phases.
Shower thought: I can hear the CPU fan burning each time the guy in the video plays notes, it may not be worth it computationally speaking to go for this approach and just do the iFFT after some parameter tweaks to alter the sound?