Mercurial > hg > cepstral-pitchtracker
comparison AgentFeeder.cpp @ 54:751b43d119cf
Fix feeder (and its tests!) so they now pass
author | Chris Cannam |
---|---|
date | Thu, 27 Sep 2012 15:20:47 +0100 |
parents | 19c8c6ca4406 |
children | 7ad142c710c6 |
comparison
equal
deleted
inserted
replaced
53:19c8c6ca4406 | 54:751b43d119cf |
---|---|
24 | 24 |
25 #include "AgentFeeder.h" | 25 #include "AgentFeeder.h" |
26 | 26 |
27 void AgentFeeder::feed(NoteHypothesis::Estimate e) | 27 void AgentFeeder::feed(NoteHypothesis::Estimate e) |
28 { | 28 { |
29 if (!m_current.accept(e)) { | 29 if (m_haveCurrent) { |
30 if (m_current.accept(e)) { | |
31 return; | |
32 } | |
33 if (m_current.getState() == NoteHypothesis::Expired) { | |
34 m_accepted.push_back(m_current); | |
35 m_haveCurrent = false; | |
36 } | |
37 } | |
30 | 38 |
31 if (m_current.getState() == NoteHypothesis::Expired) { | 39 bool swallowed = false; |
32 m_accepted.push_back(m_current); | |
33 } | |
34 | 40 |
35 bool swallowed = false; | 41 Hypotheses newCandidates; |
36 | 42 |
37 Hypotheses newCandidates; | 43 for (Hypotheses::iterator i = m_candidates.begin(); |
38 | 44 i != m_candidates.end(); ++i) { |
39 for (typename Hypotheses::iterator i = m_candidates.begin(); | 45 |
40 i != m_candidates.end(); ++i) { | 46 NoteHypothesis h = *i; |
41 | 47 |
42 NoteHypothesis h = *i; | 48 if (swallowed) { |
49 | |
50 // don't offer: each observation can only belong to one | |
51 // satisfied hypothesis | |
52 newCandidates.push_back(h); | |
53 | |
54 } else { | |
55 | |
56 if (h.accept(e)) { | |
43 | 57 |
44 if (swallowed) { | 58 if (h.getState() == NoteHypothesis::Satisfied) { |
45 | 59 |
46 // don't offer: each observation can only belong to one | 60 swallowed = true; |
47 // satisfied hypothesis | 61 |
48 newCandidates.push_back(h); | 62 if (!m_haveCurrent || |
49 | 63 m_current.getState() == NoteHypothesis::Expired || |
50 } else { | 64 m_current.getState() == NoteHypothesis::Rejected) { |
51 | 65 m_current = h; |
52 if (h.accept(e)) { | 66 m_haveCurrent = true; |
53 | 67 } else { |
54 if (h.getState() == NoteHypothesis::Satisfied) { | 68 newCandidates.push_back(h); |
55 | 69 } |
56 swallowed = true; | 70 |
57 | 71 } else { |
58 if (m_current.getState() == NoteHypothesis::Expired || | 72 newCandidates.push_back(h); |
59 m_current.getState() == NoteHypothesis::Rejected) { | 73 } |
60 m_current = h; | 74 } |
61 } else { | 75 } |
62 newCandidates.push_back(h); | 76 } |
63 } | 77 |
64 | 78 if (!swallowed) { |
65 } else { | 79 NoteHypothesis h; |
66 newCandidates.push_back(h); | 80 if (h.accept(e)) { |
67 } | 81 newCandidates.push_back(h); |
68 } | 82 } |
69 } | 83 } |
70 } | 84 |
71 | 85 m_candidates = reap(newCandidates); |
72 if (!swallowed) { | |
73 NoteHypothesis h; | |
74 h.accept(e); // must succeed, as h is new | |
75 newCandidates.push_back(h); | |
76 } | |
77 | |
78 // reap rejected/expired hypotheses from candidates list, | |
79 // and assign back to m_candidates | |
80 | |
81 m_candidates.clear(); | |
82 | |
83 for (typename Hypotheses::const_iterator i = newCandidates.begin(); | |
84 i != newCandidates.end(); ++i) { | |
85 NoteHypothesis h = *i; | |
86 if (h.getState() != NoteHypothesis::Rejected && | |
87 h.getState() != NoteHypothesis::Expired) { | |
88 m_candidates.push_back(h); | |
89 } | |
90 } | |
91 } | |
92 } | 86 } |
93 | 87 |
88 AgentFeeder::Hypotheses | |
89 AgentFeeder::reap(Hypotheses candidates) | |
90 { | |
91 // reap rejected/expired hypotheses from list of candidates | |
92 | |
93 Hypotheses survived; | |
94 for (Hypotheses::const_iterator i = candidates.begin(); | |
95 i != candidates.end(); ++i) { | |
96 NoteHypothesis h = *i; | |
97 if (h.getState() != NoteHypothesis::Rejected && | |
98 h.getState() != NoteHypothesis::Expired) { | |
99 survived.push_back(h); | |
100 } | |
101 } | |
102 | |
103 return survived; | |
104 } | |
105 | |
94 void | 106 void |
95 AgentFeeder::finish() | 107 AgentFeeder::finish() |
96 { | 108 { |
97 if (m_current.getState() == NoteHypothesis::Satisfied) { | 109 if (m_current.getState() == NoteHypothesis::Satisfied) { |
98 m_accepted.push_back(m_current); | 110 m_accepted.push_back(m_current); |