Skip to content

Commit

Permalink
fft interface
Browse files Browse the repository at this point in the history
  • Loading branch information
vlazzarini committed Feb 17, 2017
1 parent 6adbe8f commit 58841a8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
14 changes: 5 additions & 9 deletions OOps/fftlib.c
Expand Up @@ -3353,15 +3353,6 @@ void csoundRealFFTMult(CSOUND *csound, MYFLT *outbuf,
New FFT interface
VL, 2016
*/
typedef struct _FFT_SETUP{
int N, M;
void *setup;
MYFLT *buffer;
int lib;
int d;
} CSOUND_FFT_SETUP;


static
void pffft_execute(CSOUND_FFT_SETUP *setup,
MYFLT *sig) {
Expand Down Expand Up @@ -3448,6 +3439,10 @@ int setupDispose(CSOUND *csound, void *pp){
return OK;
}

int isPowTwo(int N) {
return ((N != 0) && !(N & (N - 1)));
}

void *csoundRealFFT2Setup(CSOUND *csound,
int FFTsize,
int d){
Expand Down Expand Up @@ -3498,6 +3493,7 @@ void *csoundRealFFT2Setup(CSOUND *csound,
csound->RegisterResetCallback(csound, (void*) setup,
(int (*)(CSOUND *, void *))
setupDispose);
setup->p2 = isPowTwo(FFTsize);
return (void *) setup;
}

Expand Down
13 changes: 13 additions & 0 deletions include/csoundCore.h
Expand Up @@ -935,6 +935,19 @@ typedef struct NAME__ {
} ENGINE_STATE;


/**
* Nen FFT interface
*/
typedef struct _FFT_SETUP{
int N, M;
void *setup;
MYFLT *buffer;
int lib;
int d;
int p2;
} CSOUND_FFT_SETUP;


/**
* plugin module info
*/
Expand Down
31 changes: 27 additions & 4 deletions include/plugin.h
Expand Up @@ -43,6 +43,8 @@ enum thread { i = 1, k = 2, ik = 3, a = 4, ia = 5, ika = 7 };
*/
enum fsig_format { pvs = 0, polar, complex, tracks };

typedef CSOUND_FFT_SETUP* fftp;

/** Csound Engine object.
*/
class Csound : CSOUND {
Expand Down Expand Up @@ -163,18 +165,39 @@ class Csound : CSOUND {
direction: FFT_FWD or FFT_INV \n
returns a handle to the FFT setup.
*/
void *rfft_setup(uint32_t size, uint32_t direction) {
return RealFFT2Setup(this, size, direction);
fftp fft_setup(uint32_t size, uint32_t direction) {
return (fftp) RealFFT2Setup(this, size, direction);
}

/** FFT operation, in-place, but also
returning a pointer to std::complex<MYFLT>
to the transformed data memory.
*/
std::complex<MYFLT> *rfft(void *setup, MYFLT *data) {
RealFFT2(this, setup, data);
std::complex<MYFLT> *rfft(fftp setup, MYFLT *data) {
if(!setup->p2) {
if(setup->d == FFT_FWD)
RealFFTnp2(this, data, setup->N);
else
InverseRealFFTnp2(this, data, setup->N);
}
else
RealFFT2(this, setup, data);
return reinterpret_cast<std::complex<MYFLT> *>(data);
}

/** FFT operation for complex data, in-place, but also
returning a pointer to std::complex<MYFLT>
to the transformed data memory.
*/
std::complex<MYFLT> *fft(fftp setup, std::complex<MYFLT> *data) {
MYFLT *fdata = reinterpret_cast<MYFLT*>(data);
if(setup->d == FFT_FWD)
ComplexFFT(this,fdata,setup->N);
else
ComplexFFT(this,fdata,setup->N);
return reinterpret_cast<std::complex<MYFLT>*>(fdata);
}

};

/** One-dimensional array container
Expand Down

0 comments on commit 58841a8

Please sign in to comment.