Mercurial > hg > vamp-simple-cepstrum
comparison CepstrumPitchTracker.cpp @ 12:cb88b9954eec track
Start an alternative idea
author | Chris Cannam |
---|---|
date | Thu, 28 Jun 2012 12:17:18 +0100 |
parents | 0c95dc49163a |
children | 9fa97de8692a 213d80320d4b |
comparison
equal
deleted
inserted
replaced
11:0c95dc49163a | 12:cb88b9954eec |
---|---|
28 #include <cstdio> | 28 #include <cstdio> |
29 #include <cmath> | 29 #include <cmath> |
30 #include <complex> | 30 #include <complex> |
31 | 31 |
32 using std::string; | 32 using std::string; |
33 using std::vector; | |
34 | |
35 CepstrumPitchTracker::Hypothesis::Hypothesis(Estimate s) | |
36 { | |
37 m_state = Provisional; | |
38 m_pending.push_back(s); | |
39 m_age = 0; | |
40 } | |
41 | |
42 bool | |
43 CepstrumPitchTracker::Hypothesis::isWithinTolerance(Estimate s) | |
44 { | |
45 if (m_pending.empty()) { | |
46 return true; | |
47 } | |
48 Estimate last = m_pending[m_pending.size()-1]; | |
49 double r = s.freq / last.freq; | |
50 int cents = lrint(1200.0 * (log(r) / log(2.0))); | |
51 return (cents > -200 && cents < 200); | |
52 } | |
53 | |
54 bool | |
55 CepstrumPitchTracker::Hypothesis::isSatisfied() | |
56 { | |
57 return (m_pending.size() > 2); | |
58 } | |
59 | |
60 bool | |
61 CepstrumPitchTracker::Hypothesis::test(Estimate s) | |
62 { | |
63 if (m_state == Rejected || m_state == Expired) { | |
64 return false; | |
65 } | |
66 | |
67 if (++m_age > 3) { | |
68 if (m_state == Satisfied) { | |
69 m_state = Expired; | |
70 } else { | |
71 m_state = Rejected; | |
72 } | |
73 return false; | |
74 } | |
75 | |
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 } | |
89 | |
90 CepstrumPitchTracker::Hypothesis::State | |
91 CepstrumPitchTracker::Hypothesis::getState() | |
92 { | |
93 return m_state; | |
94 } | |
95 | |
96 CepstrumPitchTracker::Hypothesis::Estimates | |
97 CepstrumPitchTracker::Hypothesis::getAcceptedEstimates() | |
98 { | |
99 if (m_state == Satisfied || m_state == Expired) { | |
100 return m_pending; | |
101 } else { | |
102 return Estimates(); | |
103 } | |
104 } | |
105 | |
33 | 106 |
34 CepstrumPitchTracker::CepstrumPitchTracker(float inputSampleRate) : | 107 CepstrumPitchTracker::CepstrumPitchTracker(float inputSampleRate) : |
35 Plugin(inputSampleRate), | 108 Plugin(inputSampleRate), |
36 m_channels(0), | 109 m_channels(0), |
37 m_stepSize(256), | 110 m_stepSize(256), |
41 m_histlen(1), | 114 m_histlen(1), |
42 m_vflen(3), | 115 m_vflen(3), |
43 m_binFrom(0), | 116 m_binFrom(0), |
44 m_binTo(0), | 117 m_binTo(0), |
45 m_bins(0), | 118 m_bins(0), |
119 m_accepted(0), | |
46 m_history(0), | 120 m_history(0), |
47 m_prevpeak(0), | 121 m_prevpeak(0), |
48 m_prevprop(0) | 122 m_prevprop(0) |
49 { | 123 { |
50 } | 124 } |