Revision 54:751b43d119cf
| AgentFeeder.cpp | ||
|---|---|---|
| 26 | 26 |
|
| 27 | 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) {
|
|
| 32 |
m_accepted.push_back(m_current); |
|
| 33 |
} |
|
| 39 |
bool swallowed = false; |
|
| 34 | 40 |
|
| 35 |
bool swallowed = false;
|
|
| 41 |
Hypotheses newCandidates;
|
|
| 36 | 42 |
|
| 37 |
Hypotheses newCandidates; |
|
| 38 |
|
|
| 39 |
for (typename Hypotheses::iterator i = m_candidates.begin(); |
|
| 40 |
i != m_candidates.end(); ++i) {
|
|
| 41 |
|
|
| 42 |
NoteHypothesis h = *i; |
|
| 43 |
for (Hypotheses::iterator i = m_candidates.begin(); |
|
| 44 |
i != m_candidates.end(); ++i) {
|
|
| 45 |
|
|
| 46 |
NoteHypothesis h = *i; |
|
| 47 |
|
|
| 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) {
|
|
| 45 |
|
|
| 46 |
// don't offer: each observation can only belong to one |
|
| 47 |
// satisfied hypothesis |
|
| 48 |
newCandidates.push_back(h); |
|
| 49 |
|
|
| 50 |
} else {
|
|
| 51 |
|
|
| 52 |
if (h.accept(e)) {
|
|
| 53 |
|
|
| 54 |
if (h.getState() == NoteHypothesis::Satisfied) {
|
|
| 55 |
|
|
| 56 |
swallowed = true; |
|
| 57 |
|
|
| 58 |
if (m_current.getState() == NoteHypothesis::Expired || |
|
| 59 |
m_current.getState() == NoteHypothesis::Rejected) {
|
|
| 60 |
m_current = h; |
|
| 61 |
} else {
|
|
| 62 |
newCandidates.push_back(h); |
|
| 63 |
} |
|
| 64 |
|
|
| 65 |
} else {
|
|
| 66 |
newCandidates.push_back(h); |
|
| 67 |
} |
|
| 68 |
} |
|
| 69 |
} |
|
| 70 |
} |
|
| 71 |
|
|
| 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 |
} |
|
| 58 |
if (h.getState() == NoteHypothesis::Satisfied) {
|
|
| 59 |
|
|
| 60 |
swallowed = true; |
|
| 61 |
|
|
| 62 |
if (!m_haveCurrent || |
|
| 63 |
m_current.getState() == NoteHypothesis::Expired || |
|
| 64 |
m_current.getState() == NoteHypothesis::Rejected) {
|
|
| 65 |
m_current = h; |
|
| 66 |
m_haveCurrent = true; |
|
| 67 |
} else {
|
|
| 68 |
newCandidates.push_back(h); |
|
| 69 |
} |
|
| 70 |
|
|
| 71 |
} else {
|
|
| 72 |
newCandidates.push_back(h); |
|
| 73 |
} |
|
| 74 |
} |
|
| 75 |
} |
|
| 76 |
} |
|
| 77 |
|
|
| 78 |
if (!swallowed) {
|
|
| 79 |
NoteHypothesis h; |
|
| 80 |
if (h.accept(e)) {
|
|
| 81 |
newCandidates.push_back(h); |
|
| 82 |
} |
|
| 83 |
} |
|
| 84 |
|
|
| 85 |
m_candidates = reap(newCandidates); |
|
| 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 | 106 |
void |
| 95 | 107 |
AgentFeeder::finish() |
| 96 | 108 |
{
|
| AgentFeeder.h | ||
|---|---|---|
| 49 | 49 |
class AgentFeeder |
| 50 | 50 |
{
|
| 51 | 51 |
public: |
| 52 |
AgentFeeder() { }
|
|
| 52 |
AgentFeeder() : m_haveCurrent(false) { }
|
|
| 53 | 53 |
|
| 54 | 54 |
void feed(NoteHypothesis::Estimate); |
| 55 | 55 |
void finish(); |
| ... | ... | |
| 60 | 60 |
return m_accepted; |
| 61 | 61 |
} |
| 62 | 62 |
|
| 63 |
Hypotheses reap(Hypotheses); |
|
| 64 |
|
|
| 63 | 65 |
private: |
| 64 | 66 |
Hypotheses m_candidates; |
| 65 | 67 |
NoteHypothesis m_current; |
| 68 |
bool m_haveCurrent; |
|
| 66 | 69 |
Hypotheses m_accepted; |
| 67 | 70 |
}; |
| 68 | 71 |
|
| Makefile.osx | ||
|---|---|---|
| 1 | 1 |
|
| 2 |
CFLAGS := -I../inst/include -Wall -g -fPIC |
|
| 2 |
CFLAGS := -I../inst/include -I/usr/local/boost -Wall -g -fPIC
|
|
| 3 | 3 |
CXXFLAGS := $(CFLAGS) |
| 4 | 4 |
|
| 5 |
LDFLAGS := -dynamiclib -L../inst/lib -lvamp-sdk
|
|
| 6 |
|
|
| 5 |
LDFLAGS := -L../inst/lib -lvamp-sdk -L/usr/local/boost/stage/lib
|
|
| 6 |
PLUGIN_LDFLAGS := -dynamiclib |
|
| 7 | 7 |
PLUGIN_EXT := .dylib |
| 8 | 8 |
|
| 9 | 9 |
include Makefile.inc |
| test/TestAgentFeeder.cpp | ||
|---|---|---|
| 31 | 31 |
|
| 32 | 32 |
static Vamp::RealTime ms(int n) { return Vamp::RealTime::fromMilliseconds(n); }
|
| 33 | 33 |
|
| 34 |
static const int low = 500, high = 700; |
|
| 35 |
|
|
| 34 | 36 |
typedef NoteHypothesis::Estimate Est; |
| 35 | 37 |
|
| 36 | 38 |
BOOST_AUTO_TEST_SUITE(TestAgentFeeder) |
| ... | ... | |
| 45 | 47 |
|
| 46 | 48 |
BOOST_AUTO_TEST_CASE(feederSingle) |
| 47 | 49 |
{
|
| 48 |
Est e0(1, ms(0), 1);
|
|
| 49 |
Est e10(1, ms(10), 1);
|
|
| 50 |
Est e20(1, ms(20), 1);
|
|
| 51 |
Est e30(1, ms(30), 1);
|
|
| 50 |
Est e0(low, ms(0), 1);
|
|
| 51 |
Est e10(low, ms(10), 1);
|
|
| 52 |
Est e20(low, ms(20), 1);
|
|
| 53 |
Est e30(low, ms(30), 1);
|
|
| 52 | 54 |
|
| 53 | 55 |
AgentFeeder f; |
| 54 | 56 |
f.feed(e0); |
| ... | ... | |
| 64 | 66 |
|
| 65 | 67 |
BOOST_AUTO_TEST_CASE(feederPairSeparate) |
| 66 | 68 |
{
|
| 67 |
Est e0(1, ms(0), 1);
|
|
| 68 |
Est e10(1, ms(10), 1);
|
|
| 69 |
Est e20(1, ms(20), 1);
|
|
| 70 |
Est e30(1, ms(30), 1);
|
|
| 69 |
Est e0(low, ms(0), 1);
|
|
| 70 |
Est e10(low, ms(10), 1);
|
|
| 71 |
Est e20(low, ms(20), 1);
|
|
| 72 |
Est e30(low, ms(30), 1);
|
|
| 71 | 73 |
|
| 72 |
Est f0(3, ms(2000), 1);
|
|
| 73 |
Est f10(3, ms(2010), 1);
|
|
| 74 |
Est f20(3, ms(2020), 1);
|
|
| 75 |
Est f30(3, ms(2030), 1);
|
|
| 74 |
Est f0(high, ms(2000), 1);
|
|
| 75 |
Est f10(high, ms(2010), 1);
|
|
| 76 |
Est f20(high, ms(2020), 1);
|
|
| 77 |
Est f30(high, ms(2030), 1);
|
|
| 76 | 78 |
|
| 77 | 79 |
AgentFeeder f; |
| 78 | 80 |
f.feed(e0); |
| ... | ... | |
| 98 | 100 |
|
| 99 | 101 |
// (With fffffff stopping before eeee has expired.) |
| 100 | 102 |
|
| 101 |
// This should give us one hypothesis, eeee. |
|
| 103 |
// This should give us one hypothesis, eeee, because eeee is still |
|
| 104 |
// the current hypothesis by the time fffffff ends. |
|
| 102 | 105 |
|
| 103 |
Est e0(1, ms(0), 1);
|
|
| 104 |
Est e10(1, ms(10), 1);
|
|
| 106 |
Est e0(low, ms(0), 1);
|
|
| 107 |
Est e10(low, ms(10), 1);
|
|
| 105 | 108 |
|
| 106 |
Est e20(1, ms(20), 1);
|
|
| 107 |
Est f20(3, ms(20), 1);
|
|
| 109 |
Est e20(low, ms(20), 1);
|
|
| 110 |
Est f20(high, ms(20), 1);
|
|
| 108 | 111 |
|
| 109 |
Est e30(1, ms(30), 1);
|
|
| 110 |
Est f30(3, ms(30), 1);
|
|
| 112 |
Est e30(low, ms(30), 1);
|
|
| 113 |
Est f30(high, ms(30), 1);
|
|
| 111 | 114 |
|
| 112 |
Est f40(3, ms(40), 1);
|
|
| 113 |
Est f50(3, ms(50), 1);
|
|
| 114 |
Est f60(3, ms(60), 1);
|
|
| 115 |
Est f70(3, ms(70), 1);
|
|
| 116 |
Est f80(3, ms(80), 1);
|
|
| 115 |
Est f40(high, ms(40), 1);
|
|
| 116 |
Est f41(high, ms(41), 1);
|
|
| 117 |
Est f42(high, ms(42), 1);
|
|
| 118 |
Est f43(high, ms(43), 1);
|
|
| 119 |
Est f44(high, ms(44), 1);
|
|
| 117 | 120 |
|
| 118 | 121 |
AgentFeeder f; |
| 119 | 122 |
f.feed(e0); |
| ... | ... | |
| 123 | 126 |
f.feed(e30); |
| 124 | 127 |
f.feed(f30); |
| 125 | 128 |
f.feed(f40); |
| 126 |
f.feed(f50);
|
|
| 127 |
f.feed(f60);
|
|
| 128 |
f.feed(f70);
|
|
| 129 |
f.feed(f80);
|
|
| 129 |
f.feed(f41);
|
|
| 130 |
f.feed(f42);
|
|
| 131 |
f.feed(f43);
|
|
| 132 |
f.feed(f44);
|
|
| 130 | 133 |
f.finish(); |
| 131 | 134 |
|
| 132 | 135 |
AgentFeeder::Hypotheses accepted = f.getAcceptedHypotheses(); |
| ... | ... | |
| 153 | 156 |
// hypothesis ends, the fffffff one should replace it. So, |
| 154 | 157 |
// both should be recognised. |
| 155 | 158 |
|
| 156 |
Est e0(1, ms(0), 1);
|
|
| 157 |
Est e10(1, ms(500), 1);
|
|
| 159 |
Est e0(low, ms(0), 1);
|
|
| 160 |
Est e10(low, ms(10), 1);
|
|
| 158 | 161 |
|
| 159 |
Est e20(1, ms(1000), 1);
|
|
| 160 |
Est f20(3, ms(1000), 1);
|
|
| 162 |
Est e20(low, ms(20), 1);
|
|
| 163 |
Est f20(high, ms(20), 1);
|
|
| 161 | 164 |
|
| 162 |
Est e30(1, ms(1500), 1);
|
|
| 163 |
Est f30(3, ms(1500), 1);
|
|
| 165 |
Est e30(low, ms(30), 1);
|
|
| 166 |
Est f30(high, ms(30), 1);
|
|
| 164 | 167 |
|
| 165 |
Est f40(3, ms(2000), 1);
|
|
| 166 |
Est f50(3, ms(2500), 1);
|
|
| 167 |
Est f60(3, ms(3000), 1);
|
|
| 168 |
Est f70(3, ms(3500), 1);
|
|
| 169 |
Est f80(3, ms(4000), 1);
|
|
| 168 |
Est f40(high, ms(40), 1);
|
|
| 169 |
Est f50(high, ms(50), 1);
|
|
| 170 |
Est f60(high, ms(60), 1);
|
|
| 171 |
Est f70(high, ms(70), 1);
|
|
| 172 |
Est f80(high, ms(80), 1);
|
|
| 170 | 173 |
|
| 171 | 174 |
AgentFeeder f; |
| 172 | 175 |
f.feed(e0); |
| ... | ... | |
| 192 | 195 |
BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(4)); |
| 193 | 196 |
++i; |
| 194 | 197 |
|
| 195 |
BOOST_CHECK_EQUAL(i->getStartTime(), ms(1000));
|
|
| 198 |
BOOST_CHECK_EQUAL(i->getStartTime(), ms(20));
|
|
| 196 | 199 |
BOOST_CHECK_EQUAL(i->getAcceptedEstimates().size(), size_t(7)); |
| 197 | 200 |
++i; |
| 198 | 201 |
} |
| ... | ... | |
| 208 | 211 |
// satisfied hypothesis eeeeeeee while it is still in |
| 209 | 212 |
// progress. |
| 210 | 213 |
|
| 211 |
Est e0(1, ms(0), 1);
|
|
| 212 |
Est e10(1, ms(10), 1);
|
|
| 213 |
Est e20(1, ms(20), 1);
|
|
| 214 |
Est e30(1, ms(30), 1);
|
|
| 215 |
Est e40(1, ms(40), 1);
|
|
| 216 |
Est e50(1, ms(50), 1);
|
|
| 217 |
Est e60(1, ms(60), 1);
|
|
| 218 |
Est e70(1, ms(70), 1);
|
|
| 214 |
Est e0(low, ms(0), 1);
|
|
| 215 |
Est e10(low, ms(10), 1);
|
|
| 216 |
Est e20(low, ms(20), 1);
|
|
| 217 |
Est e30(low, ms(30), 1);
|
|
| 218 |
Est e40(low, ms(40), 1);
|
|
| 219 |
Est e50(low, ms(50), 1);
|
|
| 220 |
Est e60(low, ms(60), 1);
|
|
| 221 |
Est e70(low, ms(70), 1);
|
|
| 219 | 222 |
|
| 220 |
Est f20(3, ms(20), 1);
|
|
| 221 |
Est f30(3, ms(30), 1);
|
|
| 222 |
Est f40(3, ms(40), 1);
|
|
| 223 |
Est f50(3, ms(50), 1);
|
|
| 223 |
Est f20(high, ms(20), 1);
|
|
| 224 |
Est f30(high, ms(30), 1);
|
|
| 225 |
Est f40(high, ms(40), 1);
|
|
| 226 |
Est f50(high, ms(50), 1);
|
|
| 224 | 227 |
|
| 225 | 228 |
AgentFeeder f; |
| 226 | 229 |
|
Also available in: Unified diff