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