Skip to content

Commit

Permalink
Use proper buffering for FFT.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremysalwen committed Jun 3, 2011
1 parent 867e953 commit 0ab08c5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
38 changes: 19 additions & 19 deletions kn0ck0ut6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ AKnockout::AKnockout(double rate) : Plugin<AKnockout>(p_n_ports)
{
sampleRate=rate;
gInFIFO = new float [MAX_FRAME_LENGTH];
gOutBuffer = new float [MAX_FRAME_LENGTH];
gFFTworksp = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * MAX_FRAME_LENGTH);
gOutputBuffer=new float [2*MAX_FRAME_LENGTH];
gOutBuffer = new float [MAX_FRAME_LENGTH];
FFTRealBuffer=new float[MAX_FRAME_LENGTH];
gFFTworksp = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * MAX_FRAME_LENGTH);
gOutputAccum = new float [2*MAX_FRAME_LENGTH];
gAnaFreq = new float [MAX_FRAME_LENGTH];
gAnaMagn = new float [MAX_FRAME_LENGTH];
Expand All @@ -53,11 +53,11 @@ AKnockout::AKnockout(double rate) : Plugin<AKnockout>(p_n_ports)
memset(gDecay,0,MAX_FRAME_LENGTH*sizeof(float));
window = new double [FFTWINDOW];

forward_sp1= fftwf_plan_dft_r2c_1d(FFTWINDOW, gInFIFO , gFFTworksp,
forward_sp1= fftwf_plan_dft_r2c_1d(FFTWINDOW, FFTRealBuffer , gFFTworksp,
FFTW_ESTIMATE);
forward_sp2= fftwf_plan_dft_r2c_1d(FFTWINDOW, gInFIFO2, gFFTworksp2,
forward_sp2= fftwf_plan_dft_r2c_1d(FFTWINDOW,FFTRealBuffer, gFFTworksp2,
FFTW_ESTIMATE);
backwards=fftwf_plan_dft_c2r_1d(FFTWINDOW, gFFTworksp, gOutputBuffer,
backwards=fftwf_plan_dft_c2r_1d(FFTWINDOW, gFFTworksp, FFTRealBuffer,
FFTW_ESTIMATE);

makelookup(FFTWINDOW);
Expand All @@ -69,11 +69,11 @@ AKnockout::AKnockout(double rate) : Plugin<AKnockout>(p_n_ports)
//-----------------------------------------------------------------------------------------
AKnockout::~AKnockout() // delete buffers in destructor
{
delete[] gInFIFO;
delete[] gInFIFO;
delete[] FFTRealBuffer;
delete[] gOutBuffer;
fftwf_free(gFFTworksp);
delete[] gOutputAccum;
delete[] gOutputBuffer;
delete[] gOutputAccum;
delete[] gAnaFreq;
delete[] gAnaMagn;
delete[] gAnaMagn2;
Expand All @@ -91,8 +91,7 @@ void AKnockout::suspend ()
memset(gInFIFO, 0, MAX_FRAME_LENGTH*sizeof(float));
memset(gOutBuffer, 0, MAX_FRAME_LENGTH*sizeof(float));
memset(gFFTworksp, 0, 2*MAX_FRAME_LENGTH*sizeof(float));
memset(gOutputAccum, 0, 2*MAX_FRAME_LENGTH*sizeof(float));
memset(gOutputBuffer, 0, 2*MAX_FRAME_LENGTH*sizeof(float));
memset(gOutputAccum, 0, 2*MAX_FRAME_LENGTH*sizeof(float));
memset(gAnaFreq, 0, MAX_FRAME_LENGTH*sizeof(float));
memset(gAnaMagn, 0, MAX_FRAME_LENGTH*sizeof(float));
memset(gInFIFO2, 0, MAX_FRAME_LENGTH*sizeof(float));
Expand Down Expand Up @@ -156,12 +155,17 @@ void AKnockout::do_rebuild(long numSampsToProcess, long fftFrameSize, long osamp

/* do windowing */
for (long k = 0; k < fftFrameSize;k++) {
gInFIFO[k] *= window[k];
gInFIFO2[k] *= window[k];
FFTRealBuffer[k]=gInFIFO[k] * window[k];
}

/* do transform */
fftwf_execute(forward_sp1);
fftwf_execute(forward_sp1);

for (long k = 0; k < fftFrameSize;k++) {
FFTRealBuffer[k]=gInFIFO2[k] * window[k];
}

fftwf_execute(forward_sp2);

/* frequency analysis */
for (long k = 0; k <= fftFrameSize2; k++) {
Expand All @@ -187,10 +191,6 @@ void AKnockout::do_rebuild(long numSampsToProcess, long fftFrameSize, long osamp

}

/* do transform */
fftwf_execute(forward_sp2);


/* this is the processing section */

// lo cut
Expand Down Expand Up @@ -262,7 +262,7 @@ void AKnockout::do_rebuild(long numSampsToProcess, long fftFrameSize, long osamp

/* do windowing and add to output accumulator */
for(long k=0; k < fftFrameSize; k++) {
gOutputAccum[k] += window[k]*gOutputBuffer[k]/(dOutfactor);
gOutputAccum[k] += window[k]*FFTRealBuffer[k]/(dOutfactor);
}

/* transfer output accum to output buffer */
Expand Down
2 changes: 1 addition & 1 deletion kn0ck0ut6.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AKnockout:public Plugin<AKnockout> {
float* gInFIFO;
float* gOutBuffer;
float* gOutputAccum;
float* gOutputBuffer;
float* FFTRealBuffer;
float* gAnaFreq;
float* gAnaMagn;
float* gInFIFO2;
Expand Down

0 comments on commit 0ab08c5

Please sign in to comment.