diff plugins/OnsetDetect.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 df7a0bc46592
children d47b22cf47bc
line wrap: on
line diff
--- a/plugins/OnsetDetect.cpp	Mon Dec 01 19:55:43 2008 +0000
+++ b/plugins/OnsetDetect.cpp	Thu Dec 04 12:03:51 2008 +0000
@@ -33,11 +33,13 @@
 	delete df;
 	df = new DetectionFunction(dfConfig);
 	dfOutput.clear();
+        origin = Vamp::RealTime::zeroTime;
     }
 
     DFConfig dfConfig;
     DetectionFunction *df;
     vector<double> dfOutput;
+    Vamp::RealTime origin;
 };
     
 
@@ -376,6 +378,8 @@
     delete[] magnitudes;
     delete[] phases;
 
+    if (m_d->dfOutput.empty()) m_d->origin = timestamp;
+
     m_d->dfOutput.push_back(output);
 
     FeatureSet returnFeatures;
@@ -461,7 +465,7 @@
 
 	Feature feature;
 	feature.hasTimestamp = true;
-	feature.timestamp = Vamp::RealTime::frame2RealTime
+	feature.timestamp = m_d->origin + Vamp::RealTime::frame2RealTime
 	    (frame, lrintf(m_inputSampleRate));
 
 	returnFeatures[0].push_back(feature); // onsets are output 0
@@ -473,7 +477,7 @@
 //        feature.hasTimestamp = false;
         feature.hasTimestamp = true;
 	size_t frame = i * m_d->dfConfig.stepSize;
-	feature.timestamp = Vamp::RealTime::frame2RealTime
+	feature.timestamp = m_d->origin + Vamp::RealTime::frame2RealTime
 	    (frame, lrintf(m_inputSampleRate));
 
         feature.values.push_back(ppSrc[i]);