Mercurial > hg > pyin
changeset 52:83ee5e6d1577
Win32 build stuff
author | Chris Cannam <chris.cannam@eecs.qmul.ac.uk> |
---|---|
date | Thu, 06 Mar 2014 15:45:36 +0000 |
parents | 1625cc4f4221 |
children | 71be7023e9d6 |
files | Yin.cpp win32-build/pyin.pro win32-build/vamp-plugin.map |
diffstat | 3 files changed, 188 insertions(+), 148 deletions(-) [+] |
line wrap: on
line diff
--- a/Yin.cpp Fri Dec 06 16:19:26 2013 +0000 +++ b/Yin.cpp Thu Mar 06 15:45:36 2014 +0000 @@ -1,148 +1,148 @@ -/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ - -/* - pYIN - A fundamental frequency estimator for monophonic audio - Centre for Digital Music, Queen Mary, University of London. - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. See the file - COPYING included with this distribution for more information. -*/ - -#include "Yin.h" - -#include "vamp-sdk/FFT.h" -#include "MeanFilter.h" -#include "YinUtil.h" - -#include <vector> -#include <cstdlib> -#include <cstdio> -#include <cmath> -#include <complex> - -using std::vector; - -Yin::Yin(size_t frameSize, size_t inputSampleRate, double thresh) : - m_frameSize(frameSize), - m_inputSampleRate(inputSampleRate), - m_thresh(thresh), - m_threshDistr(2), - m_yinBufferSize(frameSize/2) -{ - if (frameSize & (frameSize-1)) { - throw "N must be a power of two"; - } -} - -Yin::~Yin() -{ -} - -Yin::YinOutput -Yin::process(const double *in) const { - - double* yinBuffer = new double[m_yinBufferSize]; - - // calculate aperiodicity function for all periods - YinUtil::fastDifference(in, yinBuffer, m_yinBufferSize); - YinUtil::cumulativeDifference(yinBuffer, m_yinBufferSize); - - int tau = 0; - tau = YinUtil::absoluteThreshold(yinBuffer, m_yinBufferSize, m_thresh); - - double interpolatedTau; - double aperiodicity; - double f0; - - if (tau!=0) - { - interpolatedTau = YinUtil::parabolicInterpolation(yinBuffer, abs(tau), m_yinBufferSize); - f0 = m_inputSampleRate * (1.0 / interpolatedTau); - } else { - interpolatedTau = 0; - f0 = 0; - } - double rms = std::sqrt(YinUtil::sumSquare(in, 0, m_yinBufferSize)/m_yinBufferSize); - aperiodicity = yinBuffer[abs(tau)]; - // std::cerr << aperiodicity << std::endl; - if (tau < 0) f0 = -f0; - - Yin::YinOutput yo(f0, 1-aperiodicity, rms); - for (size_t iBuf = 0; iBuf < m_yinBufferSize; ++iBuf) - { - yo.salience.push_back(yinBuffer[iBuf] < 1 ? 1-yinBuffer[iBuf] : 0); // why are the values sometimes < 0 if I don't check? - } - - delete [] yinBuffer; - return yo; -} - -Yin::YinOutput -Yin::processProbabilisticYin(const double *in) const { - - double* yinBuffer = new double[m_yinBufferSize]; - - // calculate aperiodicity function for all periods - YinUtil::fastDifference(in, yinBuffer, m_yinBufferSize); - YinUtil::cumulativeDifference(yinBuffer, m_yinBufferSize); - - vector<double> 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]; - } - - 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 = - m_inputSampleRate * (1.0 / - YinUtil::parabolicInterpolation(yinBuffer, iBuf, m_yinBufferSize)); - yo.freqProb.push_back(pair<double, double>(currentF0, peakProbability[iBuf])); - } - } - - // std::cerr << yo.freqProb.size() << std::endl; - - delete [] yinBuffer; - return yo; -} - - -int -Yin::setThreshold(double parameter) -{ - m_thresh = static_cast<float>(parameter); - return 0; -} - -int -Yin::setThresholdDistr(float parameter) -{ - m_threshDistr = static_cast<size_t>(parameter); - return 0; -} - -int -Yin::setFrameSize(size_t parameter) -{ - m_frameSize = parameter; - m_yinBufferSize = m_frameSize/2; - return 0; -} - -// int -// Yin::setRemoveUnvoiced(bool parameter) -// { -// m_removeUnvoiced = parameter; -// return 0; -// } +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + pYIN - A fundamental frequency estimator for monophonic audio + Centre for Digital Music, Queen Mary, University of London. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include "Yin.h" + +#include "vamp-sdk/FFT.h" +#include "MeanFilter.h" +#include "YinUtil.h" + +#include <vector> +#include <cstdlib> +#include <cstdio> +#include <cmath> +#include <complex> + +using std::vector; + +Yin::Yin(size_t frameSize, size_t inputSampleRate, double thresh) : + m_frameSize(frameSize), + m_inputSampleRate(inputSampleRate), + m_thresh(thresh), + m_threshDistr(2), + m_yinBufferSize(frameSize/2) +{ + if (frameSize & (frameSize-1)) { + // throw "N must be a power of two"; + } +} + +Yin::~Yin() +{ +} + +Yin::YinOutput +Yin::process(const double *in) const { + + double* yinBuffer = new double[m_yinBufferSize]; + + // calculate aperiodicity function for all periods + YinUtil::fastDifference(in, yinBuffer, m_yinBufferSize); + YinUtil::cumulativeDifference(yinBuffer, m_yinBufferSize); + + int tau = 0; + tau = YinUtil::absoluteThreshold(yinBuffer, m_yinBufferSize, m_thresh); + + double interpolatedTau; + double aperiodicity; + double f0; + + if (tau!=0) + { + interpolatedTau = YinUtil::parabolicInterpolation(yinBuffer, abs(tau), m_yinBufferSize); + f0 = m_inputSampleRate * (1.0 / interpolatedTau); + } else { + interpolatedTau = 0; + f0 = 0; + } + double rms = std::sqrt(YinUtil::sumSquare(in, 0, m_yinBufferSize)/m_yinBufferSize); + aperiodicity = yinBuffer[abs(tau)]; + // std::cerr << aperiodicity << std::endl; + if (tau < 0) f0 = -f0; + + Yin::YinOutput yo(f0, 1-aperiodicity, rms); + for (size_t iBuf = 0; iBuf < m_yinBufferSize; ++iBuf) + { + yo.salience.push_back(yinBuffer[iBuf] < 1 ? 1-yinBuffer[iBuf] : 0); // why are the values sometimes < 0 if I don't check? + } + + delete [] yinBuffer; + return yo; +} + +Yin::YinOutput +Yin::processProbabilisticYin(const double *in) const { + + double* yinBuffer = new double[m_yinBufferSize]; + + // calculate aperiodicity function for all periods + YinUtil::fastDifference(in, yinBuffer, m_yinBufferSize); + YinUtil::cumulativeDifference(yinBuffer, m_yinBufferSize); + + vector<double> 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]; + } + + 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 = + m_inputSampleRate * (1.0 / + YinUtil::parabolicInterpolation(yinBuffer, iBuf, m_yinBufferSize)); + yo.freqProb.push_back(pair<double, double>(currentF0, peakProbability[iBuf])); + } + } + + // std::cerr << yo.freqProb.size() << std::endl; + + delete [] yinBuffer; + return yo; +} + + +int +Yin::setThreshold(double parameter) +{ + m_thresh = static_cast<float>(parameter); + return 0; +} + +int +Yin::setThresholdDistr(float parameter) +{ + m_threshDistr = static_cast<size_t>(parameter); + return 0; +} + +int +Yin::setFrameSize(size_t parameter) +{ + m_frameSize = parameter; + m_yinBufferSize = m_frameSize/2; + return 0; +} + +// int +// Yin::setRemoveUnvoiced(bool parameter) +// { +// m_removeUnvoiced = parameter; +// return 0; +// }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/win32-build/pyin.pro Thu Mar 06 15:45:36 2014 +0000 @@ -0,0 +1,36 @@ +TEMPLATE = lib + +INCLUDEPATH += ../../vamp-plugin-sdk/include ../../boost_1_54_0 +LIBS += ../../vamp-plugin-sdk/lib/libvamp-sdk.a -Wl,--version-script=../win32-build/vamp-plugin.map + +CONFIG -= qt +CONFIG += plugin release warn_on + +TARGET = pyin + +SOURCES += \ + ../YinUtil.cpp \ + ../Yin.cpp \ + ../VampYin.cpp \ + ../SparseHMM.cpp \ + ../PYIN.cpp \ + ../MonoPitchHMM.cpp \ + ../MonoPitch.cpp \ + ../MonoNoteParameters.cpp \ + ../MonoNoteHMM.cpp \ + ../MonoNote.cpp \ + ../libmain.cpp + +HEADERS += \ + ../YinUtil.h \ + ../Yin.h \ + ../VampYin.h \ + ../SparseHMM.h \ + ../PYIN.h \ + ../MonoPitchHMM.h \ + ../MonoPitch.h \ + ../MonoNoteParameters.h \ + ../MonoNoteHMM.h \ + ../MonoNote.h \ + ../MeanFilter.h +