Mercurial > hg > pyin
diff PYIN.cpp @ 91:854d9403c5be
note separation based on RMS
author | matthiasm |
---|---|
date | Wed, 07 Jan 2015 16:30:16 +0000 |
parents | b087967c4417 |
children | 2687ba2cafae |
line wrap: on
line diff
--- a/PYIN.cpp Wed Jan 07 15:22:03 2015 +0000 +++ b/PYIN.cpp Wed Jan 07 16:30:16 2015 +0000 @@ -46,7 +46,8 @@ m_threshDistr(2.0f), m_outputUnvoiced(0.0f), m_pitchProb(0), - m_timestamp(0) + m_timestamp(0), + m_level(0) { } @@ -344,6 +345,7 @@ m_pitchProb.clear(); m_timestamp.clear(); + m_level.clear(); /* std::cerr << "PYIN::reset" << ", blockSize = " << m_blockSize @@ -363,6 +365,8 @@ Yin::YinOutput yo = m_yin.processProbabilisticYin(dInputBuffers); delete [] dInputBuffers; + m_level.push_back(yo.rms); + // First, get the things out of the way that we don't want to output // immediately, but instead save for later. vector<pair<double, double> > tempPitchProb; @@ -470,7 +474,11 @@ std::vector<float> notePitchTrack; // collects pitches for one note at a time for (size_t iFrame = 0; iFrame < nFrame; ++iFrame) { - isVoiced = mnOut[iFrame].noteState < 3 && smoothedPitch[iFrame].size() > 0; + isVoiced = mnOut[iFrame].noteState < 3 + && smoothedPitch[iFrame].size() > 0 + && (iFrame == nFrame-1 + || ((m_level[iFrame+1]/m_level[iFrame]) < 1.25)); + // std::cerr << m_level[iFrame]/m_level[iFrame-1] << std::endl; if (isVoiced && iFrame != nFrame-1) { if (oldIsVoiced == 0) // beginning of a note @@ -481,7 +489,7 @@ float pitch = smoothedPitch[iFrame][0].first; notePitchTrack.push_back(pitch); // add to the note's pitch track } else { // not currently voiced - if (oldIsVoiced == 1 && notePitchTrack.size() > 17) // end of note + if (oldIsVoiced == 1 && notePitchTrack.size() > 14) // end of note { std::sort(notePitchTrack.begin(), notePitchTrack.end()); float medianPitch = notePitchTrack[notePitchTrack.size()/2];