Revision 62:7c463642a0a7

View differences:

CepstralPitchTracker.cpp
333 333
    if (nextPeakVal != 0.0) {
334 334
        confidence = (maxval - nextPeakVal) * 10.0;
335 335
        if (magmean < threshold) confidence = 0.0;
336
//        std::cerr << "magmean = " << magmean << ", confidence = " << confidence << std::endl;
337 336
    }
338 337

  
339 338
    delete[] data;
NoteHypothesis.cpp
64 64
NoteHypothesis::isOutOfDateFor(Estimate s) const
65 65
{
66 66
    if (m_pending.empty()) return false;
67

  
68 67
    return ((s.time - m_pending[m_pending.size()-1].time) > 
69 68
            RealTime::fromMilliseconds(40));
70 69
}
......
80 79
    }
81 80
    meanConfidence /= m_pending.size();
82 81

  
83
    int lengthRequired = 10000;
82
    int lengthRequired = 100;
84 83
    if (meanConfidence > 0.0) {
85 84
        lengthRequired = int(2.0 / meanConfidence + 0.5);
86 85
    }
......
93 92
{
94 93
    bool accept = false;
95 94

  
95
    static double negligibleConfidence = 0.0001;
96

  
97
    if (s.confidence < negligibleConfidence) {
98
        // avoid piling up a lengthy sequence of estimates that are
99
        // all acceptable but are in total not enough to cause us to
100
        // be satisfied
101
        if (m_pending.empty()) {
102
            m_state = Rejected;
103
        }
104
        return false;
105
    }
106

  
96 107
    switch (m_state) {
97 108

  
98 109
    case New:
NoteHypothesis.h
68 68
    ~NoteHypothesis();
69 69

  
70 70
    struct Estimate {
71
        Estimate() : freq(0), time(), confidence(0) { }
71
        Estimate() : freq(0), time(), confidence(1) { }
72 72
        Estimate(double _f, Vamp::RealTime _t, double _c) :
73 73
            freq(_f), time(_t), confidence(_c) { }
74 74
        bool operator==(const Estimate &e) const {
test/TestNoteHypothesis.cpp
53 53

  
54 54
BOOST_AUTO_TEST_CASE(emptyAccept)
55 55
{
56
    // An empty hypothesis should accept any estimate and enter
57
    // provisional state
56
    // An empty hypothesis should accept any estimate with a
57
    // non-negligible confidence, and enter provisional state
58
    NoteHypothesis h;
59
    NoteHypothesis::Estimate e; // default estimate has confidence 1
60
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
61
    BOOST_CHECK(h.accept(e));
62
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
63
}
64

  
65
BOOST_AUTO_TEST_CASE(noConfidence)
66
{
67
    // A hypothesis should reject any estimate that has a negligible
68
    // confidence
69
    NoteHypothesis h;
70
    NoteHypothesis::Estimate e;
71
    e.confidence = 0;
72
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
73
    BOOST_CHECK(!h.accept(e));
74
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Rejected);
75
}
76

  
77
BOOST_AUTO_TEST_CASE(noConfidenceIgnore)
78
{
79
    // But if we're already in process we don't go to rejected state,
80
    // we just ignore this hypothesis
58 81
    NoteHypothesis h;
59 82
    NoteHypothesis::Estimate e;
60 83
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::New);
61 84
    BOOST_CHECK(h.accept(e));
62 85
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
86
    e.confidence = 0;
87
    BOOST_CHECK(!h.accept(e));
88
    BOOST_CHECK_EQUAL(h.getState(), NoteHypothesis::Provisional);
63 89
}
64 90
		
65 91
BOOST_AUTO_TEST_CASE(tooSlow)

Also available in: Unified diff