For a VST3 plugin, I am trying to perform a fast fourier transform on the input signal, then process the output of that FFT and invert it to regain an audio signal that I then copy into the AudioBuffer again.
void KwSquarifyAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
juce::ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();
for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
buffer.clear (i, 0, buffer.getNumSamples());
auto fftIn = juce::AudioBuffer<juce::dsp::Complex<float>> (1, fftSize);
auto fftOut = juce::AudioBuffer<juce::dsp::Complex<float>> (1, fftSize);
auto* fftInData = fftIn.getWritePointer (0);
auto* fftOutData = fftOut.getWritePointer (0);
for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
auto* channelData = buffer.getWritePointer (channel);
// Copy samples to the fftIn buffer.
for (int i = 0; i < fftSize; i++)
{
fftInData[i] = juce::dsp::Complex<float> (channelData[i], 0.f);
}
// Perform the FFT.
fft.perform (fftInData, fftOutData, false);
/* ... some processing would go here, but I want to make sure the FFT and IFFT works first. ... */
// Perform the IFFT.
fft.perform (fftOutData, fftInData, true);
// Copy output of IFFT (stored in fftIn) to the channelData.
for (int i = 0; i < fftSize; i++)
{
channelData[i] = fftInData[i].real ();
}
}
}
I have left out the processing of the FFT data for now, as I want to make sure that the FFT and IFFT works correctly before continuing, which they don’t seem to do.
I have no idea what I am doing wrong here (how should I be able to anyway, with virtually no documentation or examples for it whatsoever), but when enabling the VST3 inside my DAW, it does not produce any sound.
I expected (or at least hoped) that it would give me (at least roughly, as I am using only 1024 for the FFT size right now) the input signal back, but it’s complete silence. Not a single sign of any signal is coming through.
Perhaps I’m missing something very obvious, or am going about this the wrong way entirely, but I would like to know how I could make this work, if anyone happens to know so.
Any help would be much appreciated, thanks in advance!