comparison examples/SpectralCentroid.cpp @ 7:c66551966b5f

* Fix a couple of memory management and corruption bugs * Some textual fixes
author cannam
date Fri, 31 Mar 2006 17:39:49 +0000
parents 8f10d35a4090
children c4662bbef275
comparison
equal deleted inserted replaced
6:8f10d35a4090 7:c66551966b5f
34 authorization. 34 authorization.
35 */ 35 */
36 36
37 #include "SpectralCentroid.h" 37 #include "SpectralCentroid.h"
38 38
39 /*
40 #include "dsp/transforms/FFT.h"
41 #include "base/Window.h"
42 */
43
44 using std::string; 39 using std::string;
45 using std::vector; 40 using std::vector;
46 using std::cerr; 41 using std::cerr;
47 using std::endl; 42 using std::endl;
43
44 #include <cmath>
48 45
49 46
50 SpectralCentroid::SpectralCentroid(float inputSampleRate) : 47 SpectralCentroid::SpectralCentroid(float inputSampleRate) :
51 Plugin(inputSampleRate), 48 Plugin(inputSampleRate),
52 m_stepSize(0), 49 m_stepSize(0),
73 } 70 }
74 71
75 string 72 string
76 SpectralCentroid::getMaker() const 73 SpectralCentroid::getMaker() const
77 { 74 {
78 return "QMUL"; 75 return "Queen Mary, University of London";
79 } 76 }
80 77
81 int 78 int
82 SpectralCentroid::getPluginVersion() const 79 SpectralCentroid::getPluginVersion() const
83 { 80 {
85 } 82 }
86 83
87 string 84 string
88 SpectralCentroid::getCopyright() const 85 SpectralCentroid::getCopyright() const
89 { 86 {
90 return "GPL"; 87 return "Freely redistributable (BSD license)";
91 } 88 }
92 89
93 bool 90 bool
94 SpectralCentroid::initialise(size_t channels, size_t stepSize, size_t blockSize) 91 SpectralCentroid::initialise(size_t channels, size_t stepSize, size_t blockSize)
95 { 92 {
155 << "SpectralCentroid has not been initialised" 152 << "SpectralCentroid has not been initialised"
156 << endl; 153 << endl;
157 return FeatureSet(); 154 return FeatureSet();
158 } 155 }
159 156
160 /*
161 for (size_t i = 0; i < m_blockSize; ++i) {
162 m_workBuffer[i] = inputBuffers[0][i];
163 m_workBuffer[i + m_blockSize] = 0.0;
164 }
165
166 Window<double>(HanningWindow, m_blockSize).cut(m_workBuffer);
167
168 FFT::process(m_blockSize, false,
169 m_workBuffer,
170 m_workBuffer + m_blockSize,
171 m_workBuffer + m_blockSize*2,
172 m_workBuffer + m_blockSize*3);
173 */
174
175 double numLin = 0.0, numLog = 0.0, denom = 0.0; 157 double numLin = 0.0, numLog = 0.0, denom = 0.0;
176 158
177 for (size_t i = 1; i < m_blockSize/2; ++i) { 159 for (size_t i = 1; i < m_blockSize/2; ++i) {
178 double freq = (double(i) * m_inputSampleRate) / m_blockSize; 160 double freq = (double(i) * m_inputSampleRate) / m_blockSize;
179 double real = inputBuffers[0][i*2]; 161 double real = inputBuffers[0][i*2];