changeset 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 b5594645adab
children e377296d01b2
files plugins/BeatTrack.cpp plugins/OnsetDetect.cpp plugins/TonalChangeDetect.cpp plugins/TonalChangeDetect.h
diffstat 4 files changed, 34 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/BeatTrack.cpp	Mon Dec 01 19:55:43 2008 +0000
+++ b/plugins/BeatTrack.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;
 };
     
 
@@ -272,7 +274,7 @@
 
 BeatTracker::FeatureSet
 BeatTracker::process(const float *const *inputBuffers,
-                     Vamp::RealTime /* timestamp */)
+                     Vamp::RealTime timestamp)
 {
     if (!m_d) {
 	cerr << "ERROR: BeatTracker::process: "
@@ -301,6 +303,8 @@
     delete[] magnitudes;
     delete[] phases;
 
+    if (m_d->dfOutput.empty()) m_d->origin = timestamp;
+
     m_d->dfOutput.push_back(output);
 
     FeatureSet returnFeatures;
@@ -351,7 +355,7 @@
 
 	Feature feature;
 	feature.hasTimestamp = true;
-	feature.timestamp = Vamp::RealTime::frame2RealTime
+	feature.timestamp = m_d->origin + Vamp::RealTime::frame2RealTime
 	    (frame, lrintf(m_inputSampleRate));
 
 	float bpm = 0.0;
@@ -387,7 +391,7 @@
         if (tempos[i] > 1 && int(tempos[i] * 100) != int(prevTempo * 100)) {
             Feature feature;
             feature.hasTimestamp = true;
-            feature.timestamp = Vamp::RealTime::frame2RealTime
+            feature.timestamp = m_d->origin + Vamp::RealTime::frame2RealTime
                 (frame, lrintf(m_inputSampleRate));
             feature.values.push_back(tempos[i]);
             sprintf(label, "%.2f bpm", tempos[i]);
--- 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]);
--- a/plugins/TonalChangeDetect.cpp	Mon Dec 01 19:55:43 2008 +0000
+++ b/plugins/TonalChangeDetect.cpp	Thu Dec 04 12:03:51 2008 +0000
@@ -18,7 +18,9 @@
       m_chromagram(0),
       m_step(0),
       m_block(0),
-      m_stepDelay(0)
+      m_stepDelay(0),
+      m_origin(Vamp::RealTime::zeroTime),
+      m_haveOrigin(false)
 {
     m_minMIDIPitch = 32;
     m_maxMIDIPitch = 108;
@@ -44,7 +46,7 @@
         std::cerr << "TonalChangeDetect::initialise: Given channel count " << channels << " outside acceptable range (" << getMinChannelCount() << " to " << getMaxChannelCount() << ")" << std::endl;
         return false;
     }
-	
+
     m_chromagram = new Chromagram(m_config);
     m_step = m_chromagram->getHopSize();
     m_block = m_chromagram->getFrameSize();
@@ -221,6 +223,9 @@
     while (!m_pending.empty()) m_pending.pop();
 	
     m_vaCurrentVector.resize(12, 0.0);
+
+    m_origin = Vamp::RealTime::zeroTime;
+    m_haveOrigin = false;
 }
 
 size_t
@@ -306,6 +311,8 @@
 	return FeatureSet();
     }
 
+    if (!m_haveOrigin) m_origin = timestamp;
+
     // convert float* to double*
     double *tempBuffer = new double[m_block];
     for (size_t i = 0; i < m_block; ++i) {
@@ -399,7 +406,8 @@
         Feature feature;
         feature.label = "";
         feature.hasTimestamp = true;
-        feature.timestamp = Vamp::RealTime::frame2RealTime(i*m_step, m_inputSampleRate);
+        feature.timestamp = m_origin +
+            Vamp::RealTime::frame2RealTime(i*m_step, m_inputSampleRate);
         feature.values.push_back(dCurrent);
         returnFeatures[1].push_back(feature);
 
@@ -409,7 +417,8 @@
             Feature featurePeak;
             featurePeak.label = "";
             featurePeak.hasTimestamp = true;
-            featurePeak.timestamp = Vamp::RealTime::frame2RealTime(i*m_step, m_inputSampleRate);
+            featurePeak.timestamp = m_origin +
+                Vamp::RealTime::frame2RealTime(i*m_step, m_inputSampleRate);
             returnFeatures[2].push_back(featurePeak);
         }
 
--- a/plugins/TonalChangeDetect.h	Mon Dec 01 19:55:43 2008 +0000
+++ b/plugins/TonalChangeDetect.h	Thu Dec 04 12:03:51 2008 +0000
@@ -54,25 +54,25 @@
     FeatureSet getRemainingFeatures();
 	
 private:
-	void setupConfig();
+    void setupConfig();
 
     ChromaConfig m_config;
     Chromagram *m_chromagram;
-	TonalEstimator m_TonalEstimator;
+    TonalEstimator m_TonalEstimator;
     mutable size_t m_step;
     mutable size_t m_block;
     size_t m_stepDelay;
     std::queue<ChromaVector> m_pending;
-	ChromaVector m_vaCurrentVector;
-	TCSGram m_TCSGram;
+    ChromaVector m_vaCurrentVector;
+    TCSGram m_TCSGram;
 	
-private:
-	int m_iSmoothingWidth;  // smoothing window size
-	
+    int m_iSmoothingWidth;  // smoothing window size
     int m_minMIDIPitch;     // chromagram parameters
     int m_maxMIDIPitch;
     float m_tuningFrequency;
-	
+
+    Vamp::RealTime m_origin;
+    bool m_haveOrigin;
 };