PDA

View Full Version : WDL fft


olilarkin
07-21-2010, 08:32 AM
can anyone advise me how to get audio in and out of wdl fft? my problem is converting to and from WDL complex numbers i think.


IPlugFFT::IPlugFFT(IPlugInstanceInfo instanceInfo)
: IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo), mGain(1.), mSampleRate(44100.), mSamplePeriod(1./44100.), fftbuffersize(1024), count(0)
{
TRACE;
GetParam(kGain)->InitDouble("Gain", 0.0, -70.0, 12.0, 0.1, "dB");

WDL_fft_init();

MakeDefaultPreset("-", kNumPrograms);
}

IPlugFFT::~IPlugFFT() {}

void IPlugFFT::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
double* in1 = inputs[0];
double* in2 = inputs[1];
double* out1 = outputs[0];
double* out2 = outputs[1];

for (int s = 0; s < nFrames; ++s, ++in1, ++in2, ++out1, ++out2)
{

if(count == fftbuffersize-1)
{
WDL_fft(fftbuffer, fftbuffersize, false);

for (int i = 0; i < fftbuffersize; i++)
{
int j = WDL_fft_permute(fftbuffersize, i);

sortedbuffer[i].re = fftbuffer[j].re;
sortedbuffer[i].im = fftbuffer[j].im;
}

//do processing on sortedbuffer here

for (int i = 0; i < fftbuffersize; i++)
{
int j = WDL_fft_permute(fftbuffersize, i);
unsortedbuffer[j].re = sortedbuffer[i].re;
unsortedbuffer[j].im = sortedbuffer[i].im;
}

WDL_fft(unsortedbuffer, fftbuffersize, true);

count = 0;
}
else
{
count++;
}

fftbuffer[count].re = (WDL_FFT_REAL) *in1; // How to input data to the fft?

*out1 = unsortedbuffer[count].re; //how to output data from the fft?

*out2 = *out1;
}
}

olilarkin
07-21-2010, 08:45 AM
doh, think i worked it out:

fftbuffer[count].re = (WDL_FFT_REAL) *in1;
fftbuffer[count].im = 0.;

*out1 = unsortedbuffer[count].re / fftbuffersize;

olilarkin
07-21-2010, 08:50 AM
at the moment i'm just re synthesising it directly

schwa
07-21-2010, 09:12 AM
http://stash.reaper.fm/oldsb/958882/capture.gif

olilarkin
07-21-2010, 09:14 AM
now i'm trying to do a brickwall filter by zeroing bins, but like another poster i am getting glitches... guess i have to try and window it

http://forum.cockos.com/showthread.php?t=56163



void IPlugFFT::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
double* in1 = inputs[0];
double* in2 = inputs[1];
double* out1 = outputs[0];
double* out2 = outputs[1];

for (int s = 0; s < nFrames; ++s, ++in1, ++in2, ++out1, ++out2)
{

if(count == fftbuffersize)
{
WDL_fft(fftbuffer, fftbuffersize, false);

for (int i = 0; i < fftbuffersize; i++)
{
int j = WDL_fft_permute(fftbuffersize, i);

sortedbuffer[i].re = fftbuffer[j].re;
sortedbuffer[i].im = fftbuffer[j].im;
}

for (int i = 0; i < fftbuffersize; i++)
{
//cartesian to polar
double mag = sqrt(sortedbuffer[i].re*sortedbuffer[i].re + sortedbuffer[i].im*sortedbuffer[i].im);
double phase = atan2(sortedbuffer[i].im, sortedbuffer[i].re);

if (i > 32)
{
mag = 0.;
phase = 0.;
}

sortedbuffer[i].re = mag * (cos(phase));
sortedbuffer[i].im = mag * (sin(phase));


//post("phase%f",phase);
}

//do processing on sortedbuffer here

for (int i = 0; i < fftbuffersize; i++)
{
int j = WDL_fft_permute(fftbuffersize, i);
unsortedbuffer[j].re = sortedbuffer[i].re;
unsortedbuffer[j].im = sortedbuffer[i].im;
}

WDL_fft(unsortedbuffer, fftbuffersize, true);

count = 0;
}
else
{
count++;
}

fftbuffer[count].re = (WDL_FFT_REAL) *in1;
fftbuffer[count].im = 0.;

*out1 = unsortedbuffer[count].re / fftbuffersize;

*out2 = *out1;
}
}

schwa
07-21-2010, 09:22 AM
now i'm trying to do a brickwall filter by zeroing bins, but like another poster i am getting glitches... guess i have to try and window it

If you do just about anything to the individual FFT bins in between the forward FFT and inverse FFT calls, then you will need to window the incoming audio and blend the outgoing audio, or else you will get glitches.

olilarkin
07-21-2010, 09:23 AM
ok thanks very much

cerberus
02-03-2012, 06:45 PM
i think i have just gotten overlap windowing working:

http://cerberusaudio.com/a/bab3d28ee0c9ffd28d9eb2b63d526b5b.png

is anyone else still working on this? of course my naive additons to the code could use improving... the cockos jesusonic plug-ins handle windowing more cleverly i think, certainly more elegantly.

A_SN
03-10-2012, 03:55 AM
I know that's a bit late but Oli what I do is make my zeropadded Dirac delta at the right position (the middle of the non padded area), FFT, multiply the bins whichever way I want, IFFT, multiply the non-padded area with a Blackman window and zero out the rest, then FFT it again so it's ready for the fast convolution.

However if you just want a brickwall filter it's perhaps better to just go with a sinc function in the time domain ( f(t) = sin (pi*t*fc) / (pi*t*fc) ) and window and zero-pad.that, then FFT.

mviljamaa
06-18-2015, 10:51 AM
i think i have just gotten overlap windowing working:

http://cerberusaudio.com/a/bab3d28ee0c9ffd28d9eb2b63d526b5b.png

is anyone else still working on this? of course my naive additons to the code could use improving... the cockos jesusonic plug-ins handle windowing more cleverly i think, certainly more elegantly.

Is the code for this windowing available somewhere?
I think I'm looking to do the same exact thing.

mviljamaa
06-27-2015, 05:40 PM
If I do WDL_fft from WDL_FFT_COMPLEX array that has imaginary parts set to zero. Then does the inverse fft return an array that has imaginary parts set to zero or small enough that they don't really belong to the signal (i.e. returns only reals)?