comparison src/FeatureExtractor.cpp @ 184:6c12db195986 re-minimise

Some fixes (still does not yet build)
author Chris Cannam
date Thu, 26 Feb 2015 09:55:28 +0000
parents 24ddab06aace
children 487261a22b18
comparison
equal deleted inserted replaced
183:24ddab06aace 184:6c12db195986
155 } 155 }
156 156
157 feature_t 157 feature_t
158 FeatureExtractor::process(const vector<double> &real, const vector<double> &imag) 158 FeatureExtractor::process(const vector<double> &real, const vector<double> &imag)
159 { 159 {
160 vector<double> mags(m_params.fftSize/2 + 1, 0.0); 160 vector<float> mags(m_params.fftSize/2 + 1, 0.0);
161
162 for (int i = 0; i <= m_params.fftSize/2; i++) {
163 mags[i] = float(real[i] * real[i] + imag[i] * imag[i]);
164 }
165
166 return processMags(mags);
167 }
168
169 feature_t
170 FeatureExtractor::process(const vector<float> &real, const vector<float> &imag)
171 {
172 vector<float> mags(m_params.fftSize/2 + 1, 0.0);
161 173
162 for (int i = 0; i <= m_params.fftSize/2; i++) { 174 for (int i = 0; i <= m_params.fftSize/2; i++) {
163 mags[i] = real[i] * real[i] + imag[i] * imag[i]; 175 mags[i] = real[i] * real[i] + imag[i] * imag[i];
164 } 176 }
165 177
167 } 179 }
168 180
169 feature_t 181 feature_t
170 FeatureExtractor::process(const float *cframe) 182 FeatureExtractor::process(const float *cframe)
171 { 183 {
172 vector<double> mags(m_params.fftSize/2 + 1, 0.0); 184 vector<float> mags(m_params.fftSize/2 + 1, 0.0);
173 185
174 for (int i = 0; i <= m_params.fftSize/2; i++) { 186 for (int i = 0; i <= m_params.fftSize/2; i++) {
175 mags[i] = cframe[i*2] * cframe[i*2] + cframe[i*2+1] * cframe[i*2+1]; 187 mags[i] = cframe[i*2] * cframe[i*2] + cframe[i*2+1] * cframe[i*2+1];
176 } 188 }
177 189
178 return processMags(mags); 190 return processMags(mags);
179 } 191 }
180 192
181 feature_t 193 feature_t
182 FeatureExtractor::processMags(const vector<double> &mags) 194 FeatureExtractor::processMags(const vector<float> &mags)
183 { 195 {
184 feature_t frame(m_featureSize, 0.0); 196 feature_t frame(m_featureSize, 0.0);
185 197
186 if (!m_params.useChromaFrequencyMap && 198 if (!m_params.useChromaFrequencyMap &&
187 (m_params.referenceFrequency != 440.)) { 199 (m_params.referenceFrequency != 440.)) {
188 200
189 // See comment in makeStandardFrequencyMap above 201 // See comment in makeStandardFrequencyMap above
190 vector<double> scaled = scaleMags(mags); 202 vector<float> scaled = scaleMags(mags);
191 203
192 for (int i = 0; i <= m_params.fftSize/2; i++) { 204 for (int i = 0; i <= m_params.fftSize/2; i++) {
193 int index = m_freqMap[i]; 205 int index = m_freqMap[i];
194 if (index >= 0) { 206 if (index >= 0) {
195 frame[index] += scaled[i]; 207 frame[index] += scaled[i];
206 } 218 }
207 219
208 return frame; 220 return frame;
209 } 221 }
210 222
211 vector<double> 223 vector<float>
212 FeatureExtractor::scaleMags(const vector<double> &mags) 224 FeatureExtractor::scaleMags(const vector<float> &mags)
213 { 225 {
214 // Scale the pitch content in the given magnitude spectrum to 226 // Scale the pitch content in the given magnitude spectrum to
215 // accommodate a difference in tuning frequency (between the 440Hz 227 // accommodate a difference in tuning frequency (between the 440Hz
216 // reference and the actual tuning frequency of the input audio). 228 // reference and the actual tuning frequency of the input audio).
217 // We only do this when not using chroma features -- see the 229 // We only do this when not using chroma features -- see the
218 // comment in makeStandardFrequencyMap() above. 230 // comment in makeStandardFrequencyMap() above.
219 231
220 if (m_params.useChromaFrequencyMap) return mags; 232 if (m_params.useChromaFrequencyMap) return mags;
221 233
222 double ratio = 440. / m_params.referenceFrequency; 234 double ratio = 440.f / m_params.referenceFrequency;
223 235
224 int n = static_cast<int>(mags.size()); 236 int n = static_cast<int>(mags.size());
225 237
226 vector<double> scaled(n, 0.0); 238 vector<float> scaled(n, 0.0);
227 239
228 for (int target = 0; target < n; ++target) { 240 for (int target = 0; target < n; ++target) {
229 241
230 double source = target / ratio; 242 double source = target / ratio;
231 243
241 } 253 }
242 if (higher >= 0 && higher < n) { 254 if (higher >= 0 && higher < n) {
243 value += higherProp * mags[higher]; 255 value += higherProp * mags[higher];
244 } 256 }
245 257
246 scaled[target] = value; 258 scaled[target] = float(value);
247 } 259 }
248 260
249 return scaled; 261 return scaled;
250 } 262 }
251 263