Chris@337: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@337: Chris@337: /* Chris@337: Vamp Chris@337: Chris@337: An API for audio analysis and feature extraction plugins. Chris@337: Chris@337: Centre for Digital Music, Queen Mary, University of London. Chris@337: Copyright 2006-2012 Chris Cannam and QMUL. Chris@337: Chris@337: Permission is hereby granted, free of charge, to any person Chris@337: obtaining a copy of this software and associated documentation Chris@337: files (the "Software"), to deal in the Software without Chris@337: restriction, including without limitation the rights to use, copy, Chris@337: modify, merge, publish, distribute, sublicense, and/or sell copies Chris@337: of the Software, and to permit persons to whom the Software is Chris@337: furnished to do so, subject to the following conditions: Chris@337: Chris@337: The above copyright notice and this permission notice shall be Chris@337: included in all copies or substantial portions of the Software. Chris@337: Chris@337: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, Chris@337: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF Chris@337: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND Chris@337: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR Chris@337: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF Chris@337: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION Chris@337: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Chris@337: Chris@337: Except as contained in this notice, the names of the Centre for Chris@337: Digital Music; Queen Mary, University of London; and Chris Cannam Chris@337: shall not be used in advertising or otherwise to promote the sale, Chris@337: use or other dealings in this Software without prior written Chris@337: authorization. Chris@337: */ Chris@337: Chris@337: #ifndef _VAMP_FFT_H_ Chris@337: #define _VAMP_FFT_H_ Chris@337: Chris@337: #include "plugguard.h" Chris@337: _VAMP_SDK_PLUGSPACE_BEGIN(FFT.h) Chris@337: Chris@337: namespace Vamp { Chris@337: Chris@337: /** Chris@337: * A simple FFT implementation provided for convenience of plugin Chris@434: * authors. This class provides one-shot (i.e. fixed table state is Chris@445: * recalculated every time) double-precision complex-complex Chris@434: * transforms. For repeated transforms from real time-domain data, use Chris@446: * an FFTComplex or FFTReal object instead. Chris@446: * Chris@446: * Note: If the SDK has been compiled with the SINGLE_PRECISION_FFT Chris@446: * flag, then all FFTs will use single precision internally. The Chris@446: * default is double precision. The API uses doubles in either case. Chris@337: * Chris@434: * The forward transform is unscaled; the inverse transform is scaled Chris@434: * by 1/n. Chris@337: */ Chris@337: class FFT Chris@337: { Chris@337: public: Chris@337: /** Chris@434: * Calculate a one-shot forward transform of size n. Chris@446: * n must be a multiple of 2. Chris@337: * Chris@337: * ri and ii must point to the real and imaginary component arrays Chris@337: * of the input. For real input, ii may be NULL. Chris@337: * Chris@337: * ro and io must point to enough space to receive the real and Chris@337: * imaginary component arrays of the output. Chris@337: * Chris@337: * All input and output arrays are of size n. Chris@337: */ Chris@338: static void forward(unsigned int n, Chris@338: const double *ri, const double *ii, Chris@338: double *ro, double *io); Chris@337: Chris@337: /** Chris@434: * Calculate a one-shot inverse transform of size n. Chris@394: * n must be a power of 2, greater than 1. Chris@337: * Chris@337: * ri and ii must point to the real and imaginary component arrays Chris@337: * of the input. For real input, ii may be NULL. Chris@337: * Chris@337: * ro and io must point to enough space to receive the real and Chris@337: * imaginary component arrays of the output. The output is scaled Chris@337: * by 1/n. The output pointers may not be NULL, even if the output Chris@337: * is expected to be real. Chris@337: * Chris@337: * All input and output arrays are of size n. Chris@337: */ Chris@338: static void inverse(unsigned int n, Chris@338: const double *ri, const double *ii, Chris@338: double *ro, double *io); Chris@337: }; Chris@337: Chris@434: /** Chris@434: * A simple FFT implementation provided for convenience of plugin Chris@446: * authors. This class provides double-precision complex-complex Chris@446: * transforms. Chris@446: * Chris@446: * Note: If the SDK has been compiled with the SINGLE_PRECISION_FFT Chris@446: * flag, then all FFTs will use single precision internally. The Chris@446: * default is double precision. The API uses doubles in either case. Chris@446: * Chris@446: * The forward transform is unscaled; the inverse transform is scaled Chris@446: * by 1/n. Chris@446: */ Chris@446: class FFTComplex Chris@446: { Chris@448: public: Chris@446: /** Chris@446: * Prepare to calculate transforms of size n. Chris@446: * n must be a multiple of 2. Chris@446: */ Chris@446: FFTComplex(unsigned int n); Chris@446: Chris@446: ~FFTComplex(); Chris@446: Chris@446: /** Chris@446: * Calculate a forward transform of size n. Chris@446: * Chris@446: * ci must point to the interleaved complex input data of size n Chris@446: * (that is, 2n doubles in total). Chris@446: * Chris@446: * co must point to enough space to receive an interleaved complex Chris@446: * output array of size n (that is, 2n doubles in total). Chris@446: */ Chris@446: void forward(const double *ci, double *co); Chris@446: Chris@446: /** Chris@446: * Calculate an inverse transform of size n. Chris@446: * Chris@446: * ci must point to an interleaved complex input array of size n Chris@446: * (that is, 2n doubles in total). Chris@446: * Chris@446: * co must point to enough space to receive the interleaved Chris@446: * complex output data of size n (that is, 2n doubles in Chris@446: * total). The output is scaled by 1/n. Chris@446: */ Chris@446: void inverse(const double *ci, double *co); Chris@446: Chris@446: private: Chris@446: class D; Chris@446: D *m_d; Chris@446: }; Chris@446: Chris@446: /** Chris@446: * A simple FFT implementation provided for convenience of plugin Chris@445: * authors. This class provides transforms between double-precision Chris@445: * real time-domain and double-precision complex frequency-domain Chris@445: * data. Chris@434: * Chris@446: * Note: If the SDK has been compiled with the SINGLE_PRECISION_FFT Chris@446: * flag, then all FFTs will use single precision internally. The Chris@446: * default is double precision. The API uses doubles in either case. Chris@446: * Chris@434: * The forward transform is unscaled; the inverse transform is scaled Chris@434: * by 1/n. Chris@434: */ Chris@434: class FFTReal Chris@434: { Chris@448: public: Chris@434: /** Chris@434: * Prepare to calculate transforms of size n. Chris@446: * n must be a multiple of 2. Chris@434: */ Chris@434: FFTReal(unsigned int n); Chris@434: Chris@434: ~FFTReal(); Chris@434: Chris@434: /** Chris@434: * Calculate a forward transform of size n. Chris@434: * Chris@434: * ri must point to the real input data of size n. Chris@434: * Chris@434: * co must point to enough space to receive an interleaved complex Chris@446: * output array of size n/2+1 (that is, n+2 doubles in total). Chris@434: */ Chris@445: void forward(const double *ri, double *co); Chris@434: Chris@434: /** Chris@434: * Calculate an inverse transform of size n. Chris@434: * Chris@446: * ci must point to an interleaved complex input array of size Chris@446: * n/2+1 (that is, n+2 doubles in total). Chris@434: * Chris@434: * ro must point to enough space to receive the real output data Chris@434: * of size n. The output is scaled by 1/n and only the real part Chris@434: * is returned. Chris@434: */ Chris@445: void inverse(const double *ci, double *ro); Chris@434: Chris@434: private: Chris@434: class D; Chris@434: D *m_d; Chris@434: }; Chris@434: Chris@337: } Chris@337: Chris@337: _VAMP_SDK_PLUGSPACE_END(FFT.h) Chris@337: Chris@337: #endif