Revision 17:088da53a2869 CepstrumPitchTracker.cpp
| CepstrumPitchTracker.cpp | ||
|---|---|---|
| 50 | 50 |
return true; |
| 51 | 51 |
} |
| 52 | 52 |
|
| 53 |
Estimate first = m_pending[0]; |
|
| 54 |
Estimate last = m_pending[m_pending.size()-1]; |
|
| 55 |
|
|
| 56 | 53 |
// check we are within a relatively close tolerance of the last |
| 57 | 54 |
// candidate |
| 55 |
Estimate last = m_pending[m_pending.size()-1]; |
|
| 58 | 56 |
double r = s.freq / last.freq; |
| 59 | 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 |
|
| 63 |
r = s.freq / first.freq; |
|
| 60 |
// and within a slightly bigger tolerance of the current mean |
|
| 61 |
double meanFreq = getMeanFrequency(); |
|
| 62 |
r = s.freq / meanFreq; |
|
| 64 | 63 |
cents = lrint(1200.0 * (log(r) / log(2.0))); |
| 65 | 64 |
if (cents < -80 || cents > 80) return false; |
| 66 | 65 |
|
| ... | ... | |
| 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 | 171 |
CepstrumPitchTracker::Hypothesis::Note |
| 162 | 172 |
CepstrumPitchTracker::Hypothesis::getAveragedNote() |
| 163 | 173 |
{
|
| ... | ... | |
| 176 | 186 |
--i; |
| 177 | 187 |
n.duration = i->time - n.time; |
| 178 | 188 |
|
| 179 |
// just mean frequency for now, but this isn't at all right |
|
| 180 |
double acc = 0.0; |
|
| 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; |
|
| 189 |
// just mean frequency for now, but this isn't at all right perceptually |
|
| 190 |
n.freq = getMeanFrequency(); |
|
| 186 | 191 |
|
| 187 | 192 |
return n; |
| 188 | 193 |
} |
Also available in: Unified diff