changeset 119:96c2191a85cc adaptive_diagonals

Confidence inflection points
author Chris Cannam
date Fri, 05 Dec 2014 14:49:57 +0000
parents 69b16c0bc903
children c7aa54343131
files Makefile.linux src/FeatureConditioner.h src/Finder.cpp src/MatchVampPlugin.cpp
diffstat 4 files changed, 59 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.linux	Fri Dec 05 13:40:23 2014 +0000
+++ b/Makefile.linux	Fri Dec 05 14:49:57 2014 +0000
@@ -1,6 +1,6 @@
 
-CXXFLAGS	+= -fPIC -ffast-math -O3 -Wall -Werror
-#CXXFLAGS	+= -fPIC -g -Wall -Werror -Wfloat-conversion -DPERFORM_ERROR_CHECKS=1
+#CXXFLAGS	+= -fPIC -ffast-math -O3 -Wall -Werror
+CXXFLAGS	+= -fPIC -g -Wall -Werror -Wfloat-conversion -DPERFORM_ERROR_CHECKS=1
 
 LDFLAGS		+= -shared -Wl,-Bstatic -lvamp-sdk -Wl,-Bdynamic -Wl,-Bsymbolic -Wl,-z,defs -lpthread -Wl,--version-script=vamp-plugin.map
 
--- a/src/FeatureConditioner.h	Fri Dec 05 13:40:23 2014 +0000
+++ b/src/FeatureConditioner.h	Fri Dec 05 14:49:57 2014 +0000
@@ -88,7 +88,10 @@
      * state: use one FeatureConditioner per audio source, and construct
      * a new one for each new source.
      */
-    FeatureConditioner(Parameters parameters) : m_params(parameters) { }
+    FeatureConditioner(Parameters parameters) :
+        m_params(parameters),
+        m_ltAverage(0.0)
+    { }
 
     /**
      * Process the given feature and return the conditioned feature.
--- a/src/Finder.cpp	Fri Dec 05 13:40:23 2014 +0000
+++ b/src/Finder.cpp	Fri Dec 05 14:49:57 2014 +0000
@@ -342,7 +342,7 @@
     distances.clear();
 
 #ifdef PERFORM_ERROR_CHECKS
-    checkAndReport();
+//    checkAndReport();
 #endif
 
     int ex = m_m->getOtherFrameCount() - 1;
--- a/src/MatchVampPlugin.cpp	Fri Dec 05 13:40:23 2014 +0000
+++ b/src/MatchVampPlugin.cpp	Fri Dec 05 14:49:57 2014 +0000
@@ -20,6 +20,7 @@
 #include "MatchFeatureFeeder.h"
 #include "FeatureExtractor.h"
 #include "Path.h"
+#include "MedianFilter.h"
 
 #include <vamp/vamp.h>
 #include <vamp-sdk/PluginAdapter.h>
@@ -547,7 +548,7 @@
     return list;
 }
 
-static double
+static float
 magOf(const vector<double> &f)
 {
     double mag = 0.0;
@@ -555,7 +556,7 @@
         mag += f[j] * f[j];
     }
     mag = sqrt(mag);
-    return mag;
+    return float(mag);
 }
 
 MatchVampPlugin::FeatureSet
@@ -654,17 +655,13 @@
             int x = pathx[i];
             int y = pathy[i];
 
-            double magSum = m_mag1[x] + m_mag2[y];
-            double distance = distances[i];
+            float magSum = m_mag1[x] + m_mag2[y];
+            float distance = distances[i];
             float c = magSum - distance * magSum;
             confidence.push_back(c);
 
             if (x != prevx) {
                 Feature f;
-                f.values.push_back(c);
-                returnFeatures[m_confidenceOutNo].push_back(f);
-
-                f.values.clear();
                 f.values.push_back(magSum);
                 returnFeatures[m_magOutNo].push_back(f);
 
@@ -676,31 +673,60 @@
             prevx = x;
             prevy = y;
         }
+
+        confidence = MedianFilter<float>::filter(3, confidence);
+        vector<float> filtered = MedianFilter<float>::filter(50, confidence);
+        for (int i = 0; i < len; ++i) {
+            confidence[i] -= filtered[i];
+            if (confidence[i] < 0.f) {
+                confidence[i] = 0.f;
+            }
+        }
+        vector<float> deriv;
+        deriv.resize(len, 0.f);
+        for (int i = 1; i < len; ++i) {
+            deriv[i] = confidence[i] - confidence[i-1];
+        }
+        vector<int> inflections;
+        for (int i = 1; i < len; ++i) {
+            if (deriv[i-1] > 0 && deriv[i] < 0) {
+                inflections.push_back(i);
+            }
+        }
         
-        map<int, int> pinpoints;
-            
-        vector<float> csorted = confidence;
-        sort(csorted.begin(), csorted.end());
-        float thresh = csorted[int(csorted.size() * 0.7)]; // 70th percentile
-
-        for (int i = 1; i + 1 < len; ++i) {
+        for (int i = 0; i < len; ++i) {
 
             int x = pathx[i];
             int y = pathy[i];
 
-            if (confidence[i] > thresh &&
-                confidence[i] > confidence[i-1] &&
-                confidence[i] >= confidence[i+1]) {
+            if (x != prevx) {
+                Feature f;
+                float c = confidence[i];
+                f.values.push_back(c);
+                returnFeatures[m_confidenceOutNo].push_back(f);
+            }
 
-                pinpoints[x] = y;
+            prevx = x;
+            prevy = y;
+        }
+
+        map<int, int> pinpoints;
+            
+        for (int ii = 0; ii < int(inflections.size()); ++ii) {
+
+            int i = inflections[ii];
+            
+            int x = pathx[i];
+            int y = pathy[i];
+
+            pinpoints[x] = y;
                 
-                Vamp::RealTime xt = Vamp::RealTime::frame2RealTime
-                    (x * m_stepSize, lrintf(m_inputSampleRate));
-                Feature feature;
-                feature.hasTimestamp = true;
-                feature.timestamp = m_startTime + xt;
-                returnFeatures[m_confPeakOutNo].push_back(feature);
-            }
+            Vamp::RealTime xt = Vamp::RealTime::frame2RealTime
+                (x * m_stepSize, lrintf(m_inputSampleRate));
+            Feature feature;
+            feature.hasTimestamp = true;
+            feature.timestamp = m_startTime + xt;
+            returnFeatures[m_confPeakOutNo].push_back(feature);
         }
 
         finder->smoothWithPinPoints(pinpoints);