Chris@191: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@191: Chris@191: /* Chris@191: QM DSP Library Chris@191: Chris@191: Centre for Digital Music, Queen Mary, University of London. Chris@191: This file by Chris Cannam. Chris@191: Chris@191: This program is free software; you can redistribute it and/or Chris@191: modify it under the terms of the GNU General Public License as Chris@191: published by the Free Software Foundation; either version 2 of the Chris@191: License, or (at your option) any later version. See the file Chris@191: COPYING included with this distribution for more information. Chris@191: */ Chris@191: Chris@191: #ifndef DCT_H Chris@191: #define DCT_H Chris@191: Chris@191: #include "FFT.h" Chris@191: Chris@191: #include Chris@191: Chris@191: class DCT Chris@191: { Chris@191: public: Chris@191: /** Chris@191: * Construct a DCT object to calculate the Discrete Cosine Chris@191: * Transform given input of size n samples. The transform is Chris@191: * implemented using an FFT of size 4n, for simplicity. Chris@191: */ Chris@191: DCT(int n); Chris@191: Chris@191: ~DCT(); Chris@191: Chris@191: /** Chris@191: * Carry out a type-II DCT of size n, where n is the value Chris@191: * provided to the constructor above. Chris@191: * Chris@191: * The in and out pointers must point to (enough space for) n Chris@191: * values. Chris@191: */ Chris@191: void forward(const double *in, double *out); Chris@191: Chris@191: /** Chris@191: * Carry out a type-II unitary DCT of size n, where n is the value Chris@191: * provided to the constructor above. This is a scaled version of Chris@191: * the type-II DCT corresponding to a transform with an orthogonal Chris@191: * matrix. This is the transform implemented by the dct() function Chris@191: * in MATLAB. Chris@191: * Chris@191: * The in and out pointers must point to (enough space for) n Chris@191: * values. Chris@191: */ Chris@191: void forwardUnitary(const double *in, double *out); Chris@191: Chris@191: /** Chris@191: * Carry out a type-III (inverse) DCT of size n, where n is the Chris@191: * value provided to the constructor above. Chris@191: * Chris@191: * The in and out pointers must point to (enough space for) n Chris@191: * values. Chris@191: */ Chris@191: void inverse(const double *in, double *out); Chris@191: Chris@191: /** Chris@191: * Carry out a type-III (inverse) unitary DCT of size n, where n Chris@191: * is the value provided to the constructor above. This is the Chris@191: * inverse of forwardUnitary(). Chris@191: * Chris@191: * The in and out pointers must point to (enough space for) n Chris@191: * values. Chris@191: */ Chris@191: void inverseUnitary(const double *in, double *out); Chris@191: Chris@191: private: Chris@191: int m_n; Chris@191: double m_scale; Chris@191: std::vector m_scaled; Chris@191: std::vector m_time2; Chris@191: std::vector m_freq2r; Chris@191: std::vector m_freq2i; Chris@191: FFTReal m_fft; Chris@191: }; Chris@191: Chris@191: #endif