Mercurial > hg > svcore
comparison transform/FeatureExtractionPluginTransform.cpp @ 132:06aba53ea0cf
* Update FeatureExtractionPluginTransform to use FFT fuzzy server. The results
seem to contain a lot of gaps -- investigate (with chromagram plugin)
author | Chris Cannam |
---|---|
date | Fri, 30 Jun 2006 11:47:52 +0000 |
parents | 69d50575c52a |
children | b18b07474e11 |
comparison
equal
deleted
inserted
replaced
131:69d50575c52a | 132:06aba53ea0cf |
---|---|
24 #include "model/SparseOneDimensionalModel.h" | 24 #include "model/SparseOneDimensionalModel.h" |
25 #include "model/SparseTimeValueModel.h" | 25 #include "model/SparseTimeValueModel.h" |
26 #include "model/DenseThreeDimensionalModel.h" | 26 #include "model/DenseThreeDimensionalModel.h" |
27 #include "model/DenseTimeValueModel.h" | 27 #include "model/DenseTimeValueModel.h" |
28 #include "model/NoteModel.h" | 28 #include "model/NoteModel.h" |
29 | 29 #include "fileio/FFTFuzzyAdapter.h" |
30 #include "fileio/FFTDataServer.h" | |
31 | 30 |
32 #include <fftw3.h> | 31 #include <fftw3.h> |
33 | 32 |
34 #include <iostream> | 33 #include <iostream> |
35 | 34 |
240 float **buffers = new float*[channelCount]; | 239 float **buffers = new float*[channelCount]; |
241 for (size_t ch = 0; ch < channelCount; ++ch) { | 240 for (size_t ch = 0; ch < channelCount; ++ch) { |
242 buffers[ch] = new float[m_blockSize]; | 241 buffers[ch] = new float[m_blockSize]; |
243 } | 242 } |
244 | 243 |
245 /*!!! | |
246 float *fftInput = 0; | |
247 fftwf_complex *fftOutput = 0; | |
248 fftwf_plan fftPlan = 0; | |
249 Window<float> windower(HanningWindow, m_blockSize); | |
250 | |
251 if (m_plugin->getInputDomain() == Vamp::Plugin::FrequencyDomain) { | |
252 | |
253 fftInput = (float *)fftwf_malloc(m_blockSize * sizeof(double)); | |
254 fftOutput = (fftwf_complex *)fftwf_malloc(m_blockSize * sizeof(fftwf_complex)); | |
255 fftPlan = fftwf_plan_dft_r2c_1d(m_blockSize, fftInput, fftOutput, | |
256 FFTW_ESTIMATE); | |
257 if (!fftPlan) { | |
258 std::cerr << "ERROR: FeatureExtractionPluginTransform::run(): fftw_plan failed! Results will be garbage" << std::endl; | |
259 } | |
260 } | |
261 */ | |
262 | |
263 bool frequencyDomain = (m_plugin->getInputDomain() == | 244 bool frequencyDomain = (m_plugin->getInputDomain() == |
264 Vamp::Plugin::FrequencyDomain); | 245 Vamp::Plugin::FrequencyDomain); |
265 std::vector<FFTDataServer *> fftServers; | 246 std::vector<FFTFuzzyAdapter *> fftAdapters; |
266 | |
267 //!!! use fuzzy fft server matching! | |
268 | 247 |
269 if (frequencyDomain) { | 248 if (frequencyDomain) { |
270 for (size_t ch = 0; ch < channelCount; ++ch) { | 249 for (size_t ch = 0; ch < channelCount; ++ch) { |
271 fftServers.push_back(FFTDataServer::getInstance | 250 fftAdapters.push_back(new FFTFuzzyAdapter |
272 (getInput(), | 251 (getInput(), |
273 channelCount == 1 ? m_channel : ch, | 252 channelCount == 1 ? m_channel : ch, |
274 HanningWindow, | 253 HanningWindow, |
275 m_blockSize, | 254 m_blockSize, |
276 m_stepSize, | 255 m_stepSize, |
277 m_blockSize, | 256 m_blockSize, |
278 false)); | 257 false)); |
279 } | 258 } |
280 } | 259 } |
281 | 260 |
282 long startFrame = m_input->getStartFrame(); | 261 long startFrame = m_input->getStartFrame(); |
283 long endFrame = m_input->getEndFrame(); | 262 long endFrame = m_input->getEndFrame(); |
301 ( (endFrame - startFrame) / m_stepSize); | 280 ( (endFrame - startFrame) / m_stepSize); |
302 | 281 |
303 // channelCount is either m_input->channelCount or 1 | 282 // channelCount is either m_input->channelCount or 1 |
304 | 283 |
305 for (size_t ch = 0; ch < channelCount; ++ch) { | 284 for (size_t ch = 0; ch < channelCount; ++ch) { |
306 //!!! if (fftPlan) { | |
307 // getFrames(ch, channelCount, | |
308 // blockFrame - m_blockSize/2, m_blockSize, buffers[ch]); | |
309 | |
310 if (frequencyDomain) { | 285 if (frequencyDomain) { |
311 int column = (blockFrame - startFrame) / m_stepSize; | 286 int column = (blockFrame - startFrame) / m_stepSize; |
312 for (size_t i = 0; i < m_blockSize/2; ++i) { | 287 for (size_t i = 0; i < m_blockSize/2; ++i) { |
313 fftServers[ch]->getValuesAt | 288 fftAdapters[ch]->getValuesAt |
314 (column, i, buffers[ch][i*2], buffers[ch][i*2+1]); | 289 (column, i, buffers[ch][i*2], buffers[ch][i*2+1]); |
315 } | 290 } |
316 } else { | 291 } else { |
317 getFrames(ch, channelCount, | 292 getFrames(ch, channelCount, |
318 blockFrame, m_blockSize, buffers[ch]); | 293 blockFrame, m_blockSize, buffers[ch]); |
319 } | 294 } |
320 } | 295 } |
321 /*!!! | 296 |
322 if (fftPlan) { | |
323 for (size_t ch = 0; ch < channelCount; ++ch) { | |
324 for (size_t i = 0; i < m_blockSize; ++i) { | |
325 fftInput[i] = buffers[ch][i]; | |
326 } | |
327 windower.cut(fftInput); | |
328 for (size_t i = 0; i < m_blockSize/2; ++i) { | |
329 float temp = fftInput[i]; | |
330 fftInput[i] = fftInput[i + m_blockSize/2]; | |
331 fftInput[i + m_blockSize/2] = temp; | |
332 } | |
333 fftwf_execute(fftPlan); | |
334 for (size_t i = 0; i < m_blockSize/2; ++i) { | |
335 buffers[ch][i*2] = fftOutput[i][0]; | |
336 buffers[ch][i*2 + 1] = fftOutput[i][1]; | |
337 } | |
338 } | |
339 } | |
340 */ | |
341 Vamp::Plugin::FeatureSet features = m_plugin->process | 297 Vamp::Plugin::FeatureSet features = m_plugin->process |
342 (buffers, Vamp::RealTime::frame2RealTime(blockFrame, sampleRate)); | 298 (buffers, Vamp::RealTime::frame2RealTime(blockFrame, sampleRate)); |
343 | 299 |
344 for (size_t fi = 0; fi < features[m_outputFeatureNo].size(); ++fi) { | 300 for (size_t fi = 0; fi < features[m_outputFeatureNo].size(); ++fi) { |
345 Vamp::Plugin::Feature feature = | 301 Vamp::Plugin::Feature feature = |
352 prevCompletion = completion; | 308 prevCompletion = completion; |
353 } | 309 } |
354 | 310 |
355 blockFrame += m_stepSize; | 311 blockFrame += m_stepSize; |
356 } | 312 } |
357 /*!!! | 313 |
358 if (fftPlan) { | |
359 fftwf_destroy_plan(fftPlan); | |
360 fftwf_free(fftInput); | |
361 fftwf_free(fftOutput); | |
362 } | |
363 */ | |
364 Vamp::Plugin::FeatureSet features = m_plugin->getRemainingFeatures(); | 314 Vamp::Plugin::FeatureSet features = m_plugin->getRemainingFeatures(); |
365 | 315 |
366 for (size_t fi = 0; fi < features[m_outputFeatureNo].size(); ++fi) { | 316 for (size_t fi = 0; fi < features[m_outputFeatureNo].size(); ++fi) { |
367 Vamp::Plugin::Feature feature = | 317 Vamp::Plugin::Feature feature = |
368 features[m_outputFeatureNo][fi]; | 318 features[m_outputFeatureNo][fi]; |
369 addFeature(blockFrame, feature); | 319 addFeature(blockFrame, feature); |
320 } | |
321 | |
322 if (frequencyDomain) { | |
323 for (size_t ch = 0; ch < channelCount; ++ch) { | |
324 delete fftAdapters[ch]; | |
325 } | |
370 } | 326 } |
371 | 327 |
372 setCompletion(100); | 328 setCompletion(100); |
373 } | 329 } |
374 | 330 |