# HG changeset patch # User Chris Cannam # Date 1353490397 0 # Node ID 7c463642a0a7e8cd4b2299e5da0bc36e2056d645 # Parent 0a2827a350312c536ccedaa892ea854df5c6d2cc# Parent c06fe5350b3452ac9e6bc80d8126cbbff247bf72 Merge diff -r 0a2827a35031 -r 7c463642a0a7 CepstralPitchTracker.cpp --- 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; diff -r 0a2827a35031 -r 7c463642a0a7 NoteHypothesis.cpp --- 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: diff -r 0a2827a35031 -r 7c463642a0a7 NoteHypothesis.h --- 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 { diff -r 0a2827a35031 -r 7c463642a0a7 test/TestNoteHypothesis.cpp --- 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)