changeset 62:7c463642a0a7

Merge
author Chris Cannam
date Wed, 21 Nov 2012 09:33:17 +0000
parents 0a2827a35031 (current diff) c06fe5350b34 (diff)
children 686ef2976366
files
diffstat 4 files changed, 42 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/CepstralPitchTracker.cpp	Fri Nov 16 15:42:21 2012 +0000
+++ b/CepstralPitchTracker.cpp	Wed Nov 21 09:33:17 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	Fri Nov 16 15:42:21 2012 +0000
+++ b/NoteHypothesis.cpp	Wed Nov 21 09:33:17 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));
 }
@@ -80,7 +79,7 @@
     }
     meanConfidence /= m_pending.size();
 
-    int lengthRequired = 10000;
+    int lengthRequired = 100;
     if (meanConfidence > 0.0) {
         lengthRequired = int(2.0 / meanConfidence + 0.5);
     }
@@ -93,6 +92,18 @@
 {
     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
+        if (m_pending.empty()) {
+            m_state = Rejected;
+        }
+        return false;
+    }
+
     switch (m_state) {
 
     case New:
--- a/NoteHypothesis.h	Fri Nov 16 15:42:21 2012 +0000
+++ b/NoteHypothesis.h	Wed Nov 21 09:33:17 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	Fri Nov 16 15:42:21 2012 +0000
+++ b/test/TestNoteHypothesis.cpp	Wed Nov 21 09:33:17 2012 +0000
@@ -53,13 +53,39 @@
 
 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; // 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(noConfidenceIgnore)
+{
+    // But if we're already in process we don't go to rejected state,
+    // we just ignore this hypothesis
     NoteHypothesis h;
     NoteHypothesis::Estimate e;
     BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
     BOOST_CHECK(h.accept(e));
     BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
+    e.confidence = 0;
+    BOOST_CHECK(!h.accept(e));
+    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
 }
 		
 BOOST_AUTO_TEST_CASE(tooSlow)