comparison src/NoteHypothesis.h @ 184:9b9cdfccbd14 noteagent

Wire up note agent code -- results are not very good, so far
author Chris Cannam
date Wed, 28 May 2014 14:54:01 +0100
parents e1718e64a921
children
comparison
equal deleted inserted replaced
182:e1718e64a921 184:9b9cdfccbd14
45 virtual bool accept(Observation); 45 virtual bool accept(Observation);
46 virtual State getState() const; 46 virtual State getState() const;
47 virtual Observations getAcceptedObservations() const; 47 virtual Observations getAcceptedObservations() const;
48 48
49 struct Note { 49 struct Note {
50 Note() : freq(0), time(), duration() { } 50 Note() : freq(0), time(), duration(), confidence(1.0) { }
51 Note(double _f, Vamp::RealTime _t, Vamp::RealTime _d) : 51 Note(double _f, Vamp::RealTime _t, Vamp::RealTime _d, double _i) :
52 freq(_f), time(_t), duration(_d) { } 52 freq(_f), time(_t), duration(_d), confidence(_i) { }
53 bool operator==(const Note &e) const { 53 bool operator==(const Note &e) const {
54 return e.freq == freq && e.time == time && e.duration == duration; 54 return e.freq == freq && e.time == time &&
55 e.duration == duration && e.confidence == confidence;
55 } 56 }
56 double freq; 57 double freq;
57 Vamp::RealTime time; 58 Vamp::RealTime time;
58 Vamp::RealTime duration; 59 Vamp::RealTime duration;
60 double confidence;
59 }; 61 };
60 62
61 /** 63 /**
62 * Return the mean frequency of the accepted observations 64 * Return the mean frequency of the accepted observations
63 */ 65 */
64 double getMeanFrequency() const; 66 double getMeanFrequency() const;
67
68 /**
69 * Return the median frequency of the accepted observations
70 */
71 double getMedianFrequency() const;
72
73 /**
74 * Return the median confidence of the accepted observations
75 */
76 double getMedianConfidence() const;
65 77
66 /** 78 /**
67 * Return a single note roughly matching this hypothesis 79 * Return a single note roughly matching this hypothesis
68 */ 80 */
69 Note getAveragedNote() const; 81 Note getAveragedNote() const;
83 bool operator==(const NoteHypothesis &other) const { 95 bool operator==(const NoteHypothesis &other) const {
84 return m_state == other.m_state && m_pending == other.m_pending; 96 return m_state == other.m_state && m_pending == other.m_pending;
85 } 97 }
86 98
87 bool operator<(const NoteHypothesis &other) const { 99 bool operator<(const NoteHypothesis &other) const {
88 return getStartTime() < other.getStartTime(); 100 if (getStartTime() != other.getStartTime()) {
101 return getStartTime() < other.getStartTime();
102 } else if (m_state != other.m_state) {
103 return m_state < other.m_state;
104 } else if (m_pending.size() != other.m_pending.size()) {
105 return m_pending.size() < other.m_pending.size();
106 } else {
107 Observations::const_iterator i = m_pending.begin();
108 Observations::const_iterator j = other.m_pending.begin();
109 while (i != m_pending.end()) {
110 if (*i == *j) {
111 ++i;
112 ++j;
113 } else {
114 return *i < *j;
115 }
116 }
117 return false;
118 }
89 } 119 }
90 120
91 private: 121 private:
92 bool isWithinTolerance(Observation) const; 122 bool isWithinTolerance(Observation) const;
93 bool isOutOfDateFor(Observation) const; 123 bool isOutOfDateFor(Observation) const;