19 #ifdef USE_FFTW // the FFTW-based version
27 mSpectBuf = (fftwf_complex *) fftwf_malloc(mCSize *
sizeof(fftwf_complex));
31 mPlan = fftwf_plan_dft_r2c_1d(size, mSampBuf, mSpectBuf, FFTWF_FLAGS);
34 mPlan = fftwf_plan_dft_c2r_1d(size, mSpectBuf, mSampBuf, FFTWF_FLAGS);
39 FFTW_Wrapper::~FFTW_Wrapper() {
40 fftwf_destroy_plan(mPlan);
42 fftwf_free(mSpectBuf);
51 memcpy(mSampBuf, in.buffer(0), mSize *
sizeof(
sample));
57 fftwf_complex * spPtr = mSpectBuf;
60 for (
unsigned j = 0; j < mCSize; j++, spPtr++)
61 *ioPtr++ = hypotf((*spPtr)[0], (*spPtr)[0]);
64 memcpy(out.buffer(0), mSpectBuf + 1, (mSize *
sizeof(
sample)));
69 for (
unsigned j = 0; j < in.mNumFrames; j++) {
71 *ioPtr++ = hypotf((*spPtr)[0], (*spPtr)[1]);
73 if ((*spPtr)[0] == 0.0f) {
74 if ((*spPtr)[1] >= 0.0f)
79 *inOutPh++ = atan((*spPtr)[1] / (*spPtr)[0]);
85 memcpy(mSpectBuf, in.buffer(0), (mCSize *
sizeof(fftwf_complex)));
89 memcpy(out.buffer(0), mSampBuf, (mSize *
sizeof(
sample)));
97 #ifdef USE_FFTREAL // the FFTReal-based version
102 :
Abst_FFT_W(size, type, forward), mFFT(size) {
107 FFTR_Wrapper::~FFTR_Wrapper() {
118 mFFT.do_fft(mTempBuf, ioPtr);
130 float normFactor = 1.0 / sqrt((
double) mSize);
131 for (
unsigned j = 0; j < mSize / 2; j++) {
133 cx_r(cplx) = *rPtr++ * normFactor;
134 cx_i(cplx) = *iPtr++ * normFactor;
137 ioPtr = out.buffer(0);
140 for (
unsigned j = 0; j < mSize / 2; j++)
141 *ioPtr++ = hypotf(*rPtr++, *iPtr++);
143 ioPtr = out.buffer(0);
147 for (
unsigned j = 0; j < mSize / 2; j++) {
148 *ioPtr++ = hypotf(*rPtr, *iPtr);
155 *inOutPh++ = atan(*iPtr / *rPtr);
168 for (
unsigned j = 0; j < mSize / 2; j++) {
170 *rPtr++ =
cx_r(cplx);
171 *iPtr++ =
cx_i(cplx);
178 for (
unsigned j = 0; j < mSize / 2; j++) {
185 mFFT.do_ifft(mTempBuf, oPtr);
208 mFFT = kiss_fft_alloc(size, dir, NULL, NULL);
213 KISSFFT_Wrapper::~KISSFFT_Wrapper() {
225 for (
int j = 0; j < mSize; j++) {
226 *cxPtr[0] = *ioPtr++;
237 kiss_fft(mFFT, (
const kiss_fft_cpx *) inBuf, (kiss_fft_cpx *) outBuf);
239 ioPtr = out.buffer(0);
245 for (
int j = 1; j < mSize; j++)
246 *ioPtr++ = hypotf(*rPtr++, *iPtr++);
252 kiss_fft(mFFT, (
const kiss_fft_cpx *) in.buffer(0), (kiss_fft_cpx *) outBuf);
256 for (
int j = 0; j < mSize; j++)
257 *ioPtr++ = cxPtr[j][0];
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
CSL_FFTType
real/complex flag (determines results from forward FFT)
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
#define cx_r(val)
complex # accesor macros
Abstract FFT class can do forward/reverse real/complex I/O FFTs.
float sample
(could be changed to int, or double)
SampleComplex * SampleComplexPtr
complex pointer
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
CSL_FFTDir
forward/reverse flag (determines FFT direction)
sample SampleComplex[2]
array-of-2 complex # type (like FFTW)
#define SAFE_MALLOC(ptr, type, len)
Useful Macros.
Base class of CSL exceptions (written upper-case). Has a string message.