Mercurial > hg > vamp-simple-cepstrum
changeset 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 | 1ae8041ae31b |
files | CepstrumPitchTracker.cpp CepstrumPitchTracker.h |
diffstat | 2 files changed, 19 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/CepstrumPitchTracker.cpp Tue Jul 03 21:10:56 2012 +0100 +++ b/CepstrumPitchTracker.cpp Wed Jul 04 22:28:46 2012 +0100 @@ -50,17 +50,16 @@ return true; } - Estimate first = m_pending[0]; - Estimate last = m_pending[m_pending.size()-1]; - // check we are within a relatively close tolerance of the last // candidate + Estimate last = m_pending[m_pending.size()-1]; double r = s.freq / last.freq; int cents = lrint(1200.0 * (log(r) / log(2.0))); - if (cents < -40 || cents > 40) return false; + if (cents < -60 || cents > 60) return false; - // and within a wider tolerance of our starting candidate - r = s.freq / first.freq; + // and within a slightly bigger tolerance of the current mean + double meanFreq = getMeanFrequency(); + r = s.freq / meanFreq; cents = lrint(1200.0 * (log(r) / log(2.0))); if (cents < -80 || cents > 80) return false; @@ -158,6 +157,17 @@ } } +double +CepstrumPitchTracker::Hypothesis::getMeanFrequency() +{ + double acc = 0.0; + for (int i = 0; i < m_pending.size(); ++i) { + acc += m_pending[i].freq; + } + acc /= m_pending.size(); + return acc; +} + CepstrumPitchTracker::Hypothesis::Note CepstrumPitchTracker::Hypothesis::getAveragedNote() { @@ -176,13 +186,8 @@ --i; n.duration = i->time - n.time; - // just mean frequency for now, but this isn't at all right - double acc = 0.0; - for (int i = 0; i < m_pending.size(); ++i) { - acc += m_pending[i].freq; - } - acc /= m_pending.size(); - n.freq = acc; + // just mean frequency for now, but this isn't at all right perceptually + n.freq = getMeanFrequency(); return n; }