changeset 63:a540137d393b refactors_no_float

Fix handling of empty queues -- we should continue processing when a queue is empty only if we've reached end of file on both
author Chris Cannam
date Tue, 18 Nov 2014 10:03:36 +0000
parents faa523be20f9
children da9ead46abe9 a1ff2d45548c 61c7d11ba86d
files src/MatchFeatureFeeder.cpp src/MatchFeatureFeeder.h src/MatchFeeder.cpp src/MatchFeeder.h src/MatchVampPlugin.cpp
diffstat 5 files changed, 72 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/MatchFeatureFeeder.cpp	Fri Nov 14 13:53:58 2014 +0000
+++ b/src/MatchFeatureFeeder.cpp	Tue Nov 18 10:03:36 2014 +0000
@@ -46,6 +46,14 @@
         q2.push(f2);
     }
 
+    while (!q1.empty() && !q2.empty()) {
+        feedBlock();
+    }
+}
+
+void
+MatchFeatureFeeder::finish()
+{
     while (!q1.empty() || !q2.empty()) {
         feedBlock();
     }
--- a/src/MatchFeatureFeeder.h	Fri Nov 14 13:53:58 2014 +0000
+++ b/src/MatchFeatureFeeder.h	Tue Nov 18 10:03:36 2014 +0000
@@ -43,6 +43,11 @@
      */
     void feed(std::vector<double> f1, std::vector<double> f2);
 
+    /**
+     * Indicate that both inputs have come to an end.
+     */
+    void finish();
+    
     Finder *getFinder() { return finder; }
 
 protected:
--- a/src/MatchFeeder.cpp	Fri Nov 14 13:53:58 2014 +0000
+++ b/src/MatchFeeder.cpp	Tue Nov 18 10:03:36 2014 +0000
@@ -53,8 +53,7 @@
 
     prepare(input);
 
-    while (!q1.empty() || !q2.empty()) {
-//        std::cerr << "MatchFeeder::feed: q1 " << q1.size() << " q2 " << q2.size() << std::endl;
+    while (!q1.empty() && !q2.empty()) {
         (void)feedBlock();
     }
 }
@@ -66,6 +65,28 @@
 
     Features all;
 
+    while (!q1.empty() && !q2.empty()) {
+        Features ff = feedBlock();
+        all.f1.insert(all.f1.end(), ff.f1.begin(), ff.f1.end());
+        all.f2.insert(all.f2.end(), ff.f2.begin(), ff.f2.end());
+    }
+
+    return all;
+}
+
+void
+MatchFeeder::finish()
+{
+    while (!q1.empty() || !q2.empty()) {
+        (void)feedBlock();
+    }
+}
+
+MatchFeeder::Features
+MatchFeeder::finishAndGetFeatures()
+{
+    Features all;
+
     while (!q1.empty() || !q2.empty()) {
         Features ff = feedBlock();
         all.f1.insert(all.f1.end(), ff.f1.begin(), ff.f1.end());
@@ -117,9 +138,9 @@
     vector<double> f1, f2;
 
     if (q1.empty()) {
-        feed2();
+        f2 = feed2();
     } else if (q2.empty()) {
-        feed1();
+        f1 = feed1();
     } else if (pm1->m_frameCount < pm1->m_blockSize) {		// fill initial block
 //        std::cerr << "feeding initial block" << std::endl;
         f1 = feed1();
--- a/src/MatchFeeder.h	Fri Nov 14 13:53:58 2014 +0000
+++ b/src/MatchFeeder.h	Tue Nov 18 10:03:36 2014 +0000
@@ -35,6 +35,11 @@
      */
     void feed(const float *const *input);
 
+    /**
+     * Indicate that the input has come to an end.
+     */
+    void finish();
+    
     struct Features {
         std::vector<std::vector<double> > f1;
         std::vector<std::vector<double> > f2;
@@ -47,6 +52,12 @@
      * calculated by the two feeders.
      */
     Features feedAndGetFeatures(const float *const *input);
+
+    /**
+     * Indicate that the input has come to an end, and return any
+     * remaining features.
+     */
+    Features finishAndGetFeatures();
     
     Finder *getFinder() { return finder; }
 
--- a/src/MatchVampPlugin.cpp	Fri Nov 14 13:53:58 2014 +0000
+++ b/src/MatchVampPlugin.cpp	Tue Nov 18 10:03:36 2014 +0000
@@ -505,12 +505,33 @@
 MatchVampPlugin::FeatureSet
 MatchVampPlugin::getRemainingFeatures()
 {
+    FeatureSet returnFeatures;
+    
+    MatchFeeder::Features ff = feeder->finishAndGetFeatures();
+
+    Feature f;
+    f.hasTimestamp = false;
+
+    for (int i = 0; i < (int)ff.f1.size(); ++i) {
+        f.values.clear();
+        for (int j = 0; j < (int)ff.f1[i].size(); ++j) {
+            f.values.push_back(float(ff.f1[i][j]));
+        }
+        returnFeatures[m_aFeaturesOutNo].push_back(f);
+    }
+
+    for (int i = 0; i < (int)ff.f2.size(); ++i) {
+        f.values.clear();
+        for (int j = 0; j < (int)ff.f2[i].size(); ++j) {
+            f.values.push_back(float(ff.f2[i][j]));
+        }
+        returnFeatures[m_bFeaturesOutNo].push_back(f);
+    }
+
     Finder *finder = feeder->getFinder();
     std::vector<int> pathx;
     std::vector<int> pathy;
     int len = finder->retrievePath(m_smooth, pathx, pathy);
-    
-    FeatureSet returnFeatures;
 
     int prevx = 0;
     int prevy = 0;