cannam@0: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ cannam@0: cannam@0: /* cannam@0: QM DSP Library cannam@0: cannam@0: Centre for Digital Music, Queen Mary, University of London. cannam@0: */ cannam@0: cannam@0: #ifndef FFT_H cannam@0: #define FFT_H cannam@0: cannam@0: class FFT cannam@0: { cannam@0: public: Chris@114: /** Chris@114: * Construct an FFT object to carry out complex-to-complex Chris@114: * transforms of size nsamples. nsamples must be a power of two in Chris@114: * this implementation. Chris@114: */ Chris@114: FFT(int nsamples); cannam@64: ~FFT(); cannam@0: Chris@114: /** Chris@114: * Carry out a forward or inverse transform (depending on the Chris@114: * value of inverse) of size nsamples, where nsamples is the value Chris@114: * provided to the constructor above. Chris@114: * Chris@114: * realIn and (where present) imagIn should contain nsamples each, Chris@114: * and realOut and imagOut should point to enough space to receive Chris@114: * nsamples each. Chris@114: * Chris@114: * imagIn may be NULL if the signal is real, but the other Chris@114: * pointers must be valid. Chris@114: * Chris@114: * The inverse transform is scaled by 1/nsamples. Chris@114: */ cannam@64: void process(bool inverse, cannam@64: const double *realIn, const double *imagIn, cannam@64: double *realOut, double *imagOut); cannam@64: cannam@64: private: Chris@114: int m_n; cannam@0: }; cannam@0: cannam@64: class FFTReal cannam@64: { cannam@64: public: Chris@114: /** Chris@114: * Construct an FFT object to carry out real-to-complex transforms Chris@114: * of size nsamples. nsamples must be a power of two in this Chris@114: * implementation. Chris@114: */ Chris@114: FFTReal(int nsamples); cannam@64: ~FFTReal(); cannam@64: Chris@114: /** Chris@114: * Carry out a forward real-to-complex transform of size nsamples, Chris@114: * where nsamples is the value provided to the constructor above. Chris@114: * Chris@114: * realIn, realOut, and imagOut must point to (enough space for) Chris@114: * nsamples values. For consistency with the FFT class above, and Chris@114: * compatibility with existing code, the conjugate half of the Chris@114: * output is returned even though it is redundant. Chris@114: */ Chris@114: void forward(const double *realIn, cannam@64: double *realOut, double *imagOut); cannam@64: Chris@114: /** Chris@114: * Carry out an inverse real transform (i.e. complex-to-real) of Chris@114: * size nsamples, where nsamples is the value provided to the Chris@114: * constructor above. Chris@114: * Chris@114: * realIn and imagIn should point to at least nsamples/2+1 values; Chris@114: * if more are provided, only the first nsamples/2+1 values of Chris@114: * each will be used (the conjugate half will always be deduced Chris@114: * from the first nsamples/2+1 rather than being read from the Chris@114: * input data). realOut should point to enough space to receive Chris@114: * nsamples values. Chris@114: * Chris@114: * The inverse transform is scaled by 1/nsamples. Chris@114: */ Chris@114: void inverse(const double *realIn, const double *imagIn, Chris@114: double *realOut); Chris@114: cannam@64: private: Chris@114: int m_n; Chris@114: FFT *m_fft; Chris@114: double *m_r; Chris@114: double *m_i; Chris@114: double *m_discard; cannam@64: }; cannam@64: cannam@0: #endif