| 38 |
38 |
CepstrumPitchTracker::Hypothesis::Hypothesis()
|
| 39 |
39 |
{
|
| 40 |
40 |
m_state = New;
|
| 41 |
|
m_age = 0;
|
| 42 |
41 |
}
|
| 43 |
42 |
|
| 44 |
43 |
CepstrumPitchTracker::Hypothesis::~Hypothesis()
|
| ... | ... | |
| 68 |
67 |
return true;
|
| 69 |
68 |
}
|
| 70 |
69 |
|
|
70 |
bool
|
|
71 |
CepstrumPitchTracker::Hypothesis::isOutOfDateFor(Estimate s)
|
|
72 |
{
|
|
73 |
if (m_pending.empty()) return false;
|
|
74 |
|
|
75 |
return ((s.time - m_pending[m_pending.size()-1].time) >
|
|
76 |
RealTime::fromMilliseconds(40));
|
|
77 |
}
|
|
78 |
|
| 71 |
79 |
bool
|
| 72 |
80 |
CepstrumPitchTracker::Hypothesis::isSatisfied()
|
| 73 |
81 |
{
|
| ... | ... | |
| 88 |
96 |
return (m_pending.size() > lengthRequired);
|
| 89 |
97 |
}
|
| 90 |
98 |
|
| 91 |
|
void
|
| 92 |
|
CepstrumPitchTracker::Hypothesis::advanceTime()
|
| 93 |
|
{
|
| 94 |
|
++m_age;
|
| 95 |
|
}
|
| 96 |
|
|
| 97 |
99 |
bool
|
| 98 |
|
CepstrumPitchTracker::Hypothesis::test(Estimate s)
|
|
100 |
CepstrumPitchTracker::Hypothesis::accept(Estimate s)
|
| 99 |
101 |
{
|
| 100 |
102 |
bool accept = false;
|
| 101 |
103 |
|
| ... | ... | |
| 107 |
109 |
break;
|
| 108 |
110 |
|
| 109 |
111 |
case Provisional:
|
| 110 |
|
if (m_age > 3) {
|
|
112 |
if (isOutOfDateFor(s)) {
|
| 111 |
113 |
m_state = Rejected;
|
| 112 |
114 |
} else if (isWithinTolerance(s)) {
|
| 113 |
115 |
accept = true;
|
| ... | ... | |
| 115 |
117 |
break;
|
| 116 |
118 |
|
| 117 |
119 |
case Satisfied:
|
| 118 |
|
if (m_age > 3) {
|
|
120 |
if (isOutOfDateFor(s)) {
|
| 119 |
121 |
m_state = Expired;
|
| 120 |
122 |
} else if (isWithinTolerance(s)) {
|
| 121 |
123 |
accept = true;
|
| ... | ... | |
| 131 |
133 |
|
| 132 |
134 |
if (accept) {
|
| 133 |
135 |
m_pending.push_back(s);
|
| 134 |
|
m_age = 0;
|
| 135 |
136 |
if (m_state == Provisional && isSatisfied()) {
|
| 136 |
137 |
m_state = Satisfied;
|
| 137 |
138 |
}
|
| 138 |
139 |
}
|
| 139 |
140 |
|
| 140 |
|
return accept && (m_state == Satisfied);
|
|
141 |
return accept;
|
| 141 |
142 |
}
|
| 142 |
143 |
|
| 143 |
144 |
CepstrumPitchTracker::Hypothesis::State
|
| ... | ... | |
| 582 |
583 |
e.time = timestamp;
|
| 583 |
584 |
e.confidence = confidence;
|
| 584 |
585 |
|
| 585 |
|
m_accepted.advanceTime();
|
| 586 |
|
|
|
586 |
// m_good.advanceTime();
|
| 587 |
587 |
for (int i = 0; i < m_possible.size(); ++i) {
|
| 588 |
|
m_possible[i].advanceTime();
|
|
588 |
// m_possible[i].advanceTime();
|
| 589 |
589 |
}
|
| 590 |
590 |
|
| 591 |
|
if (!m_accepted.test(e)) {
|
|
591 |
if (!m_good.accept(e)) {
|
| 592 |
592 |
|
| 593 |
593 |
int candidate = -1;
|
| 594 |
594 |
bool accepted = false;
|
| 595 |
595 |
|
| 596 |
596 |
for (int i = 0; i < m_possible.size(); ++i) {
|
| 597 |
|
if (m_possible[i].test(e)) {
|
| 598 |
|
accepted = true;
|
|
597 |
if (m_possible[i].accept(e)) {
|
| 599 |
598 |
if (m_possible[i].getState() == Hypothesis::Satisfied) {
|
|
599 |
accepted = true;
|
| 600 |
600 |
candidate = i;
|
| 601 |
601 |
}
|
| 602 |
602 |
break;
|
| ... | ... | |
| 605 |
605 |
|
| 606 |
606 |
if (!accepted) {
|
| 607 |
607 |
Hypothesis h;
|
| 608 |
|
h.test(e); //!!! must succeed as h is new, so perhaps there should be a ctor for this
|
|
608 |
h.accept(e); //!!! must succeed as h is new, so perhaps there should be a ctor for this
|
| 609 |
609 |
m_possible.push_back(h);
|
| 610 |
610 |
}
|
| 611 |
611 |
|
| 612 |
|
if (m_accepted.getState() == Hypothesis::Expired) {
|
| 613 |
|
m_accepted.addFeatures(fs);
|
|
612 |
if (m_good.getState() == Hypothesis::Expired) {
|
|
613 |
m_good.addFeatures(fs);
|
| 614 |
614 |
}
|
| 615 |
615 |
|
| 616 |
|
if (m_accepted.getState() == Hypothesis::Expired ||
|
| 617 |
|
m_accepted.getState() == Hypothesis::Rejected) {
|
|
616 |
if (m_good.getState() == Hypothesis::Expired ||
|
|
617 |
m_good.getState() == Hypothesis::Rejected) {
|
| 618 |
618 |
if (candidate >= 0) {
|
| 619 |
|
m_accepted = m_possible[candidate];
|
|
619 |
m_good = m_possible[candidate];
|
| 620 |
620 |
} else {
|
| 621 |
|
m_accepted = Hypothesis();
|
|
621 |
m_good = Hypothesis();
|
| 622 |
622 |
}
|
| 623 |
623 |
}
|
| 624 |
624 |
|
| ... | ... | |
| 634 |
634 |
}
|
| 635 |
635 |
}
|
| 636 |
636 |
|
| 637 |
|
std::cerr << "accepted length = " << m_accepted.getPendingLength()
|
| 638 |
|
<< ", state = " << m_accepted.getState()
|
|
637 |
std::cerr << "accepted length = " << m_good.getPendingLength()
|
|
638 |
<< ", state = " << m_good.getState()
|
| 639 |
639 |
<< ", hypothesis count = " << m_possible.size() << std::endl;
|
| 640 |
640 |
|
| 641 |
641 |
delete[] data;
|
| ... | ... | |
| 646 |
646 |
CepstrumPitchTracker::getRemainingFeatures()
|
| 647 |
647 |
{
|
| 648 |
648 |
FeatureSet fs;
|
| 649 |
|
if (m_accepted.getState() == Hypothesis::Satisfied) {
|
| 650 |
|
m_accepted.addFeatures(fs);
|
|
649 |
if (m_good.getState() == Hypothesis::Satisfied) {
|
|
650 |
m_good.addFeatures(fs);
|
| 651 |
651 |
}
|
| 652 |
652 |
return fs;
|
| 653 |
653 |
}
|