# HG changeset patch # User matthiasm # Date 1390503530 0 # Node ID c0763eed48f0446d841ab0b95dfa1cfd286976d5 # Parent 24943b76a1097fd058c11ca3487b6a6f3c5910ee new plugin -- working towards local candidate PYIN diff -r 24943b76a109 -r c0763eed48f0 Makefile.inc --- a/Makefile.inc Tue Jan 21 22:12:21 2014 +0000 +++ b/Makefile.inc Thu Jan 23 18:58:50 2014 +0000 @@ -11,6 +11,7 @@ SOURCES := PYIN.cpp \ VampYin.cpp \ + LocalCandidatePYIN.cpp \ Yin.cpp \ YinUtil.cpp \ MonoNote.cpp \ @@ -65,6 +66,7 @@ PYIN.o: PYIN.h VampYin.o: VampYin.h +LocalCandidatePYIN.o: LocalCandidatePYIN.h Yin.o: Yin.h MonoNoteParameters.o: MonoNoteParameters.h MonoNote.o: MonoNote.h @@ -72,7 +74,7 @@ MonoPitchHMM.o: MonoPitchHMM.h SparseHMM.o: SparseHMM.h MonoNoteHMM.o: MonoNoteHMM.h -libmain.o: PYIN.h VampYin.h +libmain.o: PYIN.h VampYin.h LocalCandidatePYIN.h test/TestMeanFilter.o: MeanFilter.h test/TestYin.o: Yin.h diff -r 24943b76a109 -r c0763eed48f0 PYIN.cpp --- a/PYIN.cpp Tue Jan 21 22:12:21 2014 +0000 +++ b/PYIN.cpp Thu Jan 23 18:58:50 2014 +0000 @@ -395,7 +395,6 @@ } fs[m_oF0Probs].push_back(f); - f.values.clear(); f.values.push_back(voicedProb); fs[m_oVoicedProb].push_back(f); diff -r 24943b76a109 -r c0763eed48f0 Yin.cpp --- a/Yin.cpp Tue Jan 21 22:12:21 2014 +0000 +++ b/Yin.cpp Thu Jan 23 18:58:50 2014 +0000 @@ -82,7 +82,7 @@ Yin::YinOutput Yin::processProbabilisticYin(const double *in) const { - + double* yinBuffer = new double[m_yinBufferSize]; // calculate aperiodicity function for all periods @@ -90,18 +90,11 @@ YinUtil::cumulativeDifference(yinBuffer, m_yinBufferSize); vector peakProbability = YinUtil::yinProb(yinBuffer, m_threshDistr, m_yinBufferSize); - - // calculate overall "probability" from peak probability - double probSum = 0; - for (size_t iBin = 0; iBin < m_yinBufferSize; ++iBin) - { - probSum += peakProbability[iBin]; - } + // basic yin output Yin::YinOutput yo(0,0,0); for (size_t iBuf = 0; iBuf < m_yinBufferSize; ++iBuf) { - yo.salience.push_back(peakProbability[iBuf]); if (peakProbability[iBuf] > 0) { double currentF0 = @@ -111,6 +104,11 @@ } } + // add salience + for (size_t iBuf = 0; iBuf < m_yinBufferSize; ++iBuf) { + yo.salience.push_back(peakProbability[iBuf]); + } + // std::cerr << yo.freqProb.size() << std::endl; delete [] yinBuffer; diff -r 24943b76a109 -r c0763eed48f0 YinUtil.cpp --- a/YinUtil.cpp Tue Jan 21 22:12:21 2014 +0000 +++ b/YinUtil.cpp Thu Jan 23 18:58:50 2014 +0000 @@ -164,10 +164,16 @@ return 0; } +std::vector +YinUtil::yinProb(const double *yinBuffer, const size_t prior, const size_t yinBufferSize, const size_t minTau0, const size_t maxTau0) +{ + size_t minTau = 2; + size_t maxTau = yinBufferSize; -std::vector -YinUtil::yinProb(const double *yinBuffer, const size_t prior, const size_t yinBufferSize) -{ + // adapt period range, if necessary + if (minTau0 > 0 && minTau0 < maxTau0) minTau = minTau0; + if (maxTau0 > 0 && maxTau0 < yinBufferSize && maxTau0 > minTau) maxTau = maxTau0; + double minWeight = 0.01; size_t tau; std::vector thresholds; @@ -220,28 +226,18 @@ thresholds.push_back(0.01 + i*0.01); } - // double minYin = 2936; - // for (size_t i = 2; i < yinBufferSize; ++i) - // { - // if (yinBuffer[i] < minYin) - // { - // minYin = yinBuffer[i]; - // } - // } - // if (minYin < 0.01) std::cerr << "min Yin buffer element: " << minYin << std::endl; - int currThreshInd = nThreshold-1; - tau = 2; + tau = minTau; // double factor = 1.0 / (0.25 * (nThresholdInt+1) * (nThresholdInt + 1)); // factor to scale down triangular weight size_t minInd = 0; float minVal = 42.f; - while (currThreshInd != -1 && tau < yinBufferSize) + while (currThreshInd != -1 && tau < maxTau) { if (yinBuffer[tau] < thresholds[currThreshInd]) { - while (tau + 1 < yinBufferSize && yinBuffer[tau+1] < yinBuffer[tau]) + while (tau + 1 < maxTau && yinBuffer[tau+1] < yinBuffer[tau]) { tau++; } @@ -258,7 +254,7 @@ } } double nonPeakProb = 1; - for (size_t i = 0; i < yinBufferSize; ++i) + for (size_t i = minTau; i < maxTau; ++i) { nonPeakProb -= peakProb[i]; } diff -r 24943b76a109 -r c0763eed48f0 YinUtil.h --- a/YinUtil.h Tue Jan 21 22:12:21 2014 +0000 +++ b/YinUtil.h Thu Jan 23 18:58:50 2014 +0000 @@ -33,7 +33,7 @@ static void fastDifference(const double *in, double *yinBuffer, const size_t yinBufferSize); static void cumulativeDifference(double *yinBuffer, const size_t yinBufferSize); static int absoluteThreshold(const double *yinBuffer, const size_t yinBufferSize, const double thresh); - static vector yinProb(const double *yinBuffer, const size_t prior, const size_t yinBufferSize); + static vector yinProb(const double *yinBuffer, const size_t prior, const size_t yinBufferSize, size_t minTau = 0, size_t maxTau = 0); static double parabolicInterpolation(const double *yinBuffer, const size_t tau, const size_t yinBufferSize); }; diff -r 24943b76a109 -r c0763eed48f0 libmain.cpp --- a/libmain.cpp Tue Jan 21 22:12:21 2014 +0000 +++ b/libmain.cpp Thu Jan 23 18:58:50 2014 +0000 @@ -16,9 +16,11 @@ #include "PYIN.h" #include "VampYin.h" +#include "LocalCandidatePYIN.h" static Vamp::PluginAdapter pyinPluginAdapter; static Vamp::PluginAdapter vampyinPluginAdapter; +static Vamp::PluginAdapter localCandidatePYINPluginAdapter; const VampPluginDescriptor * vampGetPluginDescriptor(unsigned int version, unsigned int index) @@ -28,6 +30,7 @@ switch (index) { case 0: return pyinPluginAdapter.getDescriptor(); case 1: return vampyinPluginAdapter.getDescriptor(); + case 2: return localCandidatePYINPluginAdapter.getDescriptor(); default: return 0; } }