changeset 31:b9c2f444cdaa

Fix incorrect return timestamps when run with non-zero origin time
author Chris Cannam
date Fri, 06 Dec 2013 14:38:17 +0000
parents eeafdd147988
children 36638ec0b379
files BeatRootProcessor.h BeatRootVampPlugin.cpp BeatRootVampPlugin.h
diffstat 3 files changed, 14 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/BeatRootProcessor.h	Fri Dec 06 14:31:09 2013 +0000
+++ b/BeatRootProcessor.h	Fri Dec 06 14:38:17 2013 +0000
@@ -94,10 +94,10 @@
      *  file is set (see <code>setInputFile()</code>). */
     BeatRootProcessor(float sr, AgentParameters parameters) :
         sampleRate(sr),
+        hopTime(0.010),
+        fftTime(0.04644),
         hopSize(0),
         fftSize(0),
-        hopTime(0.010),
-        fftTime(0.04644),
         agentParameters(parameters)
     {
         hopSize = lrint(sampleRate * hopTime);
--- a/BeatRootVampPlugin.cpp	Fri Dec 06 14:31:09 2013 +0000
+++ b/BeatRootVampPlugin.cpp	Fri Dec 06 14:38:17 2013 +0000
@@ -22,7 +22,8 @@
 #include <vamp-sdk/PluginAdapter.h>
 
 BeatRootVampPlugin::BeatRootVampPlugin(float inputSampleRate) :
-    Plugin(inputSampleRate)
+    Plugin(inputSampleRate),
+    m_firstFrame(true)
 {
     m_processor = new BeatRootProcessor(inputSampleRate, AgentParameters());
 }
@@ -107,21 +108,6 @@
 
     ParameterDescriptor desc;
 
-    double postMarginFactor;
-
-    /** The maximum amount by which a beat can be earlier than the
-     *  predicted beat time, expressed as a fraction of the beat
-     *  period. */
-    double preMarginFactor;
-
-    /** The maximum allowed deviation from the initial tempo,
-     * expressed as a fraction of the initial beat period. */
-    double maxChange;
-
-    /** The default value of expiryTime, which is the time (in
-     *  seconds) after which an Agent that has no Event matching its
-     *  beat predictions will be destroyed. */
-    
     desc.identifier = "preMarginFactor";
     desc.name = "Pre-Margin Factor";
     desc.description = "The maximum amount by which a beat can be earlier than the predicted beat time, expressed as a fraction of the beat period.";
@@ -295,11 +281,18 @@
 BeatRootVampPlugin::reset()
 {
     m_processor->reset();
+    m_firstFrame = true;
+    m_origin = Vamp::RealTime::zeroTime;
 }
 
 BeatRootVampPlugin::FeatureSet
 BeatRootVampPlugin::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
 {
+    if (m_firstFrame) {
+        m_origin = timestamp;
+        m_firstFrame = false;
+    }
+
     m_processor->processFrame(inputBuffers);
     return FeatureSet();
 }
@@ -318,7 +311,7 @@
     FeatureSet fs;
 
     for (EventList::const_iterator i = el.begin(); i != el.end(); ++i) {
-        f.timestamp = Vamp::RealTime::fromSeconds(i->time);
+        f.timestamp = m_origin + Vamp::RealTime::fromSeconds(i->time);
         fs[0].push_back(f);
     }
 
--- a/BeatRootVampPlugin.h	Fri Dec 06 14:31:09 2013 +0000
+++ b/BeatRootVampPlugin.h	Fri Dec 06 14:38:17 2013 +0000
@@ -64,6 +64,8 @@
 protected:
     BeatRootProcessor *m_processor;
     AgentParameters m_parameters;
+    Vamp::RealTime m_origin;
+    bool m_firstFrame;
 };