# HG changeset patch # User Chris Cannam # Date 1381857998 -3600 # Node ID a586888bc06ca88f03d546faacacb6a077fba995 # Parent 2053a308bb4d38b23e68387923f52c75acf3bb6f Add forwardMagnitude diff -r 2053a308bb4d -r a586888bc06c dsp/phasevocoder/PhaseVocoder.h --- a/dsp/phasevocoder/PhaseVocoder.h Tue Oct 15 11:52:00 2013 +0100 +++ b/dsp/phasevocoder/PhaseVocoder.h Tue Oct 15 18:26:38 2013 +0100 @@ -21,7 +21,6 @@ class PhaseVocoder { public: - //!!! review: size must be a power of two, or not? PhaseVocoder(int size, int hop); virtual ~PhaseVocoder(); diff -r 2053a308bb4d -r a586888bc06c dsp/transforms/FFT.cpp --- a/dsp/transforms/FFT.cpp Tue Oct 15 11:52:00 2013 +0100 +++ b/dsp/transforms/FFT.cpp Tue Oct 15 18:26:38 2013 +0100 @@ -132,6 +132,19 @@ } } + void forwardMagnitude(const double *ri, double *mo) { + + double *io = new double[m_n]; + + forward(ri, mo, io); + + for (int i = 0; i < m_n; ++i) { + mo[i] = sqrt(mo[i] * mo[i] + io[i] * io[i]); + } + + delete[] io; + } + void inverse(const double *ri, const double *ii, double *ro) { for (int i = 0; i < m_n; ++i) { @@ -172,6 +185,12 @@ } void +FFTReal::forwardMagnitude(const double *ri, double *mo) +{ + m_d->forwardMagnitude(ri, mo); +} + +void FFTReal::inverse(const double *ri, const double *ii, double *ro) { m_d->inverse(ri, ii, ro); diff -r 2053a308bb4d -r a586888bc06c dsp/transforms/FFT.h --- a/dsp/transforms/FFT.h Tue Oct 15 11:52:00 2013 +0100 +++ b/dsp/transforms/FFT.h Tue Oct 15 18:26:38 2013 +0100 @@ -49,8 +49,9 @@ /** * Construct an FFT object to carry out real-to-complex transforms * of size nsamples. nsamples does not have to be a power of two, - * but it does have to be even. (A std::invalid_argument exception - * will be thrown if nsamples is odd.) + * but it does have to be even. (Use the complex-complex FFT above + * if you need an odd FFT size. This constructor will throw + * std::invalid_argument if nsamples is odd.) */ FFTReal(int nsamples); ~FFTReal(); @@ -68,6 +69,18 @@ double *realOut, double *imagOut); /** + * Carry out a forward real-to-complex transform of size nsamples, + * where nsamples is the value provided to the constructor + * above. Return only the magnitudes of the complex output values. + * + * realIn and magOut must point to (enough space for) nsamples + * values. For consistency with the FFT class above, and + * compatibility with existing code, the conjugate half of the + * output is returned even though it is redundant. + */ + void forwardMagnitude(const double *realIn, double *magOut); + + /** * Carry out an inverse real transform (i.e. complex-to-real) of * size nsamples, where nsamples is the value provided to the * constructor above.