comparison CepstrumPitchTracker.cpp @ 13:9fa97de8692a track

Partial updates to new method (but this doesn't currently build)
author Chris Cannam
date Fri, 29 Jun 2012 10:09:19 +0100
parents cb88b9954eec
children 63dde216ea37
comparison
equal deleted inserted replaced
12:cb88b9954eec 13:9fa97de8692a
30 #include <complex> 30 #include <complex>
31 31
32 using std::string; 32 using std::string;
33 using std::vector; 33 using std::vector;
34 34
35 CepstrumPitchTracker::Hypothesis::Hypothesis(Estimate s) 35 CepstrumPitchTracker::Hypothesis::Hypothesis()
36 { 36 {
37 m_state = Provisional; 37 m_state = New;
38 m_pending.push_back(s);
39 m_age = 0; 38 m_age = 0;
40 } 39 }
41 40
42 bool 41 bool
43 CepstrumPitchTracker::Hypothesis::isWithinTolerance(Estimate s) 42 CepstrumPitchTracker::Hypothesis::isWithinTolerance(Estimate s)
55 CepstrumPitchTracker::Hypothesis::isSatisfied() 54 CepstrumPitchTracker::Hypothesis::isSatisfied()
56 { 55 {
57 return (m_pending.size() > 2); 56 return (m_pending.size() > 2);
58 } 57 }
59 58
59 void
60 CepstrumPitchTracker::Hypothesis::advanceTime()
61 {
62 ++m_age;
63 }
64
60 bool 65 bool
61 CepstrumPitchTracker::Hypothesis::test(Estimate s) 66 CepstrumPitchTracker::Hypothesis::test(Estimate s)
62 { 67 {
63 if (m_state == Rejected || m_state == Expired) { 68 bool accept = false;
64 return false; 69
65 } 70 switch (m_state) {
66 71
67 if (++m_age > 3) { 72 case New:
68 if (m_state == Satisfied) { 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) {
69 m_state = Expired; 87 m_state = Expired;
70 } else { 88 } else if (isWithinTolerance(s)) {
71 m_state = Rejected; 89 accept = true;
72 } 90 }
73 return false; 91 break;
74 } 92
75 93 case Rejected:
76 if (isWithinTolerance(s)) { 94 break;
95
96 case Expired:
97 break;
98 }
99
100 if (accept) {
77 m_pending.push_back(s); 101 m_pending.push_back(s);
78 if (m_state == Provisional) {
79 if (isSatisfied()) {
80 m_state == Satisfied;
81 }
82 }
83 m_age = 0; 102 m_age = 0;
84 return true; 103 if (m_state == Provisional && isSatisfied()) {
85 } 104 m_state = Satisfied;
86 105 }
87 return false; 106 }
88 } 107
108 return accept;
109 }
89 110
90 CepstrumPitchTracker::Hypothesis::State 111 CepstrumPitchTracker::Hypothesis::State
91 CepstrumPitchTracker::Hypothesis::getState() 112 CepstrumPitchTracker::Hypothesis::getState()
92 { 113 {
93 return m_state; 114 return m_state;
114 m_histlen(1), 135 m_histlen(1),
115 m_vflen(3), 136 m_vflen(3),
116 m_binFrom(0), 137 m_binFrom(0),
117 m_binTo(0), 138 m_binTo(0),
118 m_bins(0), 139 m_bins(0),
119 m_accepted(0),
120 m_history(0), 140 m_history(0),
121 m_prevpeak(0), 141 m_prevpeak(0),
122 m_prevprop(0) 142 m_prevprop(0)
123 { 143 {
124 } 144 }
432 maxval = data[i]; 452 maxval = data[i];
433 maxbin = i; 453 maxbin = i;
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 bool accepted = false; 476 bool accepted = false;
438 477
439 if (maxbin >= 0) { 478 if (maxbin >= 0) {
440 double pp = calculatePeakProportion(data, abstot, maxbin); 479 double pp = calculatePeakProportion(data, abstot, maxbin);
441 if (acceptPeak(maxbin, pp)) { 480 if (acceptPeak(maxbin, pp)) {
463 if (accepted) { 502 if (accepted) {
464 m_prevpeak = maxbin; 503 m_prevpeak = maxbin;
465 m_prevprop = pp; 504 m_prevprop = pp;
466 } 505 }
467 } 506 }
468 507 */
469 // std::cerr << "peakProportion = " << peakProportion << std::endl; 508 // std::cerr << "peakProportion = " << peakProportion << std::endl;
470 // std::cerr << "peak = " << m_inputSampleRate / (maxbin + m_binFrom) << std::endl; 509 // std::cerr << "peak = " << m_inputSampleRate / (maxbin + m_binFrom) << std::endl;
471 // std::cerr << "bins = " << m_bins << std::endl; 510 // std::cerr << "bins = " << m_bins << std::endl;
472 511
473 // if (peakProportion >= (0.00006 * m_bins)) { 512 // if (peakProportion >= (0.00006 * m_bins)) {