Revision 8:e9d86e129467 CepstrumPitchTracker.cpp

View differences:

CepstrumPitchTracker.cpp
32 32
using std::string;
33 33
using std::vector;
34 34

  
35
CepstrumPitchTracker::Hypothesis::Hypothesis(Estimate s)
35
CepstrumPitchTracker::Hypothesis::Hypothesis()
36 36
{
37
    m_state = Provisional;
38
    m_pending.push_back(s);
37
    m_state = New;
39 38
    m_age = 0;
40 39
}
41 40

  
......
57 56
    return (m_pending.size() > 2);
58 57
}
59 58

  
59
void
60
CepstrumPitchTracker::Hypothesis::advanceTime()
61
{
62
    ++m_age;
63
}
64

  
60 65
bool
61 66
CepstrumPitchTracker::Hypothesis::test(Estimate s)
62 67
{
63
    if (m_state == Rejected || m_state == Expired) {
64
        return false;
68
    bool accept = false;
69

  
70
    switch (m_state) {
71

  
72
    case New:
73
        m_state = Provisional;
74
        accept = true;
75
        break;
76

  
77
    case Provisional:
78
        if (m_age > 3) {
79
            m_state = Rejected;
80
        } else if (isWithinTolerance(s)) {
81
            accept = true;
82
        }
83
        break;
84
        
85
    case Satisfied:
86
        if (m_age > 3) {
87
            m_state = Expired;
88
        } else if (isWithinTolerance(s)) {
89
            accept = true;
90
        }
91
        break;
92

  
93
    case Rejected:
94
        break;
95

  
96
    case Expired:
97
        break;
65 98
    }
66 99

  
67
    if (++m_age > 3) {
68
        if (m_state == Satisfied) {
69
            m_state = Expired;
70
        } else {
71
            m_state = Rejected;
100
    if (accept) {
101
        m_pending.push_back(s);
102
        m_age = 0;
103
        if (m_state == Provisional && isSatisfied()) {
104
            m_state = Satisfied;
72 105
        }
73
        return false;
74 106
    }
75 107

  
76
    if (isWithinTolerance(s)) {
77
        m_pending.push_back(s);
78
        if (m_state == Provisional) {
79
            if (isSatisfied()) {
80
                m_state == Satisfied;
81
            }
82
        }
83
        m_age = 0;
84
        return true;
85
    }
86
    
87
    return false;
88
}
108
    return accept;
109
}        
89 110

  
90 111
CepstrumPitchTracker::Hypothesis::State
91 112
CepstrumPitchTracker::Hypothesis::getState()
......
116 137
    m_binFrom(0),
117 138
    m_binTo(0),
118 139
    m_bins(0),
119
    m_accepted(0),
120 140
    m_history(0),
121 141
    m_prevpeak(0),
122 142
    m_prevprop(0)
......
434 454
        }
435 455
    }
436 456

  
457
    if (maxbin < 0) return fs;
458

  
459
    double peakfreq = m_inputSampleRate / (maxbin + m_binFrom);
460
    Hypothesis::Estimate e;
461
    e.freq = peakfreq;
462
    e.time = timestamp;
463

  
464
    m_accepted.advanceTime();
465
    for (int i = 0; i < m_possible.size(); ++i) {
466
        m_possible[i].advanceTime();
467
    }
468

  
469
    if (m_accepted.test(e)) {
470
        return fs;
471
    }
472

  
473
    //...
474

  
475
/*
437 476
    bool accepted = false;
438 477

  
439 478
    if (maxbin >= 0) {
......
465 504
            m_prevprop = pp;
466 505
        }
467 506
    }
468
            
507
*/
469 508
//    std::cerr << "peakProportion = " << peakProportion << std::endl;
470 509
//    std::cerr << "peak = " << m_inputSampleRate / (maxbin + m_binFrom) << std::endl;
471 510
//    std::cerr << "bins = " << m_bins << std::endl;

Also available in: Unified diff