c@120: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ c@120: /* c@120: Constant-Q library c@120: Copyright (c) 2013-2014 Queen Mary, University of London c@120: c@120: Permission is hereby granted, free of charge, to any person c@120: obtaining a copy of this software and associated documentation c@120: files (the "Software"), to deal in the Software without c@120: restriction, including without limitation the rights to use, copy, c@120: modify, merge, publish, distribute, sublicense, and/or sell copies c@120: of the Software, and to permit persons to whom the Software is c@120: furnished to do so, subject to the following conditions: c@120: c@120: The above copyright notice and this permission notice shall be c@120: included in all copies or substantial portions of the Software. c@120: c@120: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, c@120: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF c@120: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND c@120: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY c@120: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF c@120: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION c@120: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. c@120: c@120: Except as contained in this notice, the names of the Centre for c@120: Digital Music; Queen Mary, University of London; and Chris Cannam c@120: shall not be used in advertising or otherwise to promote the sale, c@120: use or other dealings in this Software without prior written c@120: authorization. c@120: */ c@120: c@120: #ifndef FFT_H c@120: #define FFT_H c@120: c@120: class FFT c@120: { c@120: public: c@120: /** c@120: * Construct an FFT object to carry out complex-to-complex c@120: * transforms of size nsamples. nsamples does not have to be a c@120: * power of two. c@120: */ c@120: FFT(int nsamples); c@120: ~FFT(); c@120: c@120: /** c@120: * Carry out a forward or inverse transform (depending on the c@120: * value of inverse) of size nsamples, where nsamples is the value c@120: * provided to the constructor above. c@120: * c@120: * realIn and (where present) imagIn should contain nsamples each, c@120: * and realOut and imagOut should point to enough space to receive c@120: * nsamples each. c@120: * c@120: * imagIn may be NULL if the signal is real, but the other c@120: * pointers must be valid. c@120: * c@120: * The inverse transform is scaled by 1/nsamples. c@120: */ c@120: void process(bool inverse, c@120: const double *realIn, const double *imagIn, c@120: double *realOut, double *imagOut); c@120: c@120: private: c@120: class D; c@120: D *m_d; c@120: }; c@120: c@120: class FFTReal c@120: { c@120: public: c@120: /** c@120: * Construct an FFT object to carry out real-to-complex transforms c@120: * of size nsamples. nsamples does not have to be a power of two, c@120: * but it does have to be even. (Use the complex-complex FFT above c@120: * if you need an odd FFT size. This constructor will throw c@120: * std::invalid_argument if nsamples is odd.) c@120: */ c@120: FFTReal(int nsamples); c@120: ~FFTReal(); c@120: c@120: /** c@120: * Carry out a forward real-to-complex transform of size nsamples, c@120: * where nsamples is the value provided to the constructor above. c@120: * c@120: * realIn, realOut, and imagOut must point to (enough space for) c@120: * nsamples values. For consistency with the FFT class above, and c@120: * compatibility with existing code, the conjugate half of the c@120: * output is returned even though it is redundant. c@120: */ c@120: void forward(const double *realIn, c@120: double *realOut, double *imagOut); c@120: c@120: /** c@120: * Carry out a forward real-to-complex transform of size nsamples, c@120: * where nsamples is the value provided to the constructor c@120: * above. Return only the magnitudes of the complex output values. c@120: * c@120: * realIn and magOut must point to (enough space for) nsamples c@120: * values. For consistency with the FFT class above, and c@120: * compatibility with existing code, the conjugate half of the c@120: * output is returned even though it is redundant. c@120: */ c@120: void forwardMagnitude(const double *realIn, double *magOut); c@120: c@120: /** c@120: * Carry out an inverse real transform (i.e. complex-to-real) of c@120: * size nsamples, where nsamples is the value provided to the c@120: * constructor above. c@120: * c@120: * realIn and imagIn should point to at least nsamples/2+1 values; c@120: * if more are provided, only the first nsamples/2+1 values of c@120: * each will be used (the conjugate half will always be deduced c@120: * from the first nsamples/2+1 rather than being read from the c@120: * input data). realOut should point to enough space to receive c@120: * nsamples values. c@120: * c@120: * The inverse transform is scaled by 1/nsamples. c@120: */ c@120: void inverse(const double *realIn, const double *imagIn, c@120: double *realOut); c@120: c@120: private: c@120: class D; c@120: D *m_d; c@120: }; c@120: c@120: #endif