diff MatchVampPlugin.cpp @ 10:6ea008aa8817

Fixes to problems reported by plugin tester
author Chris Cannam
date Wed, 06 Aug 2014 12:38:00 +0100
parents 80fae79c9472
children a82276091bbd
line wrap: on
line diff
--- a/MatchVampPlugin.cpp	Tue Aug 05 11:06:04 2014 +0100
+++ b/MatchVampPlugin.cpp	Wed Aug 06 12:38:00 2014 +0100
@@ -40,6 +40,11 @@
 bool
 MatchVampPlugin::m_serialisingMutexInitialised = false;
 
+// We want to ensure our freq map / crossover bin in Matcher.cpp are
+// always valid with a fixed FFT length in seconds, so must reject low
+// sample rates
+static float sampleRateMin = 5000.f;
+
 MatchVampPlugin::MatchVampPlugin(float inputSampleRate) :
     Plugin(inputSampleRate),
     m_stepSize(0),
@@ -47,6 +52,13 @@
     m_begin(true),
     m_locked(false)
 {
+    if (inputSampleRate < sampleRateMin) {
+        std::cerr << "MatchVampPlugin::MatchVampPlugin: input sample rate "
+                  << inputSampleRate << " < min supported rate "
+                  << sampleRateMin << ", plugin will refuse to initialise"
+                  << std::endl;
+    }
+
     if (!m_serialisingMutexInitialised) {
         m_serialisingMutexInitialised = true;
 #ifdef _WIN32
@@ -149,7 +161,7 @@
 {
     if (name == "serialise") {
         m_serialise = (value > 0.5);
-        std::cerr << "MatchVampPlugin::setParameter: set serialise to " << m_serialise << std::endl;
+//        std::cerr << "MatchVampPlugin::setParameter: set serialise to " << m_serialise << std::endl;
     }
 }
 
@@ -179,6 +191,12 @@
 bool
 MatchVampPlugin::initialise(size_t channels, size_t stepSize, size_t blockSize)
 {
+    if (m_inputSampleRate < sampleRateMin) {
+        std::cerr << "MatchVampPlugin::MatchVampPlugin: input sample rate "
+                  << m_inputSampleRate << " < min supported rate "
+                  << sampleRateMin << std::endl;
+        return false;
+    }
     if (!pm1) createMatchers();
     if (channels < getMinChannelCount() ||
 	channels > getMaxChannelCount()) return false;
@@ -294,6 +312,7 @@
             pthread_mutex_lock(&m_serialisingMutex);
 #endif
         }
+        m_startTime = timestamp;
         m_begin = false;
     }
     
@@ -359,7 +378,7 @@
 
         Feature feature;
         feature.hasTimestamp = true;
-        feature.timestamp = xt;
+        feature.timestamp = m_startTime + xt;
         feature.values.clear();
         feature.values.push_back(yt.sec + double(yt.nsec)/1.0e9);
         returnFeatures[0].push_back(feature);
@@ -367,7 +386,7 @@
         if (x != prevx) {
 
             feature.hasTimestamp = true;
-            feature.timestamp = xt;
+            feature.timestamp = m_startTime + xt;
             feature.values.clear();
             feature.values.push_back(yt.sec + yt.msec()/1000.0);
             returnFeatures[1].push_back(feature);
@@ -395,7 +414,7 @@
 
         if (y != prevy) {
             feature.hasTimestamp = true;
-            feature.timestamp = yt;
+            feature.timestamp = m_startTime + yt;
             feature.values.clear();
             feature.values.push_back(xt.sec + xt.msec()/1000.0);
             returnFeatures[2].push_back(feature);