comparison plugins/BeatTrack.cpp @ 85:2631d0b3d7eb

* Ensure beat tracker, onset detector & tonal change detector return results timed from the first input timestamp, not always from zero
author Chris Cannam <c.cannam@qmul.ac.uk>
date Thu, 04 Dec 2008 12:03:51 +0000
parents 4fe04e706839
children e377296d01b2
comparison
equal deleted inserted replaced
84:b5594645adab 85:2631d0b3d7eb
31 } 31 }
32 void reset() { 32 void reset() {
33 delete df; 33 delete df;
34 df = new DetectionFunction(dfConfig); 34 df = new DetectionFunction(dfConfig);
35 dfOutput.clear(); 35 dfOutput.clear();
36 origin = Vamp::RealTime::zeroTime;
36 } 37 }
37 38
38 DFConfig dfConfig; 39 DFConfig dfConfig;
39 DetectionFunction *df; 40 DetectionFunction *df;
40 vector<double> dfOutput; 41 vector<double> dfOutput;
42 Vamp::RealTime origin;
41 }; 43 };
42 44
43 45
44 BeatTracker::BeatTracker(float inputSampleRate) : 46 BeatTracker::BeatTracker(float inputSampleRate) :
45 Vamp::Plugin(inputSampleRate), 47 Vamp::Plugin(inputSampleRate),
270 return list; 272 return list;
271 } 273 }
272 274
273 BeatTracker::FeatureSet 275 BeatTracker::FeatureSet
274 BeatTracker::process(const float *const *inputBuffers, 276 BeatTracker::process(const float *const *inputBuffers,
275 Vamp::RealTime /* timestamp */) 277 Vamp::RealTime timestamp)
276 { 278 {
277 if (!m_d) { 279 if (!m_d) {
278 cerr << "ERROR: BeatTracker::process: " 280 cerr << "ERROR: BeatTracker::process: "
279 << "BeatTracker has not been initialised" 281 << "BeatTracker has not been initialised"
280 << endl; 282 << endl;
298 300
299 double output = m_d->df->process(magnitudes, phases); 301 double output = m_d->df->process(magnitudes, phases);
300 302
301 delete[] magnitudes; 303 delete[] magnitudes;
302 delete[] phases; 304 delete[] phases;
305
306 if (m_d->dfOutput.empty()) m_d->origin = timestamp;
303 307
304 m_d->dfOutput.push_back(output); 308 m_d->dfOutput.push_back(output);
305 309
306 FeatureSet returnFeatures; 310 FeatureSet returnFeatures;
307 311
349 353
350 size_t frame = beats[i] * m_d->dfConfig.stepSize; 354 size_t frame = beats[i] * m_d->dfConfig.stepSize;
351 355
352 Feature feature; 356 Feature feature;
353 feature.hasTimestamp = true; 357 feature.hasTimestamp = true;
354 feature.timestamp = Vamp::RealTime::frame2RealTime 358 feature.timestamp = m_d->origin + Vamp::RealTime::frame2RealTime
355 (frame, lrintf(m_inputSampleRate)); 359 (frame, lrintf(m_inputSampleRate));
356 360
357 float bpm = 0.0; 361 float bpm = 0.0;
358 int frameIncrement = 0; 362 int frameIncrement = 0;
359 363
385 // std::cerr << "unit " << i << ", step size " << m_d->dfConfig.stepSize << ", hop " << ttParams.lagLength << ", frame = " << frame << std::endl; 389 // std::cerr << "unit " << i << ", step size " << m_d->dfConfig.stepSize << ", hop " << ttParams.lagLength << ", frame = " << frame << std::endl;
386 390
387 if (tempos[i] > 1 && int(tempos[i] * 100) != int(prevTempo * 100)) { 391 if (tempos[i] > 1 && int(tempos[i] * 100) != int(prevTempo * 100)) {
388 Feature feature; 392 Feature feature;
389 feature.hasTimestamp = true; 393 feature.hasTimestamp = true;
390 feature.timestamp = Vamp::RealTime::frame2RealTime 394 feature.timestamp = m_d->origin + Vamp::RealTime::frame2RealTime
391 (frame, lrintf(m_inputSampleRate)); 395 (frame, lrintf(m_inputSampleRate));
392 feature.values.push_back(tempos[i]); 396 feature.values.push_back(tempos[i]);
393 sprintf(label, "%.2f bpm", tempos[i]); 397 sprintf(label, "%.2f bpm", tempos[i]);
394 feature.label = label; 398 feature.label = label;
395 returnFeatures[2].push_back(feature); // tempo is output 2 399 returnFeatures[2].push_back(feature); // tempo is output 2