changeset 58:9f50a5876dd3

Avoid accepting estimates with negligible confidence
author Chris Cannam
date Tue, 20 Nov 2012 21:30:35 +0000
parents 82b3cdf6ca6b
children 82552664d471
files CepstralPitchTracker.cpp NoteHypothesis.cpp NoteHypothesis.h test/TestNoteHypothesis.cpp
diffstat 4 files changed, 26 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/CepstralPitchTracker.cpp	Thu Sep 27 17:22:51 2012 +0100
+++ b/CepstralPitchTracker.cpp	Tue Nov 20 21:30:35 2012 +0000
@@ -333,7 +333,6 @@
     if (nextPeakVal != 0.0) {
         confidence = (maxval - nextPeakVal) * 10.0;
         if (magmean < threshold) confidence = 0.0;
-//        std::cerr << "magmean = " << magmean << ", confidence = " << confidence << std::endl;
     }
 
     delete[] data;
--- a/NoteHypothesis.cpp	Thu Sep 27 17:22:51 2012 +0100
+++ b/NoteHypothesis.cpp	Tue Nov 20 21:30:35 2012 +0000
@@ -64,7 +64,6 @@
 NoteHypothesis::isOutOfDateFor(Estimate s) const
 {
     if (m_pending.empty()) return false;
-
     return ((s.time - m_pending[m_pending.size()-1].time) > 
             RealTime::fromMilliseconds(40));
 }
@@ -93,6 +92,16 @@
 {
     bool accept = false;
 
+    static double negligibleConfidence = 0.0001;
+
+    if (s.confidence < negligibleConfidence) {
+        // avoid piling up a lengthy sequence of estimates that are
+        // all acceptable but are in total not enough to cause us to
+        // be satisfied
+        m_state = Rejected;
+        return false;
+    }
+
     switch (m_state) {
 
     case New:
--- a/NoteHypothesis.h	Thu Sep 27 17:22:51 2012 +0100
+++ b/NoteHypothesis.h	Tue Nov 20 21:30:35 2012 +0000
@@ -68,7 +68,7 @@
     ~NoteHypothesis();
 
     struct Estimate {
-        Estimate() : freq(0), time(), confidence(0) { }
+        Estimate() : freq(0), time(), confidence(1) { }
         Estimate(double _f, Vamp::RealTime _t, double _c) :
             freq(_f), time(_t), confidence(_c) { }
         bool operator==(const Estimate &e) const {
--- a/test/TestNoteHypothesis.cpp	Thu Sep 27 17:22:51 2012 +0100
+++ b/test/TestNoteHypothesis.cpp	Tue Nov 20 21:30:35 2012 +0000
@@ -53,14 +53,26 @@
 
 BOOST_AUTO_TEST_CASE(emptyAccept)
 {
-    // An empty hypothesis should accept any estimate and enter
-    // provisional state
+    // An empty hypothesis should accept any estimate with a
+    // non-negligible confidence, and enter provisional state
     NoteHypothesis h;
-    NoteHypothesis::Estimate e;
+    NoteHypothesis::Estimate e; // default estimate has confidence 1
     BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
     BOOST_CHECK(h.accept(e));
     BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
 }
+
+BOOST_AUTO_TEST_CASE(noConfidence)
+{
+    // A hypothesis should reject any estimate that has a negligible
+    // confidence
+    NoteHypothesis h;
+    NoteHypothesis::Estimate e;
+    e.confidence = 0;
+    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
+    BOOST_CHECK(!h.accept(e));
+    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Rejected);
+}
 		
 BOOST_AUTO_TEST_CASE(tooSlow)
 {