Revision 7:32defdb2f9d9 CepstrumPitchTracker.cpp
| CepstrumPitchTracker.cpp | ||
|---|---|---|
| 30 | 30 |
#include <complex> |
| 31 | 31 |
|
| 32 | 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 | 107 |
CepstrumPitchTracker::CepstrumPitchTracker(float inputSampleRate) : |
| 35 | 108 |
Plugin(inputSampleRate), |
| ... | ... | |
| 43 | 116 |
m_binFrom(0), |
| 44 | 117 |
m_binTo(0), |
| 45 | 118 |
m_bins(0), |
| 119 |
m_accepted(0), |
|
| 46 | 120 |
m_history(0), |
| 47 | 121 |
m_prevpeak(0), |
| 48 | 122 |
m_prevprop(0) |
Also available in: Unified diff