comparison examples/SpectralCentroid.cpp @ 255:88ef5ffdbe8d

* docs
author cannam
date Wed, 12 Nov 2008 14:11:01 +0000
parents 3cf5bd155e5b
children 91574fc544db
comparison
equal deleted inserted replaced
254:e02c93c4de8f 255:88ef5ffdbe8d
135 list.push_back(d); 135 list.push_back(d);
136 136
137 return list; 137 return list;
138 } 138 }
139 139
140 //static int scount = 0;
141
142 SpectralCentroid::FeatureSet 140 SpectralCentroid::FeatureSet
143 SpectralCentroid::process(const float *const *inputBuffers, Vamp::RealTime timestamp) 141 SpectralCentroid::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
144 { 142 {
145 if (m_stepSize == 0) { 143 if (m_stepSize == 0) {
146 cerr << "ERROR: SpectralCentroid::process: " 144 cerr << "ERROR: SpectralCentroid::process: "
147 << "SpectralCentroid has not been initialised" 145 << "SpectralCentroid has not been initialised"
148 << endl; 146 << endl;
149 return FeatureSet(); 147 return FeatureSet();
150 } 148 }
151
152 // std::cerr << "SpectralCentroid::process: count = " << scount++ << ", timestamp = " << timestamp << ", total power = ";
153 149
154 double numLin = 0.0, numLog = 0.0, denom = 0.0; 150 double numLin = 0.0, numLog = 0.0, denom = 0.0;
155 151
156 for (size_t i = 1; i <= m_blockSize/2; ++i) { 152 for (size_t i = 1; i <= m_blockSize/2; ++i) {
157 double freq = (double(i) * m_inputSampleRate) / m_blockSize; 153 double freq = (double(i) * m_inputSampleRate) / m_blockSize;
160 double scalemag = sqrt(real * real + imag * imag) / (m_blockSize/2); 156 double scalemag = sqrt(real * real + imag * imag) / (m_blockSize/2);
161 numLin += freq * scalemag; 157 numLin += freq * scalemag;
162 numLog += log10f(freq) * scalemag; 158 numLog += log10f(freq) * scalemag;
163 denom += scalemag; 159 denom += scalemag;
164 } 160 }
165
166 // std::cerr << denom << std::endl;
167 161
168 FeatureSet returnFeatures; 162 FeatureSet returnFeatures;
169 163
170 if (denom != 0.0) { 164 if (denom != 0.0) {
171 float centroidLin = float(numLin / denom); 165 float centroidLin = float(numLin / denom);