comparison dsp/transforms/FFT.cpp @ 280:9c403afdd9e9

* Various fixes related to the bar estimator code
author Chris Cannam <c.cannam@qmul.ac.uk>
date Tue, 10 Feb 2009 16:37:11 +0000
parents 9edaa3ce62e8
children 6cb2b3cd5356
comparison
equal deleted inserted replaced
279:c8908cdc8c32 280:9c403afdd9e9
6 Centre for Digital Music, Queen Mary, University of London. 6 Centre for Digital Music, Queen Mary, University of London.
7 This file is based on Don Cross's public domain FFT implementation. 7 This file is based on Don Cross's public domain FFT implementation.
8 */ 8 */
9 9
10 #include "FFT.h" 10 #include "FFT.h"
11
12 #include "maths/MathUtilities.h"
13
11 #include <cmath> 14 #include <cmath>
15
16 #include <iostream>
12 17
13 ////////////////////////////////////////////////////////////////////// 18 //////////////////////////////////////////////////////////////////////
14 // Construction/Destruction 19 // Construction/Destruction
15 ////////////////////////////////////////////////////////////////////// 20 //////////////////////////////////////////////////////////////////////
16 21
37 unsigned int BlockSize, BlockEnd; 42 unsigned int BlockSize, BlockEnd;
38 43
39 double angle_numerator = 2.0 * M_PI; 44 double angle_numerator = 2.0 * M_PI;
40 double tr, ti; 45 double tr, ti;
41 46
42 if( !isPowerOfTwo(p_nSamples) ) 47 if( !MathUtilities::isPowerOfTwo(p_nSamples) )
43 { 48 {
49 std::cerr << "ERROR: FFT::process: Non-power-of-two FFT size "
50 << p_nSamples << " not supported in this implementation"
51 << std::endl;
44 return; 52 return;
45 } 53 }
46 54
47 if( p_bInverseTransform ) angle_numerator = -angle_numerator; 55 if( p_bInverseTransform ) angle_numerator = -angle_numerator;
48 56
116 p_lpImagOut[i] /= denom; 124 p_lpImagOut[i] /= denom;
117 } 125 }
118 } 126 }
119 } 127 }
120 128
121 bool FFT::isPowerOfTwo(unsigned int p_nX)
122 {
123 if( p_nX < 2 ) return false;
124
125 if( p_nX & (p_nX-1) ) return false;
126
127 return true;
128 }
129
130 unsigned int FFT::numberOfBitsNeeded(unsigned int p_nSamples) 129 unsigned int FFT::numberOfBitsNeeded(unsigned int p_nSamples)
131 { 130 {
132 int i; 131 int i;
133 132
134 if( p_nSamples < 2 ) 133 if( p_nSamples < 2 )