comparison TempogramPlugin.cpp @ 23:7d36c742a183

* Tidying in TempogramPlugin.cpp
author Carl Bussey <c.bussey@se10.qmul.ac.uk>
date Tue, 19 Aug 2014 17:40:10 +0100
parents 99380ba63be6
children 957b83524c06
comparison
equal deleted inserted replaced
22:99380ba63be6 23:7d36c742a183
400 } 400 }
401 401
402 TempogramPlugin::FeatureSet 402 TempogramPlugin::FeatureSet
403 TempogramPlugin::process(const float *const *inputBuffers, Vamp::RealTime timestamp) 403 TempogramPlugin::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
404 { 404 {
405 //cerr << "Here" << endl; 405
406 406 int n = m_inputBlockSize/2 + 1;
407 size_t n = m_inputBlockSize/2 + 1;
408
409 FeatureSet featureSet;
410 Feature feature;
411
412 const float *in = inputBuffers[0]; 407 const float *in = inputBuffers[0];
413 408
414 //calculate magnitude of FrequencyDomain input 409 //calculate magnitude of FrequencyDomain input
415 vector<float> fftCoefficients; 410 vector<float> fftCoefficients;
416 for (int i = 0; i < (int)n; i++){ 411 for (int i = 0; i < n; i++){
417 float magnitude = sqrt(in[2*i] * in[2*i] + in[2*i + 1] * in[2*i + 1]); 412 float magnitude = sqrt(in[2*i] * in[2*i] + in[2*i + 1] * in[2*i + 1]);
418 magnitude = magnitude > m_noveltyCurveMinDB ? magnitude : m_noveltyCurveMinDB; 413 magnitude = magnitude > m_noveltyCurveMinDB ? magnitude : m_noveltyCurveMinDB;
419 fftCoefficients.push_back(magnitude); 414 fftCoefficients.push_back(magnitude);
420 } 415 }
421 m_spectrogram.push_back(fftCoefficients); 416 m_spectrogram.push_back(fftCoefficients);
422 417
423 return featureSet; 418 return FeatureSet();
424 } 419 }
425 420
426 TempogramPlugin::FeatureSet 421 TempogramPlugin::FeatureSet
427 TempogramPlugin::getRemainingFeatures() 422 TempogramPlugin::getRemainingFeatures()
428 { 423 {
433 } 428 }
434 429
435 FeatureSet featureSet; 430 FeatureSet featureSet;
436 431
437 //initialise novelty curve processor 432 //initialise novelty curve processor
438 size_t numberOfBlocks = m_spectrogram.size(); 433 int numberOfBlocks = m_spectrogram.size();
439 //cerr << numberOfBlocks << endl; 434 //cerr << numberOfBlocks << endl;
440 NoveltyCurveProcessor nc(m_inputSampleRate, m_inputBlockSize, m_noveltyCurveCompressionConstant); 435 NoveltyCurveProcessor nc(m_inputSampleRate, m_inputBlockSize, m_noveltyCurveCompressionConstant);
441 vector<float> noveltyCurve = nc.spectrogramToNoveltyCurve(m_spectrogram); //calculate novelty curvefrom magnitude data 436 vector<float> noveltyCurve = nc.spectrogramToNoveltyCurve(m_spectrogram); //calculate novelty curvefrom magnitude data
442 //if(noveltyCurve.size() > 50) for (int i = 0; i < 50; i++) cerr << noveltyCurve[i] << endl; 437 //if(noveltyCurve.size() > 50) for (int i = 0; i < 50; i++) cerr << noveltyCurve[i] << endl;
443 438
444 //push novelty curve data to featureset 1 and set timestamps 439 //push novelty curve data to featureset 1 and set timestamps
445 for (int i = 0; i < (int)numberOfBlocks; i++){ 440 for (int i = 0; i < numberOfBlocks; i++){
446 Feature noveltyCurveFeature; 441 Feature noveltyCurveFeature;
447 noveltyCurveFeature.values.push_back(noveltyCurve[i]); 442 noveltyCurveFeature.values.push_back(noveltyCurve[i]);
448 noveltyCurveFeature.hasTimestamp = false; 443 noveltyCurveFeature.hasTimestamp = false;
449 featureSet[2].push_back(noveltyCurveFeature); 444 featureSet[2].push_back(noveltyCurveFeature);
450 assert(!isnan(noveltyCurveFeature.values.back())); 445 assert(!isnan(noveltyCurveFeature.values.back()));
480 475
481 //assert((int)logBins.size() == m_cyclicTempogramOctaveDivider*m_cyclicTempogramNumberOfOctaves); 476 //assert((int)logBins.size() == m_cyclicTempogramOctaveDivider*m_cyclicTempogramNumberOfOctaves);
482 for (int block = 0; block < tempogramLength; block++){ 477 for (int block = 0; block < tempogramLength; block++){
483 Feature cyclicTempogramFeature; 478 Feature cyclicTempogramFeature;
484 479
485 for (int i = 0; i < (int)m_cyclicTempogramOctaveDivider; i++){ 480 for (int i = 0; i < m_cyclicTempogramOctaveDivider; i++){
486 float sum = 0; 481 float sum = 0;
487 482
488 for (int j = 0; j < (int)m_cyclicTempogramNumberOfOctaves; j++){ 483 for (int j = 0; j < m_cyclicTempogramNumberOfOctaves; j++){
489 sum += tempogram[block][logBins[j][i]]; 484 sum += tempogram[block][logBins[j][i]];
490 } 485 }
491 cyclicTempogramFeature.values.push_back(sum/m_cyclicTempogramNumberOfOctaves); 486 cyclicTempogramFeature.values.push_back(sum/m_cyclicTempogramNumberOfOctaves);
492 assert(!isnan(cyclicTempogramFeature.values.back())); 487 assert(!isnan(cyclicTempogramFeature.values.back()));
493 } 488 }
506 for (int octave = 0; octave < (int)m_cyclicTempogramNumberOfOctaves; octave++){ 501 for (int octave = 0; octave < (int)m_cyclicTempogramNumberOfOctaves; octave++){
507 vector<unsigned int> octaveBins; 502 vector<unsigned int> octaveBins;
508 503
509 for (int bin = 0; bin < (int)m_cyclicTempogramOctaveDivider; bin++){ 504 for (int bin = 0; bin < (int)m_cyclicTempogramOctaveDivider; bin++){
510 float bpm = m_cyclicTempogramMinBPM*pow(2.0f, octave+(float)bin/m_cyclicTempogramOctaveDivider); 505 float bpm = m_cyclicTempogramMinBPM*pow(2.0f, octave+(float)bin/m_cyclicTempogramOctaveDivider);
511
512 octaveBins.push_back(bpmToBin(bpm)); 506 octaveBins.push_back(bpmToBin(bpm));
507 //cout << octaveBins.back() << endl;
513 } 508 }
514 logBins.push_back(octaveBins); 509 logBins.push_back(octaveBins);
515 } 510 }
516 511
517 //cerr << logBins.size() << endl; 512 //cerr << logBins.size() << endl;