13
0

NO-OP: remove trailing whitespace

This commit is contained in:
Robin Gareus 2019-09-03 04:52:01 +02:00
parent b340dc7282
commit 58ee66e924
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
25 changed files with 208 additions and 210 deletions

View File

@ -3,7 +3,7 @@
/*
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
@ -106,7 +106,7 @@ LocalCandidatePYIN::getPreferredBlockSize() const
return 2048;
}
size_t
size_t
LocalCandidatePYIN::getPreferredStepSize() const
{
return 256;
@ -128,7 +128,7 @@ LocalCandidatePYIN::ParameterList
LocalCandidatePYIN::getParameterDescriptors() const
{
ParameterList list;
ParameterDescriptor d;
d.identifier = "threshdistr";
@ -196,7 +196,7 @@ LocalCandidatePYIN::getParameter(string identifier) const
}
void
LocalCandidatePYIN::setParameter(string identifier, float value)
LocalCandidatePYIN::setParameter(string identifier, float value)
{
if (identifier == "threshdistr")
{
@ -268,7 +268,7 @@ LocalCandidatePYIN::initialise(size_t channels, size_t stepSize, size_t blockSiz
m_channels = channels;
m_stepSize = stepSize;
m_blockSize = blockSize;
reset();
return true;
@ -276,10 +276,10 @@ LocalCandidatePYIN::initialise(size_t channels, size_t stepSize, size_t blockSiz
void
LocalCandidatePYIN::reset()
{
{
m_pitchProb.clear();
m_timestamp.clear();
/*
/*
std::cerr << "LocalCandidatePYIN::reset"
<< ", blockSize = " << m_blockSize
<< std::endl;
@ -291,25 +291,25 @@ LocalCandidatePYIN::process(const float *const *inputBuffers, RealTime timestamp
{
int offset = m_preciseTime == 1.0 ? m_blockSize/2 : m_blockSize/4;
timestamp = timestamp + Vamp::RealTime::frame2RealTime(offset, lrintf(m_inputSampleRate));
double *dInputBuffers = new double[m_blockSize];
for (size_t i = 0; i < m_blockSize; ++i) dInputBuffers[i] = inputBuffers[0][i];
size_t yinBufferSize = m_blockSize/2;
double* yinBuffer = new double[yinBufferSize];
if (!m_preciseTime) YinUtil::fastDifference(dInputBuffers, yinBuffer, yinBufferSize);
else YinUtil::slowDifference(dInputBuffers, yinBuffer, yinBufferSize);
else YinUtil::slowDifference(dInputBuffers, yinBuffer, yinBufferSize);
delete [] dInputBuffers;
YinUtil::cumulativeDifference(yinBuffer, yinBufferSize);
float minFrequency = 60;
float maxFrequency = 900;
vector<double> peakProbability = YinUtil::yinProb(yinBuffer,
m_threshDistr,
yinBufferSize,
m_inputSampleRate/maxFrequency,
vector<double> peakProbability = YinUtil::yinProb(yinBuffer,
m_threshDistr,
yinBufferSize,
m_inputSampleRate/maxFrequency,
m_inputSampleRate/minFrequency);
vector<pair<double, double> > tempPitchProb;
@ -317,7 +317,7 @@ LocalCandidatePYIN::process(const float *const *inputBuffers, RealTime timestamp
{
if (peakProbability[iBuf] > 0)
{
double currentF0 =
double currentF0 =
m_inputSampleRate * (1.0 /
YinUtil::parabolicInterpolation(yinBuffer, iBuf, yinBufferSize));
double tempPitch = 12 * std::log(currentF0/440)/std::log(2.) + 69;
@ -351,10 +351,10 @@ LocalCandidatePYIN::getRemainingFeatures()
vector<float> freqSum = vector<float>(m_nCandidate);
vector<float> freqNumber = vector<float>(m_nCandidate);
vector<float> freqMean = vector<float>(m_nCandidate);
boost::math::normal normalDist(0, 8); // semitones sd
float maxNormalDist = boost::math::pdf(normalDist, 0);
// Viterbi-decode multiple times with different frequencies emphasised
for (size_t iCandidate = 0; iCandidate < m_nCandidate; ++iCandidate)
{
@ -369,8 +369,8 @@ LocalCandidatePYIN::getRemainingFeatures()
float prob = 0;
for (size_t iProb = 0; iProb < m_pitchProb[iFrame].size(); ++iProb)
{
pitch = m_pitchProb[iFrame][iProb].first;
prob = m_pitchProb[iFrame][iProb].second *
pitch = m_pitchProb[iFrame][iProb].first;
prob = m_pitchProb[iFrame][iProb].second *
boost::math::pdf(normalDist, pitch-centrePitch) /
maxNormalDist * 2;
sumProb += prob;
@ -404,13 +404,13 @@ LocalCandidatePYIN::getRemainingFeatures()
for (size_t iCandidate = 0; iCandidate < m_nCandidate; ++iCandidate) {
for (size_t jCandidate = iCandidate+1; jCandidate < m_nCandidate; ++jCandidate) {
size_t countEqual = 0;
for (size_t iFrame = 0; iFrame < nFrame; ++iFrame)
for (size_t iFrame = 0; iFrame < nFrame; ++iFrame)
{
if ((pitchTracks[jCandidate][iFrame] == 0 && pitchTracks[iCandidate][iFrame] == 0) ||
fabs(pitchTracks[iCandidate][iFrame]/pitchTracks[jCandidate][iFrame]-1)<0.01)
countEqual++;
}
// std::cerr << "proportion equal: " << (countEqual * 1.0 / nFrame) << std::endl;
// std::cerr << "proportion equal: " << (countEqual * 1.0 / nFrame) << std::endl;
if (countEqual * 1.0 / nFrame > 0.8) {
if (freqNumber[iCandidate] > freqNumber[jCandidate]) {
duplicates.push_back(jCandidate);
@ -433,7 +433,7 @@ LocalCandidatePYIN::getRemainingFeatures()
{
bool isDuplicate = false;
for (size_t i = 0; i < duplicates.size(); ++i) {
if (duplicates[i] == iCandidate) {
isDuplicate = true;
break;
@ -446,11 +446,11 @@ LocalCandidatePYIN::getRemainingFeatures()
candidateLabels[iCandidate] = convert.str();
candidateActuals[iCandidate] = actualCandidateNumber;
// std::cerr << iCandidate << " " << actualCandidateNumber << " " << freqNumber[iCandidate] << " " << freqMean[iCandidate] << std::endl;
for (size_t iFrame = 0; iFrame < nFrame; ++iFrame)
for (size_t iFrame = 0; iFrame < nFrame; ++iFrame)
{
if (pitchTracks[iCandidate][iFrame] > 0)
{
// featureValues[m_timestamp[iFrame]][iCandidate] =
// featureValues[m_timestamp[iFrame]][iCandidate] =
// pitchTracks[iCandidate][iFrame];
outputFrequencies[iFrame].push_back(pitchTracks[iCandidate][iFrame]);
} else {
@ -473,7 +473,7 @@ LocalCandidatePYIN::getRemainingFeatures()
f.values = outputFrequencies[iFrame];
fs[0].push_back(f);
}
// I stopped using Chris's map stuff below because I couldn't get my head around it
//
// for (map<RealTime, map<int, float> >::const_iterator i =
@ -482,7 +482,7 @@ LocalCandidatePYIN::getRemainingFeatures()
// f.hasTimestamp = true;
// f.timestamp = i->first;
// int nextCandidate = candidateActuals.begin()->second;
// for (map<int, float>::const_iterator j =
// for (map<int, float>::const_iterator j =
// i->second.begin(); j != i->second.end(); ++j) {
// while (candidateActuals[j->first] > nextCandidate) {
// f.values.push_back(0);

View File

@ -3,7 +3,7 @@
/*
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
@ -61,9 +61,9 @@ protected:
size_t m_blockSize;
float m_fmin;
float m_fmax;
mutable int m_oPitchTrackCandidates;
float m_threshDistr;
float m_outputUnvoiced;
float m_preciseTime;

View File

@ -3,7 +3,7 @@
/*
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

View File

@ -3,7 +3,7 @@
/*
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
@ -38,13 +38,13 @@ MonoNote::process(const vector<vector<pair<double, double> > > pitchProb)
{
obsProb.push_back(hmm.calculateObsProb(pitchProb[iFrame]));
}
vector<double> *scale = new vector<double>(pitchProb.size());
vector<MonoNote::FrameOutput> out;
vector<MonoNote::FrameOutput> out;
vector<int> path = hmm.decodeViterbi(obsProb, scale);
for (size_t iFrame = 0; iFrame < path.size(); ++iFrame)
{
double currPitch = -1;

View File

@ -3,7 +3,7 @@
/*
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
@ -28,7 +28,7 @@ class MonoNote {
public:
MonoNote();
virtual ~MonoNote();
struct FrameOutput {
size_t frameNumber;
double pitch;

View File

@ -3,7 +3,7 @@
/*
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
@ -31,9 +31,9 @@ const vector<double>
MonoNoteHMM::calculateObsProb(const vector<pair<double, double> > pitchProb)
{
// pitchProb is a list of pairs (pitches and their probabilities)
size_t nCandidate = pitchProb.size();
// what is the probability of pitched
double pIsPitched = 0;
for (size_t iCandidate = 0; iCandidate < nCandidate; ++iCandidate)
@ -68,8 +68,8 @@ MonoNoteHMM::calculateObsProb(const vector<pair<double, double> > pitchProb)
minDistCandidate = iCandidate;
}
}
tempProb = std::pow(minDistProb, par.yinTrust) *
boost::math::pdf(pitchDistr[i],
tempProb = std::pow(minDistProb, par.yinTrust) *
boost::math::pdf(pitchDistr[i],
pitchProb[minDistCandidate].first);
} else {
tempProb = 1;
@ -78,12 +78,12 @@ MonoNoteHMM::calculateObsProb(const vector<pair<double, double> > pitchProb)
out[i] = tempProb;
}
}
for (size_t i = 0; i < par.n; ++i)
{
if (i % par.nSPP != 2)
{
if (tempProbSum > 0)
if (tempProbSum > 0)
{
out[i] = out[i] / tempProbSum * pIsPitched;
}
@ -106,7 +106,7 @@ MonoNoteHMM::build()
// 3-5. second-lowest pitch
// 3. attack state
// ...
// observation distributions
for (size_t iState = 0; iState < par.n; ++iState)
{
@ -116,7 +116,7 @@ MonoNoteHMM::build()
// silent state starts tracking
init.push_back(1.0/(par.nS * par.nPPS));
} else {
init.push_back(0.0);
init.push_back(0.0);
}
}
@ -128,7 +128,7 @@ MonoNoteHMM::build()
pitchDistr[index+1] = boost::math::normal(mu, par.sigmaYinPitchStable);
pitchDistr[index+2] = boost::math::normal(mu, 1.0); // dummy
}
boost::math::normal noteDistanceDistr(0, par.sigma2Note);
for (size_t iPitch = 0; iPitch < (par.nS * par.nPPS); ++iPitch)
@ -149,7 +149,7 @@ MonoNoteHMM::build()
from.push_back(index+1);
to.push_back(index+1); // to itself
transProb.push_back(par.pStableSelftrans);
from.push_back(index+1);
to.push_back(index+2); // to silent
transProb.push_back(par.pStable2Silent);
@ -158,8 +158,7 @@ MonoNoteHMM::build()
from.push_back(index+2);
to.push_back(index+2);
transProb.push_back(par.pSilentSelftrans);
// the more complicated transitions from the silent
double probSumSilent = 0;
@ -168,17 +167,17 @@ MonoNoteHMM::build()
{
int fromPitch = iPitch;
int toPitch = jPitch;
double semitoneDistance =
double semitoneDistance =
std::abs(fromPitch - toPitch) * 1.0 / par.nPPS;
// if (std::fmod(semitoneDistance, 1) == 0 && semitoneDistance > par.minSemitoneDistance)
if (semitoneDistance == 0 ||
(semitoneDistance > par.minSemitoneDistance
if (semitoneDistance == 0 ||
(semitoneDistance > par.minSemitoneDistance
&& semitoneDistance < par.maxJump))
{
size_t toIndex = jPitch * par.nSPP; // note attack index
double tempWeightSilent = boost::math::pdf(noteDistanceDistr,
double tempWeightSilent = boost::math::pdf(noteDistanceDistr,
semitoneDistance);
probSumSilent += tempWeightSilent;

View File

@ -3,7 +3,7 @@
/*
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

View File

@ -3,7 +3,7 @@
/*
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
@ -14,23 +14,23 @@
#include "MonoNoteParameters.h"
MonoNoteParameters::MonoNoteParameters() :
minPitch(35),
nPPS(3),
nS(69),
minPitch(35),
nPPS(3),
nS(69),
nSPP(3), // states per pitch
n(0),
initPi(0),
initPi(0),
pAttackSelftrans(0.9),
pStableSelftrans(0.99),
pStable2Silent(0.01),
pSilentSelftrans(0.9999),
pSilentSelftrans(0.9999),
sigma2Note(0.7),
maxJump(13),
pInterSelftrans(0.0),
priorPitchedProb(.7),
priorWeight(0.5),
minSemitoneDistance(.5),
sigmaYinPitchAttack(5),
sigmaYinPitchAttack(5),
sigmaYinPitchStable(0.8),
sigmaYinPitchInter(.1),
yinTrust(0.1)

View File

@ -3,7 +3,7 @@
/*
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
@ -25,17 +25,17 @@ class MonoNoteParameters
public:
MonoNoteParameters();
virtual ~MonoNoteParameters();
// model architecture parameters
size_t minPitch; // lowest pitch in MIDI notes
size_t nPPS; // number of pitches per semitone
size_t nS; // number of semitones
size_t nSPP; // number of states per pitch
size_t n; // number of states (will be calcualted from other parameters)
// initial state probabilities
vector<double> initPi;
vector<double> initPi;
// transition parameters
double pAttackSelftrans;
double pStableSelftrans;
@ -44,18 +44,17 @@ public:
double sigma2Note; // standard deviation of next note Gaussian distribution
double maxJump;
double pInterSelftrans;
double priorPitchedProb;
double priorWeight;
double minSemitoneDistance; // minimum distance for a transition
double sigmaYinPitchAttack;
double sigmaYinPitchStable;
double sigmaYinPitchInter;
double yinTrust;
};
#endif

View File

@ -3,7 +3,7 @@
/*
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
@ -40,15 +40,15 @@ MonoPitch::process(const vector<vector<pair<double, double> > > pitchProb)
{
obsProb.push_back(hmm.calculateObsProb(pitchProb[iFrame]));
}
vector<double> *scale = new vector<double>(0);
vector<float> out;
vector<float> out;
// std::cerr << "before Viterbi decoding" << obsProb.size() << "ng" << obsProb[1].size() << std::endl;
vector<int> path = hmm.decodeViterbi(obsProb, scale);
// std::cerr << "after Viterbi decoding" << std::endl;
for (size_t iFrame = 0; iFrame < path.size(); ++iFrame)
{
// std::cerr << path[iFrame] << " " << hmm.m_freqs[path[iFrame]] << std::endl;

View File

@ -3,7 +3,7 @@
/*
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
@ -27,7 +27,7 @@ class MonoPitch {
public:
MonoPitch();
virtual ~MonoPitch();
// pitchProb is a frame-wise vector carrying a vector of pitch-probability pairs
const vector<float> process(const vector<vector<pair<double, double> > > pitchProb);
private:

View File

@ -3,7 +3,7 @@
/*
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
@ -66,7 +66,7 @@ MonoPitchHMM::calculateObsProb(const vector<pair<double, double> > pitchProb)
oldd = d;
}
}
double probReallyPitched = m_yinTrust * probYinPitched;
// std::cerr << probReallyPitched << " " << probYinPitched << std::endl;
// damn, I forget what this is all about...
@ -84,14 +84,14 @@ MonoPitchHMM::build()
{
// INITIAL VECTOR
init = vector<double>(2*m_nPitch, 1.0 / 2*m_nPitch);
// TRANSITIONS
for (size_t iPitch = 0; iPitch < m_nPitch; ++iPitch)
{
int theoreticalMinNextPitch = static_cast<int>(iPitch)-static_cast<int>(m_transitionWidth/2);
int minNextPitch = iPitch>m_transitionWidth/2 ? iPitch-m_transitionWidth/2 : 0;
int maxNextPitch = iPitch<m_nPitch-m_transitionWidth/2 ? iPitch+m_transitionWidth/2 : m_nPitch-1;
// WEIGHT VECTOR
double weightSum = 0;
vector<double> weights;
@ -107,7 +107,7 @@ MonoPitchHMM::build()
}
weightSum += weights[weights.size()-1];
}
// std::cerr << minNextPitch << " " << maxNextPitch << std::endl;
// TRANSITIONS TO CLOSE PITCH
for (size_t i = minNextPitch; i <= maxNextPitch; ++i)
@ -124,7 +124,7 @@ MonoPitchHMM::build()
to.push_back(i+m_nPitch);
transProb.push_back(weights[i-minNextPitch] / weightSum * m_selfTrans);
// transProb.push_back(weights[i-minNextPitch] / weightSum * 0.5);
from.push_back(iPitch+m_nPitch);
to.push_back(i);
transProb.push_back(weights[i-minNextPitch] / weightSum * (1-m_selfTrans));
@ -135,7 +135,7 @@ MonoPitchHMM::build()
// from.push_back(iPitch+m_nPitch);
// to.push_back(2*m_nPitch);
// transProb.push_back(1-m_selfTrans);
// TRANSITION FROM UNVOICED TO PITCH
// from.push_back(2*m_nPitch);
// to.push_back(iPitch+m_nPitch);
@ -145,9 +145,9 @@ MonoPitchHMM::build()
// from.push_back(2*m_nPitch);
// to.push_back(2*m_nPitch);
// transProb.push_back(m_selfTrans);
// for (size_t i = 0; i < from.size(); ++i) {
// std::cerr << "P(["<< from[i] << " --> " << to[i] << "]) = " << transProb[i] << std::endl;
// }
}

View File

@ -3,7 +3,7 @@
/*
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

View File

@ -3,7 +3,7 @@
/*
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
@ -109,7 +109,7 @@ PYinVamp::getPreferredBlockSize() const
return 2048;
}
size_t
size_t
PYinVamp::getPreferredStepSize() const
{
return 256;
@ -131,7 +131,7 @@ PYinVamp::ParameterList
PYinVamp::getParameterDescriptors() const
{
ParameterList list;
ParameterDescriptor d;
d.identifier = "threshdistr";
@ -241,7 +241,7 @@ PYinVamp::getParameter(string identifier) const
}
void
PYinVamp::setParameter(string identifier, float value)
PYinVamp::setParameter(string identifier, float value)
{
if (identifier == "threshdistr")
{
@ -293,7 +293,7 @@ PYinVamp::getOutputDescriptors() const
OutputList outputs;
OutputDescriptor d;
int outputNumber = 0;
d.identifier = "f0candidates";
@ -327,7 +327,7 @@ PYinVamp::getOutputDescriptors() const
d.hasDuration = false;
outputs.push_back(d);
m_oF0Probs = outputNumber++;
d.identifier = "voicedprob";
d.name = "Voiced Probability";
d.description = "Probability that the signal is voiced according to Probabilistic Yin.";
@ -358,7 +358,7 @@ PYinVamp::getOutputDescriptors() const
d.hasDuration = false;
outputs.push_back(d);
m_oCandidateSalience = outputNumber++;
d.identifier = "smoothedpitchtrack";
d.name = "Smoothed Pitch Track";
d.description = ".";
@ -407,7 +407,7 @@ PYinVamp::initialise(size_t channels, size_t stepSize, size_t blockSize)
m_channels = channels;
m_stepSize = stepSize;
m_blockSize = blockSize;
reset();
return true;
@ -415,15 +415,15 @@ PYinVamp::initialise(size_t channels, size_t stepSize, size_t blockSize)
void
PYinVamp::reset()
{
{
m_yin.setThresholdDistr(m_threshDistr);
m_yin.setFrameSize(m_blockSize);
m_yin.setFast(!m_preciseTime);
m_pitchProb.clear();
m_timestamp.clear();
m_level.clear();
/*
/*
std::cerr << "PYinVamp::reset"
<< ", blockSize = " << m_blockSize
<< std::endl;
@ -437,9 +437,9 @@ PYinVamp::process(const float *const *inputBuffers, RealTime timestamp)
timestamp = timestamp + Vamp::RealTime::frame2RealTime(offset, lrintf(m_inputSampleRate));
FeatureSet fs;
float rms = 0;
double *dInputBuffers = new double[m_blockSize];
for (size_t i = 0; i < m_blockSize; ++i) {
dInputBuffers[i] = inputBuffers[0][i];
@ -447,15 +447,15 @@ PYinVamp::process(const float *const *inputBuffers, RealTime timestamp)
}
rms /= m_blockSize;
rms = sqrt(rms);
bool isLowAmplitude = (rms < m_lowAmp);
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
// 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;
for (size_t iCandidate = 0; iCandidate < yo.freqProb.size(); ++iCandidate)
@ -483,7 +483,7 @@ PYinVamp::process(const float *const *inputBuffers, RealTime timestamp)
f.values.push_back(yo.freqProb[i].first);
}
fs[m_oF0Candidates].push_back(f);
// VOICEDPROB
f.values.clear();
float voicedProb = 0;
@ -493,7 +493,7 @@ PYinVamp::process(const float *const *inputBuffers, RealTime timestamp)
voicedProb += yo.freqProb[i].second;
}
fs[m_oF0Probs].push_back(f);
f.values.push_back(voicedProb);
fs[m_oVoicedProb].push_back(f);
@ -517,7 +517,7 @@ PYinVamp::getRemainingFeatures()
Feature f;
f.hasTimestamp = true;
f.hasDuration = false;
if (m_pitchProb.empty()) {
return fs;
}
@ -536,10 +536,10 @@ PYinVamp::getRemainingFeatures()
} else {
f.values.push_back(mpOut[iFrame]);
}
fs[m_oSmoothedPitchTrack].push_back(f);
}
// MONO-NOTE STUFF
// std::cerr << "Mono Note Stuff" << std::endl;
MonoNote mn;
@ -555,19 +555,19 @@ PYinVamp::getRemainingFeatures()
}
// vector<MonoNote::FrameOutput> mnOut = mn.process(m_pitchProb);
vector<MonoNote::FrameOutput> mnOut = mn.process(smoothedPitch);
// turning feature into a note feature
f.hasTimestamp = true;
f.hasDuration = true;
f.values.clear();
int onsetFrame = 0;
bool isVoiced = 0;
bool oldIsVoiced = 0;
size_t nFrame = m_pitchProb.size();
float minNoteFrames = (m_inputSampleRate*m_pruneThresh) / m_stepSize;
std::vector<float> notePitchTrack; // collects pitches for one note at a time
for (size_t iFrame = 0; iFrame < nFrame; ++iFrame)
{

View File

@ -3,7 +3,7 @@
/*
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
@ -62,7 +62,7 @@ protected:
float m_fmin;
float m_fmax;
Yin m_yin;
mutable int m_oF0Candidates;
mutable int m_oF0Probs;
mutable int m_oVoicedProb;

2
libs/vamp-pyin/README Normal file
View File

@ -0,0 +1,2 @@
https://code.soundsoftware.ac.uk/projects/pyin
https://code.soundsoftware.ac.uk/attachments/download/1458/pyin-v1.1.tar.gz

View File

@ -3,7 +3,7 @@
/*
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
@ -26,9 +26,9 @@ SparseHMM::calculateObsProb(const vector<pair<double, double> > data)
return(vector<double>());
}
const std::vector<int>
const std::vector<int>
SparseHMM::decodeViterbi(std::vector<vector<double> > obsProb,
vector<double> *scale)
vector<double> *scale)
{
if (obsProb.size() < 1) {
return vector<int>();
@ -36,10 +36,10 @@ SparseHMM::decodeViterbi(std::vector<vector<double> > obsProb,
size_t nState = init.size();
size_t nFrame = obsProb.size();
// check for consistency
// check for consistency
size_t nTrans = transProb.size();
// declaring variables
std::vector<double> delta = std::vector<double>(nState);
std::vector<double> oldDelta = std::vector<double>(nState);
@ -76,22 +76,22 @@ SparseHMM::decodeViterbi(std::vector<vector<double> > obsProb,
size_t toState;
double currentTransProb;
double currentValue;
// this is the "sparse" loop
for (size_t iTrans = 0; iTrans < nTrans; ++iTrans)
{
fromState = from[iTrans];
toState = to[iTrans];
currentTransProb = transProb[iTrans];
currentValue = oldDelta[fromState] * currentTransProb;
if (currentValue > delta[toState])
{
delta[toState] = currentValue; // will be multiplied by the right obs later!
psi[iFrame][toState] = fromState;
}
}
}
for (size_t jState = 0; jState < nState; ++jState)
{
delta[jState] *= obsProb[iFrame][jState];
@ -125,7 +125,7 @@ SparseHMM::decodeViterbi(std::vector<vector<double> > obsProb,
double currentValue = oldDelta[iState];
if (currentValue > bestValue)
{
bestValue = currentValue;
bestValue = currentValue;
path[nFrame-1] = iState;
}
}
@ -135,11 +135,11 @@ SparseHMM::decodeViterbi(std::vector<vector<double> > obsProb,
{
path[iFrame] = psi[iFrame+1][path[iFrame+1]];
}
// for (size_t iState = 0; iState < nState; ++iState)
// {
// // std::cerr << psi[2][iState] << std::endl;
// }
return path;
}

View File

@ -3,7 +3,7 @@
/*
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
@ -24,7 +24,7 @@ class SparseHMM
{
public:
virtual const std::vector<double> calculateObsProb(const vector<pair<double, double> >);
const std::vector<int> decodeViterbi(std::vector<vector<double> > obs,
const std::vector<int> decodeViterbi(std::vector<vector<double> > obs,
vector<double> *scale);
vector<double> init;
vector<size_t> from;

View File

@ -3,7 +3,7 @@
/*
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
@ -25,7 +25,7 @@
using std::vector;
Yin::Yin(size_t frameSize, size_t inputSampleRate, double thresh, bool fast) :
Yin::Yin(size_t frameSize, size_t inputSampleRate, double thresh, bool fast) :
m_frameSize(frameSize),
m_inputSampleRate(inputSampleRate),
m_thresh(thresh),
@ -38,13 +38,13 @@ Yin::Yin(size_t frameSize, size_t inputSampleRate, double thresh, bool fast) :
}
}
Yin::~Yin()
Yin::~Yin()
{
}
Yin::YinOutput
Yin::process(const double *in) const {
double* yinBuffer = new double[m_yinBufferSize];
// calculate aperiodicity function for all periods
@ -55,11 +55,11 @@ Yin::process(const double *in) const {
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);
@ -78,14 +78,14 @@ Yin::process(const double *in) const {
{
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
@ -95,7 +95,7 @@ Yin::processProbabilisticYin(const double *in) const {
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)
@ -109,15 +109,15 @@ Yin::processProbabilisticYin(const double *in) const {
yo.salience.push_back(peakProbability[iBuf]);
if (peakProbability[iBuf] > 0)
{
double currentF0 =
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;
}

View File

@ -3,7 +3,7 @@
/*
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
@ -27,7 +27,6 @@ using std::vector;
using std::pair;
class Yin
{
public:
@ -40,16 +39,16 @@ public:
double rms;
vector<double> salience;
vector<pair<double, double> > freqProb;
YinOutput() : f0(0), periodicity(0), rms(0),
YinOutput() : f0(0), periodicity(0), rms(0),
salience(vector<double>(0)), freqProb(vector<pair<double, double> >(0)) { }
YinOutput(double _f, double _p, double _r) :
f0(_f), periodicity(_p), rms(_r),
f0(_f), periodicity(_p), rms(_r),
salience(vector<double>(0)), freqProb(vector<pair<double, double> >(0)) { }
YinOutput(double _f, double _p, double _r, vector<double> _salience) :
f0(_f), periodicity(_p), rms(_r), salience(_salience),
f0(_f), periodicity(_p), rms(_r), salience(_salience),
freqProb(vector<pair<double, double> >(0)) { }
};
int setThreshold(double parameter);
int setThresholdDistr(float parameter);
int setFrameSize(size_t frameSize);

View File

@ -3,7 +3,7 @@
/*
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
@ -21,8 +21,8 @@
#include <boost/math/distributions.hpp>
void
YinUtil::slowDifference(const double *in, double *yinBuffer, const size_t yinBufferSize)
void
YinUtil::slowDifference(const double *in, double *yinBuffer, const size_t yinBufferSize)
{
yinBuffer[0] = 0;
double delta ;
@ -36,19 +36,19 @@ YinUtil::slowDifference(const double *in, double *yinBuffer, const size_t yinBuf
delta = in[i+j] - in[j];
yinBuffer[i] += delta * delta;
}
}
}
}
void
YinUtil::fastDifference(const double *in, double *yinBuffer, const size_t yinBufferSize)
void
YinUtil::fastDifference(const double *in, double *yinBuffer, const size_t yinBufferSize)
{
// DECLARE AND INITIALISE
// initialisation of most of the arrays here was done in a separate function,
// with all the arrays as members of the class... moved them back here.
size_t frameSize = 2 * yinBufferSize;
double *audioTransformedReal = new double[frameSize];
double *audioTransformedImag = new double[frameSize];
double *nullImag = new double[frameSize];
@ -58,13 +58,13 @@ YinUtil::fastDifference(const double *in, double *yinBuffer, const size_t yinBuf
double *yinStyleACFReal = new double[frameSize];
double *yinStyleACFImag = new double[frameSize];
double *powerTerms = new double[yinBufferSize];
for (size_t j = 0; j < yinBufferSize; ++j)
{
yinBuffer[j] = 0.; // set to zero
powerTerms[j] = 0.; // set to zero
}
for (size_t j = 0; j < frameSize; ++j)
{
nullImag[j] = 0.;
@ -76,7 +76,7 @@ YinUtil::fastDifference(const double *in, double *yinBuffer, const size_t yinBuf
yinStyleACFReal[j] = 0.;
yinStyleACFImag[j] = 0.;
}
// POWER TERM CALCULATION
// ... for the power terms in equation (7) in the Yin paper
powerTerms[0] = 0.0;
@ -86,13 +86,13 @@ YinUtil::fastDifference(const double *in, double *yinBuffer, const size_t yinBuf
// now iteratively calculate all others (saves a few multiplications)
for (size_t tau = 1; tau < yinBufferSize; ++tau) {
powerTerms[tau] = powerTerms[tau-1] - in[tau-1] * in[tau-1] + in[tau+yinBufferSize] * in[tau+yinBufferSize];
powerTerms[tau] = powerTerms[tau-1] - in[tau-1] * in[tau-1] + in[tau+yinBufferSize] * in[tau+yinBufferSize];
}
// YIN-STYLE AUTOCORRELATION via FFT
// 1. data
Vamp::FFT::forward(frameSize, in, nullImag, audioTransformedReal, audioTransformedImag);
// 2. half of the data, disguised as a convolution kernel
for (size_t j = 0; j < yinBufferSize; ++j) {
kernel[j] = in[yinBufferSize-1-j];
@ -105,7 +105,7 @@ YinUtil::fastDifference(const double *in, double *yinBuffer, const size_t yinBuf
yinStyleACFImag[j] = audioTransformedReal[j]*kernelTransformedImag[j] + audioTransformedImag[j]*kernelTransformedReal[j]; // imaginary
}
Vamp::FFT::inverse(frameSize, yinStyleACFReal, yinStyleACFImag, audioTransformedReal, audioTransformedImag);
// CALCULATION OF difference function
// ... according to (7) in the Yin paper.
for (size_t j = 0; j < yinBufferSize; ++j) {
@ -123,15 +123,15 @@ YinUtil::fastDifference(const double *in, double *yinBuffer, const size_t yinBuf
delete [] powerTerms;
}
void
void
YinUtil::cumulativeDifference(double *yinBuffer, const size_t yinBufferSize)
{
{
size_t tau;
yinBuffer[0] = 1;
double runningSum = 0;
for (tau = 1; tau < yinBufferSize; ++tau) {
runningSum += yinBuffer[tau];
if (runningSum == 0)
@ -140,16 +140,16 @@ YinUtil::cumulativeDifference(double *yinBuffer, const size_t yinBufferSize)
} else {
yinBuffer[tau] *= tau / runningSum;
}
}
}
}
int
int
YinUtil::absoluteThreshold(const double *yinBuffer, const size_t yinBufferSize, const double thresh)
{
size_t tau;
size_t minTau = 0;
double minVal = 1000.;
// using Joren Six's "loop construct" from TarsosDSP
tau = 2;
while (tau < yinBufferSize)
@ -187,7 +187,7 @@ static float single15[100] = {0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.
static float single20[100] = {0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,1.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000,0.00000};
std::vector<double>
YinUtil::yinProb(const double *yinBuffer, const size_t prior, const size_t yinBufferSize, const size_t minTau0, const size_t maxTau0)
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;
@ -201,10 +201,10 @@ YinUtil::yinProb(const double *yinBuffer, const size_t prior, const size_t yinBu
std::vector<float> thresholds;
std::vector<float> distribution;
std::vector<double> peakProb = std::vector<double>(yinBufferSize);
size_t nThreshold = 100;
int nThresholdInt = nThreshold;
for (int i = 0; i < nThresholdInt; ++i)
{
switch (prior) {
@ -237,11 +237,10 @@ YinUtil::yinProb(const double *yinBuffer, const size_t prior, const size_t yinBu
}
thresholds.push_back(0.01 + i*0.01);
}
int currThreshInd = nThreshold-1;
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;
@ -270,7 +269,7 @@ YinUtil::yinProb(const double *yinBuffer, const size_t prior, const size_t yinBu
// {
// nonPeakProb -= peakProb[i];
// }
//
//
// std::cerr << tau << " " << currThreshInd << " "<< thresholds[currThreshInd] << " " << distribution[currThreshInd] << std::endl;
float sumProb = 0;
while (tau+1 < maxTau)
@ -300,12 +299,12 @@ YinUtil::yinProb(const double *yinBuffer, const size_t prior, const size_t yinBu
tau++;
}
}
if (peakProb[minInd] > 1) {
std::cerr << "WARNING: yin has prob > 1 ??? I'm returning all zeros instead." << std::endl;
return(std::vector<double>(yinBufferSize));
}
double nonPeakProb = 1;
if (sumProb > 0) {
for (size_t i = minTau; i < maxTau; ++i)
@ -316,33 +315,33 @@ YinUtil::yinProb(const double *yinBuffer, const size_t prior, const size_t yinBu
}
if (minInd > 0)
{
// std::cerr << "min set " << minVal << " " << minInd << " " << nonPeakProb << std::endl;
// std::cerr << "min set " << minVal << " " << minInd << " " << nonPeakProb << std::endl;
peakProb[minInd] += nonPeakProb * minWeight;
}
return peakProb;
}
double
YinUtil::parabolicInterpolation(const double *yinBuffer, const size_t tau, const size_t yinBufferSize)
YinUtil::parabolicInterpolation(const double *yinBuffer, const size_t tau, const size_t yinBufferSize)
{
// this is taken almost literally from Joren Six's Java implementation
if (tau == yinBufferSize) // not valid anyway.
{
return static_cast<double>(tau);
}
double betterTau = 0.0;
if (tau > 0 && tau < yinBufferSize-1) {
float s0, s1, s2;
s0 = yinBuffer[tau-1];
s1 = yinBuffer[tau];
s2 = yinBuffer[tau+1];
double adjustment = (s2 - s0) / (2 * (2 * s1 - s2 - s0));
if (abs(adjustment)>1) adjustment = 0;
betterTau = tau + adjustment;
} else {
// std::cerr << "WARNING: can't do interpolation at the edge (tau = " << tau << "), will return un-interpolated value.\n";
@ -351,7 +350,7 @@ YinUtil::parabolicInterpolation(const double *yinBuffer, const size_t tau, const
return betterTau;
}
double
double
YinUtil::sumSquare(const double *in, const size_t start, const size_t end)
{
double out = 0;

View File

@ -3,7 +3,7 @@
/*
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

View File

@ -3,7 +3,7 @@
/*
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
@ -99,7 +99,7 @@ YinVamp::getPreferredBlockSize() const
return 2048;
}
size_t
size_t
YinVamp::getPreferredStepSize() const
{
return 256;
@ -121,7 +121,7 @@ YinVamp::ParameterList
YinVamp::getParameterDescriptors() const
{
ParameterList list;
ParameterDescriptor d;
d.identifier = "yinThreshold";
d.name = "Yin threshold";
@ -132,7 +132,7 @@ YinVamp::getParameterDescriptors() const
d.defaultValue = 0.15f;
d.isQuantized = true;
d.quantizeStep = 0.025f;
list.push_back(d);
d.identifier = "outputunvoiced";
@ -166,7 +166,7 @@ YinVamp::getParameter(string identifier) const
}
void
YinVamp::setParameter(string identifier, float value)
YinVamp::setParameter(string identifier, float value)
{
if (identifier == "yinThreshold")
{
@ -202,7 +202,7 @@ YinVamp::getOutputDescriptors() const
OutputList outputs;
OutputDescriptor d;
int outputNumber = 0;
d.identifier = "f0";
@ -285,7 +285,7 @@ YinVamp::initialise(size_t channels, size_t stepSize, size_t blockSize)
m_channels = channels;
m_stepSize = stepSize;
m_blockSize = blockSize;
reset();
return true;
@ -293,10 +293,10 @@ YinVamp::initialise(size_t channels, size_t stepSize, size_t blockSize)
void
YinVamp::reset()
{
{
m_yin.setThreshold(m_yinParameter);
m_yin.setFrameSize(m_blockSize);
/*
/*
std::cerr << "YinVamp::reset: yin threshold set to " << (m_yinParameter)
<< ", blockSize = " << m_blockSize
<< std::endl;
@ -308,10 +308,10 @@ YinVamp::process(const float *const *inputBuffers, RealTime timestamp)
{
timestamp = timestamp + Vamp::RealTime::frame2RealTime(m_blockSize/2, lrintf(m_inputSampleRate));
FeatureSet fs;
double *dInputBuffers = new double[m_blockSize];
for (size_t i = 0; i < m_blockSize; ++i) dInputBuffers[i] = inputBuffers[0][i];
Yin::YinOutput yo = m_yin.process(dInputBuffers);
// std::cerr << "f0 in YinVamp: " << yo.f0 << std::endl;
Feature f;
@ -341,19 +341,19 @@ YinVamp::process(const float *const *inputBuffers, RealTime timestamp)
f.values.clear();
f.values.push_back(yo.rms);
fs[m_outNoRms].push_back(f);
f.values.clear();
for (size_t iBin = 0; iBin < yo.salience.size(); ++iBin)
{
f.values.push_back(yo.salience[iBin]);
}
fs[m_outNoSalience].push_back(f);
f.values.clear();
// f.values[0] = yo.periodicity;
f.values.push_back(yo.periodicity);
fs[m_outNoPeriodicity].push_back(f);
delete [] dInputBuffers;
return fs;

View File

@ -3,7 +3,7 @@
/*
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
@ -62,7 +62,7 @@ protected:
float m_fmin;
float m_fmax;
Yin m_yin;
mutable int m_outNoF0;
mutable int m_outNoPeriodicity;
mutable int m_outNoRms;

View File

@ -3,7 +3,7 @@
/*
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