comparison dsp/onsets/DetectionFunction.cpp @ 130:2053a308bb4d kissfft

Frame length no longer needs to be a power of two
author Chris Cannam
date Tue, 15 Oct 2013 11:52:00 +0100
parents b0e98fcfacd7
children 2ae4ceb76ac3
comparison
equal deleted inserted replaced
129:6ec45e85ed81 130:2053a308bb4d
61 memset(m_phaseHistoryOld,0, m_halfLength*sizeof(double)); 61 memset(m_phaseHistoryOld,0, m_halfLength*sizeof(double));
62 62
63 m_magPeaks = new double[ m_halfLength ]; 63 m_magPeaks = new double[ m_halfLength ];
64 memset(m_magPeaks,0, m_halfLength*sizeof(double)); 64 memset(m_magPeaks,0, m_halfLength*sizeof(double));
65 65
66 // See note in processTimeDomain below 66 m_phaseVoc = new PhaseVocoder(m_dataLength, m_stepSize);
67 int actualLength = MathUtilities::previousPowerOfTwo(m_dataLength);
68 m_phaseVoc = new PhaseVocoder(actualLength, m_stepSize);
69 67
70 m_magnitude = new double[ m_halfLength ]; 68 m_magnitude = new double[ m_halfLength ];
71 m_thetaAngle = new double[ m_halfLength ]; 69 m_thetaAngle = new double[ m_halfLength ];
72 m_unwrapped = new double[ m_halfLength ]; 70 m_unwrapped = new double[ m_halfLength ];
73 71
93 } 91 }
94 92
95 double DetectionFunction::processTimeDomain(const double *samples) 93 double DetectionFunction::processTimeDomain(const double *samples)
96 { 94 {
97 m_window->cut(samples, m_windowed); 95 m_window->cut(samples, m_windowed);
98
99 // Our own FFT implementation supports power-of-two sizes only.
100 // If we have to use this implementation (as opposed to the
101 // version of process() below that operates on frequency domain
102 // data directly), we will have to use the next smallest power of
103 // two from the block size. Results may vary accordingly!
104
105 int actualLength = MathUtilities::previousPowerOfTwo((int)m_dataLength);
106
107 if (actualLength != (int)m_dataLength) {
108 // Pre-fill mag and phase vectors with zero, as the FFT output
109 // will not fill the arrays
110 for (int i = actualLength/2; i < (int)m_dataLength/2; ++i) {
111 m_magnitude[i] = 0;
112 m_thetaAngle[0] = 0;
113 }
114 }
115 96
116 m_phaseVoc->processTimeDomain(m_windowed, 97 m_phaseVoc->processTimeDomain(m_windowed,
117 m_magnitude, m_thetaAngle, m_unwrapped); 98 m_magnitude, m_thetaAngle, m_unwrapped);
118 99
119 if (m_whiten) whiten(); 100 if (m_whiten) whiten();