comparison CepstrumPitchTracker.cpp @ 22:a949c0278d7d track

Adjust hypothesis tolerances (i.e. note breaking algorithm)
author Chris Cannam
date Wed, 04 Jul 2012 22:28:46 +0100
parents df41333abbc9
children a15d8c89a36e
comparison
equal deleted inserted replaced
21:df41333abbc9 22:a949c0278d7d
48 { 48 {
49 if (m_pending.empty()) { 49 if (m_pending.empty()) {
50 return true; 50 return true;
51 } 51 }
52 52
53 Estimate first = m_pending[0];
54 Estimate last = m_pending[m_pending.size()-1];
55
56 // check we are within a relatively close tolerance of the last 53 // check we are within a relatively close tolerance of the last
57 // candidate 54 // candidate
55 Estimate last = m_pending[m_pending.size()-1];
58 double r = s.freq / last.freq; 56 double r = s.freq / last.freq;
59 int cents = lrint(1200.0 * (log(r) / log(2.0))); 57 int cents = lrint(1200.0 * (log(r) / log(2.0)));
60 if (cents < -40 || cents > 40) return false; 58 if (cents < -60 || cents > 60) return false;
61 59
62 // and within a wider tolerance of our starting candidate 60 // and within a slightly bigger tolerance of the current mean
63 r = s.freq / first.freq; 61 double meanFreq = getMeanFrequency();
62 r = s.freq / meanFreq;
64 cents = lrint(1200.0 * (log(r) / log(2.0))); 63 cents = lrint(1200.0 * (log(r) / log(2.0)));
65 if (cents < -80 || cents > 80) return false; 64 if (cents < -80 || cents > 80) return false;
66 65
67 return true; 66 return true;
68 } 67 }
156 } else { 155 } else {
157 return Estimates(); 156 return Estimates();
158 } 157 }
159 } 158 }
160 159
160 double
161 CepstrumPitchTracker::Hypothesis::getMeanFrequency()
162 {
163 double acc = 0.0;
164 for (int i = 0; i < m_pending.size(); ++i) {
165 acc += m_pending[i].freq;
166 }
167 acc /= m_pending.size();
168 return acc;
169 }
170
161 CepstrumPitchTracker::Hypothesis::Note 171 CepstrumPitchTracker::Hypothesis::Note
162 CepstrumPitchTracker::Hypothesis::getAveragedNote() 172 CepstrumPitchTracker::Hypothesis::getAveragedNote()
163 { 173 {
164 Note n; 174 Note n;
165 175
174 184
175 Estimates::iterator i = m_pending.end(); 185 Estimates::iterator i = m_pending.end();
176 --i; 186 --i;
177 n.duration = i->time - n.time; 187 n.duration = i->time - n.time;
178 188
179 // just mean frequency for now, but this isn't at all right 189 // just mean frequency for now, but this isn't at all right perceptually
180 double acc = 0.0; 190 n.freq = getMeanFrequency();
181 for (int i = 0; i < m_pending.size(); ++i) {
182 acc += m_pending[i].freq;
183 }
184 acc /= m_pending.size();
185 n.freq = acc;
186 191
187 return n; 192 return n;
188 } 193 }
189 194
190 void 195 void