Mercurial > hg > vamp-plugin-sdk
comparison examples/SpectralCentroid.cpp @ 243:3cf5bd155e5b
* Some build improvements
* Make parameterisable values in tempo estimator into parameters
author | cannam |
---|---|
date | Mon, 10 Nov 2008 22:04:40 +0000 |
parents | 6b30e064cab7 |
children | 88ef5ffdbe8d |
comparison
equal
deleted
inserted
replaced
242:7f3a806ed1df | 243:3cf5bd155e5b |
---|---|
155 | 155 |
156 for (size_t i = 1; i <= m_blockSize/2; ++i) { | 156 for (size_t i = 1; i <= m_blockSize/2; ++i) { |
157 double freq = (double(i) * m_inputSampleRate) / m_blockSize; | 157 double freq = (double(i) * m_inputSampleRate) / m_blockSize; |
158 double real = inputBuffers[0][i*2]; | 158 double real = inputBuffers[0][i*2]; |
159 double imag = inputBuffers[0][i*2 + 1]; | 159 double imag = inputBuffers[0][i*2 + 1]; |
160 double power = sqrt(real * real + imag * imag) / (m_blockSize/2); | 160 double scalemag = sqrt(real * real + imag * imag) / (m_blockSize/2); |
161 numLin += freq * power; | 161 numLin += freq * scalemag; |
162 numLog += log10f(freq) * power; | 162 numLog += log10f(freq) * scalemag; |
163 denom += power; | 163 denom += scalemag; |
164 } | 164 } |
165 | 165 |
166 // std::cerr << denom << std::endl; | 166 // std::cerr << denom << std::endl; |
167 | 167 |
168 FeatureSet returnFeatures; | 168 FeatureSet returnFeatures; |
171 float centroidLin = float(numLin / denom); | 171 float centroidLin = float(numLin / denom); |
172 float centroidLog = powf(10, float(numLog / denom)); | 172 float centroidLog = powf(10, float(numLog / denom)); |
173 | 173 |
174 Feature feature; | 174 Feature feature; |
175 feature.hasTimestamp = false; | 175 feature.hasTimestamp = false; |
176 if (!isnan(centroidLog) && !isinf(centroidLog)) { | 176 |
177 feature.values.push_back(centroidLog); | 177 if (!isnan(centroidLog) && !isinf(centroidLog)) { |
178 } | 178 feature.values.push_back(centroidLog); |
179 } | |
179 returnFeatures[0].push_back(feature); | 180 returnFeatures[0].push_back(feature); |
180 | 181 |
181 feature.values.clear(); | 182 feature.values.clear(); |
182 if (!isnan(centroidLin) && !isinf(centroidLin)) { | 183 if (!isnan(centroidLin) && !isinf(centroidLin)) { |
183 feature.values.push_back(centroidLin); | 184 feature.values.push_back(centroidLin); |
184 } | 185 } |
185 returnFeatures[1].push_back(feature); | 186 returnFeatures[1].push_back(feature); |
186 } | 187 } |
187 | 188 |
188 return returnFeatures; | 189 return returnFeatures; |
189 } | 190 } |