Mercurial > hg > pyin
changeset 70:01057d57dd9a tony
pyin has now a parameter to go for precise timing (slow) or not (fast)
author | matthiasm |
---|---|
date | Fri, 13 Jun 2014 11:52:57 +0100 |
parents | d1f89559321a |
children | 27eee0f7a4f6 |
files | LocalCandidatePYIN.cpp LocalCandidatePYIN.h PYinVamp.cpp PYinVamp.h Yin.cpp Yin.h |
diffstat | 6 files changed, 64 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/LocalCandidatePYIN.cpp Wed Apr 02 17:42:56 2014 +0100 +++ b/LocalCandidatePYIN.cpp Fri Jun 13 11:52:57 2014 +0100 @@ -42,10 +42,10 @@ m_blockSize(2048), m_fmin(40), m_fmax(700), - m_yin(2048, inputSampleRate, 0.0), m_oPitchTrackCandidates(0), m_threshDistr(2.0f), m_outputUnvoiced(0.0f), + m_preciseTime(0.0f), m_pitchProb(0), m_timestamp(0), m_nCandidate(13) @@ -165,6 +165,18 @@ d.valueNames.push_back("Yes, as negative frequencies"); list.push_back(d); + d.identifier = "precisetime"; + d.valueNames.clear(); + d.name = "Use non-standard precise YIN timing (slow)."; + d.description = "."; + d.unit = ""; + d.minValue = 0.0f; + d.maxValue = 1.0f; + d.defaultValue = 0.0f; + d.isQuantized = true; + d.quantizeStep = 1.0f; + list.push_back(d); + return list; } @@ -177,6 +189,9 @@ if (identifier == "outputunvoiced") { return m_outputUnvoiced; } + if (identifier == "precisetime") { + return m_preciseTime; + } return 0.f; } @@ -191,7 +206,10 @@ { m_outputUnvoiced = value; } - + if (identifier == "precisetime") + { + m_preciseTime = value; + } } LocalCandidatePYIN::ProgramList @@ -261,9 +279,6 @@ void LocalCandidatePYIN::reset() { - m_yin.setThresholdDistr(m_threshDistr); - m_yin.setFrameSize(m_blockSize); - m_pitchProb.clear(); m_timestamp.clear(); /* @@ -283,7 +298,8 @@ size_t yinBufferSize = m_blockSize/2; double* yinBuffer = new double[yinBufferSize]; - YinUtil::slowDifference(dInputBuffers, yinBuffer, yinBufferSize); + if (!m_preciseTime) YinUtil::fastDifference(dInputBuffers, yinBuffer, yinBufferSize); + else YinUtil::slowDifference(dInputBuffers, yinBuffer, yinBufferSize); delete [] dInputBuffers;
--- a/LocalCandidatePYIN.h Wed Apr 02 17:42:56 2014 +0100 +++ b/LocalCandidatePYIN.h Fri Jun 13 11:52:57 2014 +0100 @@ -61,12 +61,12 @@ size_t m_blockSize; float m_fmin; float m_fmax; - Yin m_yin; mutable int m_oPitchTrackCandidates; float m_threshDistr; float m_outputUnvoiced; + float m_preciseTime; vector<vector<pair<double, double> > > m_pitchProb; vector<Vamp::RealTime> m_timestamp; size_t m_nCandidate;
--- a/PYinVamp.cpp Wed Apr 02 17:42:56 2014 +0100 +++ b/PYinVamp.cpp Fri Jun 13 11:52:57 2014 +0100 @@ -45,6 +45,7 @@ m_oNotes(0), m_threshDistr(2.0f), m_outputUnvoiced(0.0f), + m_preciseTime(0.0f), m_pitchProb(0), m_timestamp(0) { @@ -163,6 +164,19 @@ d.valueNames.push_back("Yes, as negative frequencies"); list.push_back(d); + d.identifier = "precisetime"; + d.valueNames.clear(); + d.name = "Use non-standard precise YIN timing (slow)."; + d.description = "."; + d.unit = ""; + d.minValue = 0.0f; + d.maxValue = 1.0f; + d.defaultValue = 0.0f; + d.isQuantized = true; + d.quantizeStep = 1.0f; + list.push_back(d); + + return list; } @@ -175,6 +189,9 @@ if (identifier == "outputunvoiced") { return m_outputUnvoiced; } + if (identifier == "precisetime") { + return m_preciseTime; + } return 0.f; } @@ -189,7 +206,10 @@ { m_outputUnvoiced = value; } - + if (identifier == "precisetime") + { + m_preciseTime = value; + } } PYinVamp::ProgramList @@ -341,6 +361,7 @@ { m_yin.setThresholdDistr(m_threshDistr); m_yin.setFrameSize(m_blockSize); + m_yin.setFast(!m_preciseTime); m_pitchProb.clear(); m_timestamp.clear();
--- a/PYinVamp.h Wed Apr 02 17:42:56 2014 +0100 +++ b/PYinVamp.h Fri Jun 13 11:52:57 2014 +0100 @@ -72,6 +72,7 @@ float m_threshDistr; float m_outputUnvoiced; + float m_preciseTime; vector<vector<pair<double, double> > > m_pitchProb; vector<Vamp::RealTime> m_timestamp; };
--- a/Yin.cpp Wed Apr 02 17:42:56 2014 +0100 +++ b/Yin.cpp Fri Jun 13 11:52:57 2014 +0100 @@ -25,12 +25,13 @@ using std::vector; -Yin::Yin(size_t frameSize, size_t inputSampleRate, double thresh) : +Yin::Yin(size_t frameSize, size_t inputSampleRate, double thresh, bool fast) : m_frameSize(frameSize), m_inputSampleRate(inputSampleRate), m_thresh(thresh), m_threshDistr(2), - m_yinBufferSize(frameSize/2) + m_yinBufferSize(frameSize/2), + m_fast(fast) { if (frameSize & (frameSize-1)) { // throw "N must be a power of two"; @@ -45,9 +46,9 @@ Yin::process(const double *in) const { double* yinBuffer = new double[m_yinBufferSize]; - // calculate aperiodicity function for all periods - YinUtil::slowDifference(in, yinBuffer, m_yinBufferSize); + if (m_fast) YinUtil::fastDifference(in, yinBuffer, m_yinBufferSize); + else YinUtil::slowDifference(in, yinBuffer, m_yinBufferSize); YinUtil::cumulativeDifference(yinBuffer, m_yinBufferSize); int tau = 0; @@ -86,7 +87,9 @@ double* yinBuffer = new double[m_yinBufferSize]; // calculate aperiodicity function for all periods - YinUtil::slowDifference(in, yinBuffer, m_yinBufferSize); + if (m_fast) YinUtil::fastDifference(in, yinBuffer, m_yinBufferSize); + else YinUtil::slowDifference(in, yinBuffer, m_yinBufferSize); + YinUtil::cumulativeDifference(yinBuffer, m_yinBufferSize); vector<double> peakProbability = YinUtil::yinProb(yinBuffer, m_threshDistr, m_yinBufferSize); @@ -138,6 +141,13 @@ return 0; } +int +Yin::setFast(bool fast) +{ + m_fast = fast; + return 0; +} + // int // Yin::setRemoveUnvoiced(bool parameter) // {
--- a/Yin.h Wed Apr 02 17:42:56 2014 +0100 +++ b/Yin.h Fri Jun 13 11:52:57 2014 +0100 @@ -31,7 +31,7 @@ class Yin { public: - Yin(size_t frameSize, size_t inputSampleRate, double thresh = 0.2); + Yin(size_t frameSize, size_t inputSampleRate, double thresh = 0.2, bool fast = true); virtual ~Yin(); struct YinOutput { @@ -53,6 +53,7 @@ int setThreshold(double parameter); int setThresholdDistr(float parameter); int setFrameSize(size_t frameSize); + int setFast(bool fast); // int setRemoveUnvoiced(bool frameSize); YinOutput process(const double *in) const; YinOutput processProbabilisticYin(const double *in) const; @@ -64,6 +65,7 @@ mutable double m_thresh; mutable size_t m_threshDistr; mutable size_t m_yinBufferSize; + mutable bool m_fast; // mutable bool m_removeUnvoiced; };