# HG changeset patch # User Chris Cannam # Date 1342211729 -3600 # Node ID 0e4e885408db7c70568f791a0800048a0947e6a7 # Parent ce5d04327b98e299773aadd9da9ff37ac212022d Another tidy diff -r ce5d04327b98 -r 0e4e885408db CepstrumPitchTracker.cpp --- a/CepstrumPitchTracker.cpp Fri Jul 13 21:25:34 2012 +0100 +++ b/CepstrumPitchTracker.cpp Fri Jul 13 21:35:29 2012 +0100 @@ -45,7 +45,7 @@ } bool -CepstrumPitchTracker::Hypothesis::isWithinTolerance(Estimate s) +CepstrumPitchTracker::Hypothesis::isWithinTolerance(Estimate s) const { if (m_pending.empty()) { return true; @@ -68,7 +68,7 @@ } bool -CepstrumPitchTracker::Hypothesis::isOutOfDateFor(Estimate s) +CepstrumPitchTracker::Hypothesis::isOutOfDateFor(Estimate s) const { if (m_pending.empty()) return false; @@ -77,7 +77,7 @@ } bool -CepstrumPitchTracker::Hypothesis::isSatisfied() +CepstrumPitchTracker::Hypothesis::isSatisfied() const { if (m_pending.empty()) return false; @@ -91,7 +91,6 @@ if (meanConfidence > 0.0) { lengthRequired = int(2.0 / meanConfidence + 0.5); } - std::cerr << "meanConfidence = " << meanConfidence << ", lengthRequired = " << lengthRequired << ", length = " << m_pending.size() << std::endl; return (m_pending.size() > lengthRequired); } @@ -142,13 +141,13 @@ } CepstrumPitchTracker::Hypothesis::State -CepstrumPitchTracker::Hypothesis::getState() +CepstrumPitchTracker::Hypothesis::getState() const { return m_state; } CepstrumPitchTracker::Hypothesis::Estimates -CepstrumPitchTracker::Hypothesis::getAcceptedEstimates() +CepstrumPitchTracker::Hypothesis::getAcceptedEstimates() const { if (m_state == Satisfied || m_state == Expired) { return m_pending; @@ -158,7 +157,7 @@ } double -CepstrumPitchTracker::Hypothesis::getMeanFrequency() +CepstrumPitchTracker::Hypothesis::getMeanFrequency() const { double acc = 0.0; for (int i = 0; i < m_pending.size(); ++i) { @@ -169,7 +168,7 @@ } CepstrumPitchTracker::Hypothesis::Note -CepstrumPitchTracker::Hypothesis::getAveragedNote() +CepstrumPitchTracker::Hypothesis::getAveragedNote() const { Note n; @@ -182,7 +181,7 @@ n.time = m_pending.begin()->time; - Estimates::iterator i = m_pending.end(); + Estimates::const_iterator i = m_pending.end(); --i; n.duration = i->time - n.time; @@ -192,27 +191,6 @@ return n; } -void -CepstrumPitchTracker::Hypothesis::addFeatures(FeatureSet &fs) -{ - for (int i = 0; i < m_pending.size(); ++i) { - Feature f; - f.hasTimestamp = true; - f.timestamp = m_pending[i].time; - f.values.push_back(m_pending[i].freq); - fs[0].push_back(f); - } - - Feature nf; - nf.hasTimestamp = true; - nf.hasDuration = true; - Note n = getAveragedNote(); - nf.timestamp = n.time; - nf.duration = n.duration; - nf.values.push_back(n.freq); - fs[1].push_back(nf); -} - CepstrumPitchTracker::CepstrumPitchTracker(float inputSampleRate) : Plugin(inputSampleRate), m_channels(0), @@ -411,6 +389,29 @@ } void +CepstrumPitchTracker::addFeaturesFrom(Hypothesis h, FeatureSet &fs) +{ + Hypothesis::Estimates es = h.getAcceptedEstimates(); + + for (int i = 0; i < es.size(); ++i) { + Feature f; + f.hasTimestamp = true; + f.timestamp = es[i].time; + f.values.push_back(es[i].freq); + fs[0].push_back(f); + } + + Feature nf; + nf.hasTimestamp = true; + nf.hasDuration = true; + Hypothesis::Note n = h.getAveragedNote(); + nf.timestamp = n.time; + nf.duration = n.duration; + nf.values.push_back(n.freq); + fs[1].push_back(nf); +} + +void CepstrumPitchTracker::filter(const double *cep, double *data) { for (int i = 0; i < m_bins; ++i) { @@ -604,7 +605,7 @@ } if (m_good.getState() == Hypothesis::Expired) { - m_good.addFeatures(fs); + addFeaturesFrom(m_good, fs); } if (m_good.getState() == Hypothesis::Expired || @@ -637,7 +638,7 @@ { FeatureSet fs; if (m_good.getState() == Hypothesis::Satisfied) { - m_good.addFeatures(fs); + addFeaturesFrom(m_good, fs); } return fs; } diff -r ce5d04327b98 -r 0e4e885408db CepstrumPitchTracker.h --- a/CepstrumPitchTracker.h Fri Jul 13 21:25:34 2012 +0100 +++ b/CepstrumPitchTracker.h Fri Jul 13 21:35:29 2012 +0100 @@ -103,18 +103,15 @@ bool accept(Estimate); - State getState(); - - Estimates getAcceptedEstimates(); - Note getAveragedNote(); - - void addFeatures(FeatureSet &fs); + State getState() const; + Estimates getAcceptedEstimates() const; + Note getAveragedNote() const; private: - bool isWithinTolerance(Estimate); - bool isOutOfDateFor(Estimate); - bool isSatisfied(); - double getMeanFrequency(); + bool isWithinTolerance(Estimate) const; + bool isOutOfDateFor(Estimate) const; + bool isSatisfied() const; + double getMeanFrequency() const; State m_state; Estimates m_pending; @@ -124,6 +121,8 @@ Hypotheses m_possible; Hypothesis m_good; + void addFeaturesFrom(Hypothesis h, FeatureSet &fs); + void filter(const double *in, double *out); double cubicInterpolate(const double[4], double); double findInterpolatedPeak(const double *in, int maxbin);