I'm still very new to signal processing, and I wanted to create a sort of example VST plugin using FFTW (since the FFT and IFFT I found on Rosetta Code seemed to be working too slowly) that does nothing but (uselessly) apply a FFT to each input sample, then apply an IFFT to the result of this. The goal was to get the original sound back, but the output seems (for lack of knowledge of a better term to describe the quality of the sound) "garbled." Here is the code for the processReplacing
function:
void VST_Testing::VST_Testing::processReplacing(float **inputs, float **outputs, VstInt32 sampleFrames) {
resume();
time = 0;
float *in1 = inputs[0];
float *in2 = inputs[1];
float *out1 = outputs[0]; //L
float *out2 = outputs[1]; //R
float *out3 = outputs[2]; //C
float *out4 = outputs[3]; //RL
float *out5 = outputs[4]; //RR
VstInt32 initialFrames = sampleFrames;
fftw_complex* left = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*sampleFrames);
fftw_complex* right = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*sampleFrames);
int i = 0;
while (--sampleFrames >= 0)
{
left[i][0] = *in1++;
left[i][1] = 0;
right[i][0] = *in2++;
left[i][1] = 0;
i++;
}
sampleFrames = initialFrames;
fftw_complex* l_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*sampleFrames);
fftw_complex* r_out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex)*sampleFrames);
fftw_plan p_l = fftw_plan_dft_1d(sampleFrames, left, l_out, FFTW_FORWARD, FFTW_MEASURE);
fftw_plan p_r = fftw_plan_dft_1d(sampleFrames, right, r_out, FFTW_FORWARD, FFTW_MEASURE);
fftw_execute(p_l);
fftw_execute(p_r);
fftw_destroy_plan(p_l);
fftw_destroy_plan(p_r);
p_l = fftw_plan_dft_1d(sampleFrames, l_out, left, FFTW_BACKWARD, FFTW_MEASURE);
p_r = fftw_plan_dft_1d(sampleFrames, r_out, right, FFTW_BACKWARD, FFTW_MEASURE);
fftw_execute(p_l);
fftw_execute(p_r);
i = 0;
while (--sampleFrames >= 0)
{
(*out3++) = 0.5*left[i][0] + 0.5*right[i][0];
(*out4++) = left[i][0];
(*out5++) = right[i][0];
i++;
}
fftw_destroy_plan(p_l);
fftw_destroy_plan(p_r);
fftw_free(left);
fftw_free(right);
fftw_free(l_out);
fftw_free(r_out);
}
}
My expectation was that I would get the signal from in1
and in2
(left and right input in the expected use) input back almost identically on out4
and out5
(rear left and rear right output in the expected use). Have I made a mistake in the code, or is my expectation of FFTW's behavior incorrect?