NO-OP: remove trailing whitespace
This commit is contained in:
parent
b340dc7282
commit
58ee66e924
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
@ -106,7 +106,7 @@ LocalCandidatePYIN::getPreferredBlockSize() const
|
|||||||
return 2048;
|
return 2048;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
LocalCandidatePYIN::getPreferredStepSize() const
|
LocalCandidatePYIN::getPreferredStepSize() const
|
||||||
{
|
{
|
||||||
return 256;
|
return 256;
|
||||||
@ -128,7 +128,7 @@ LocalCandidatePYIN::ParameterList
|
|||||||
LocalCandidatePYIN::getParameterDescriptors() const
|
LocalCandidatePYIN::getParameterDescriptors() const
|
||||||
{
|
{
|
||||||
ParameterList list;
|
ParameterList list;
|
||||||
|
|
||||||
ParameterDescriptor d;
|
ParameterDescriptor d;
|
||||||
|
|
||||||
d.identifier = "threshdistr";
|
d.identifier = "threshdistr";
|
||||||
@ -196,7 +196,7 @@ LocalCandidatePYIN::getParameter(string identifier) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
LocalCandidatePYIN::setParameter(string identifier, float value)
|
LocalCandidatePYIN::setParameter(string identifier, float value)
|
||||||
{
|
{
|
||||||
if (identifier == "threshdistr")
|
if (identifier == "threshdistr")
|
||||||
{
|
{
|
||||||
@ -268,7 +268,7 @@ LocalCandidatePYIN::initialise(size_t channels, size_t stepSize, size_t blockSiz
|
|||||||
m_channels = channels;
|
m_channels = channels;
|
||||||
m_stepSize = stepSize;
|
m_stepSize = stepSize;
|
||||||
m_blockSize = blockSize;
|
m_blockSize = blockSize;
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -276,10 +276,10 @@ LocalCandidatePYIN::initialise(size_t channels, size_t stepSize, size_t blockSiz
|
|||||||
|
|
||||||
void
|
void
|
||||||
LocalCandidatePYIN::reset()
|
LocalCandidatePYIN::reset()
|
||||||
{
|
{
|
||||||
m_pitchProb.clear();
|
m_pitchProb.clear();
|
||||||
m_timestamp.clear();
|
m_timestamp.clear();
|
||||||
/*
|
/*
|
||||||
std::cerr << "LocalCandidatePYIN::reset"
|
std::cerr << "LocalCandidatePYIN::reset"
|
||||||
<< ", blockSize = " << m_blockSize
|
<< ", blockSize = " << m_blockSize
|
||||||
<< std::endl;
|
<< 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;
|
int offset = m_preciseTime == 1.0 ? m_blockSize/2 : m_blockSize/4;
|
||||||
timestamp = timestamp + Vamp::RealTime::frame2RealTime(offset, lrintf(m_inputSampleRate));
|
timestamp = timestamp + Vamp::RealTime::frame2RealTime(offset, lrintf(m_inputSampleRate));
|
||||||
|
|
||||||
double *dInputBuffers = new double[m_blockSize];
|
double *dInputBuffers = new double[m_blockSize];
|
||||||
for (size_t i = 0; i < m_blockSize; ++i) dInputBuffers[i] = inputBuffers[0][i];
|
for (size_t i = 0; i < m_blockSize; ++i) dInputBuffers[i] = inputBuffers[0][i];
|
||||||
|
|
||||||
size_t yinBufferSize = m_blockSize/2;
|
size_t yinBufferSize = m_blockSize/2;
|
||||||
double* yinBuffer = new double[yinBufferSize];
|
double* yinBuffer = new double[yinBufferSize];
|
||||||
if (!m_preciseTime) YinUtil::fastDifference(dInputBuffers, yinBuffer, yinBufferSize);
|
if (!m_preciseTime) YinUtil::fastDifference(dInputBuffers, yinBuffer, yinBufferSize);
|
||||||
else YinUtil::slowDifference(dInputBuffers, yinBuffer, yinBufferSize);
|
else YinUtil::slowDifference(dInputBuffers, yinBuffer, yinBufferSize);
|
||||||
|
|
||||||
delete [] dInputBuffers;
|
delete [] dInputBuffers;
|
||||||
|
|
||||||
YinUtil::cumulativeDifference(yinBuffer, yinBufferSize);
|
YinUtil::cumulativeDifference(yinBuffer, yinBufferSize);
|
||||||
|
|
||||||
float minFrequency = 60;
|
float minFrequency = 60;
|
||||||
float maxFrequency = 900;
|
float maxFrequency = 900;
|
||||||
vector<double> peakProbability = YinUtil::yinProb(yinBuffer,
|
vector<double> peakProbability = YinUtil::yinProb(yinBuffer,
|
||||||
m_threshDistr,
|
m_threshDistr,
|
||||||
yinBufferSize,
|
yinBufferSize,
|
||||||
m_inputSampleRate/maxFrequency,
|
m_inputSampleRate/maxFrequency,
|
||||||
m_inputSampleRate/minFrequency);
|
m_inputSampleRate/minFrequency);
|
||||||
|
|
||||||
vector<pair<double, double> > tempPitchProb;
|
vector<pair<double, double> > tempPitchProb;
|
||||||
@ -317,7 +317,7 @@ LocalCandidatePYIN::process(const float *const *inputBuffers, RealTime timestamp
|
|||||||
{
|
{
|
||||||
if (peakProbability[iBuf] > 0)
|
if (peakProbability[iBuf] > 0)
|
||||||
{
|
{
|
||||||
double currentF0 =
|
double currentF0 =
|
||||||
m_inputSampleRate * (1.0 /
|
m_inputSampleRate * (1.0 /
|
||||||
YinUtil::parabolicInterpolation(yinBuffer, iBuf, yinBufferSize));
|
YinUtil::parabolicInterpolation(yinBuffer, iBuf, yinBufferSize));
|
||||||
double tempPitch = 12 * std::log(currentF0/440)/std::log(2.) + 69;
|
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> freqSum = vector<float>(m_nCandidate);
|
||||||
vector<float> freqNumber = vector<float>(m_nCandidate);
|
vector<float> freqNumber = vector<float>(m_nCandidate);
|
||||||
vector<float> freqMean = vector<float>(m_nCandidate);
|
vector<float> freqMean = vector<float>(m_nCandidate);
|
||||||
|
|
||||||
boost::math::normal normalDist(0, 8); // semitones sd
|
boost::math::normal normalDist(0, 8); // semitones sd
|
||||||
float maxNormalDist = boost::math::pdf(normalDist, 0);
|
float maxNormalDist = boost::math::pdf(normalDist, 0);
|
||||||
|
|
||||||
// Viterbi-decode multiple times with different frequencies emphasised
|
// Viterbi-decode multiple times with different frequencies emphasised
|
||||||
for (size_t iCandidate = 0; iCandidate < m_nCandidate; ++iCandidate)
|
for (size_t iCandidate = 0; iCandidate < m_nCandidate; ++iCandidate)
|
||||||
{
|
{
|
||||||
@ -369,8 +369,8 @@ LocalCandidatePYIN::getRemainingFeatures()
|
|||||||
float prob = 0;
|
float prob = 0;
|
||||||
for (size_t iProb = 0; iProb < m_pitchProb[iFrame].size(); ++iProb)
|
for (size_t iProb = 0; iProb < m_pitchProb[iFrame].size(); ++iProb)
|
||||||
{
|
{
|
||||||
pitch = m_pitchProb[iFrame][iProb].first;
|
pitch = m_pitchProb[iFrame][iProb].first;
|
||||||
prob = m_pitchProb[iFrame][iProb].second *
|
prob = m_pitchProb[iFrame][iProb].second *
|
||||||
boost::math::pdf(normalDist, pitch-centrePitch) /
|
boost::math::pdf(normalDist, pitch-centrePitch) /
|
||||||
maxNormalDist * 2;
|
maxNormalDist * 2;
|
||||||
sumProb += prob;
|
sumProb += prob;
|
||||||
@ -404,13 +404,13 @@ LocalCandidatePYIN::getRemainingFeatures()
|
|||||||
for (size_t iCandidate = 0; iCandidate < m_nCandidate; ++iCandidate) {
|
for (size_t iCandidate = 0; iCandidate < m_nCandidate; ++iCandidate) {
|
||||||
for (size_t jCandidate = iCandidate+1; jCandidate < m_nCandidate; ++jCandidate) {
|
for (size_t jCandidate = iCandidate+1; jCandidate < m_nCandidate; ++jCandidate) {
|
||||||
size_t countEqual = 0;
|
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) ||
|
if ((pitchTracks[jCandidate][iFrame] == 0 && pitchTracks[iCandidate][iFrame] == 0) ||
|
||||||
fabs(pitchTracks[iCandidate][iFrame]/pitchTracks[jCandidate][iFrame]-1)<0.01)
|
fabs(pitchTracks[iCandidate][iFrame]/pitchTracks[jCandidate][iFrame]-1)<0.01)
|
||||||
countEqual++;
|
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 (countEqual * 1.0 / nFrame > 0.8) {
|
||||||
if (freqNumber[iCandidate] > freqNumber[jCandidate]) {
|
if (freqNumber[iCandidate] > freqNumber[jCandidate]) {
|
||||||
duplicates.push_back(jCandidate);
|
duplicates.push_back(jCandidate);
|
||||||
@ -433,7 +433,7 @@ LocalCandidatePYIN::getRemainingFeatures()
|
|||||||
{
|
{
|
||||||
bool isDuplicate = false;
|
bool isDuplicate = false;
|
||||||
for (size_t i = 0; i < duplicates.size(); ++i) {
|
for (size_t i = 0; i < duplicates.size(); ++i) {
|
||||||
|
|
||||||
if (duplicates[i] == iCandidate) {
|
if (duplicates[i] == iCandidate) {
|
||||||
isDuplicate = true;
|
isDuplicate = true;
|
||||||
break;
|
break;
|
||||||
@ -446,11 +446,11 @@ LocalCandidatePYIN::getRemainingFeatures()
|
|||||||
candidateLabels[iCandidate] = convert.str();
|
candidateLabels[iCandidate] = convert.str();
|
||||||
candidateActuals[iCandidate] = actualCandidateNumber;
|
candidateActuals[iCandidate] = actualCandidateNumber;
|
||||||
// std::cerr << iCandidate << " " << actualCandidateNumber << " " << freqNumber[iCandidate] << " " << freqMean[iCandidate] << std::endl;
|
// 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)
|
if (pitchTracks[iCandidate][iFrame] > 0)
|
||||||
{
|
{
|
||||||
// featureValues[m_timestamp[iFrame]][iCandidate] =
|
// featureValues[m_timestamp[iFrame]][iCandidate] =
|
||||||
// pitchTracks[iCandidate][iFrame];
|
// pitchTracks[iCandidate][iFrame];
|
||||||
outputFrequencies[iFrame].push_back(pitchTracks[iCandidate][iFrame]);
|
outputFrequencies[iFrame].push_back(pitchTracks[iCandidate][iFrame]);
|
||||||
} else {
|
} else {
|
||||||
@ -473,7 +473,7 @@ LocalCandidatePYIN::getRemainingFeatures()
|
|||||||
f.values = outputFrequencies[iFrame];
|
f.values = outputFrequencies[iFrame];
|
||||||
fs[0].push_back(f);
|
fs[0].push_back(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// I stopped using Chris's map stuff below because I couldn't get my head around it
|
// 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 =
|
// for (map<RealTime, map<int, float> >::const_iterator i =
|
||||||
@ -482,7 +482,7 @@ LocalCandidatePYIN::getRemainingFeatures()
|
|||||||
// f.hasTimestamp = true;
|
// f.hasTimestamp = true;
|
||||||
// f.timestamp = i->first;
|
// f.timestamp = i->first;
|
||||||
// int nextCandidate = candidateActuals.begin()->second;
|
// 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) {
|
// i->second.begin(); j != i->second.end(); ++j) {
|
||||||
// while (candidateActuals[j->first] > nextCandidate) {
|
// while (candidateActuals[j->first] > nextCandidate) {
|
||||||
// f.values.push_back(0);
|
// f.values.push_back(0);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
@ -61,9 +61,9 @@ protected:
|
|||||||
size_t m_blockSize;
|
size_t m_blockSize;
|
||||||
float m_fmin;
|
float m_fmin;
|
||||||
float m_fmax;
|
float m_fmax;
|
||||||
|
|
||||||
mutable int m_oPitchTrackCandidates;
|
mutable int m_oPitchTrackCandidates;
|
||||||
|
|
||||||
float m_threshDistr;
|
float m_threshDistr;
|
||||||
float m_outputUnvoiced;
|
float m_outputUnvoiced;
|
||||||
float m_preciseTime;
|
float m_preciseTime;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
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]));
|
obsProb.push_back(hmm.calculateObsProb(pitchProb[iFrame]));
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<double> *scale = new vector<double>(pitchProb.size());
|
vector<double> *scale = new vector<double>(pitchProb.size());
|
||||||
|
|
||||||
vector<MonoNote::FrameOutput> out;
|
vector<MonoNote::FrameOutput> out;
|
||||||
|
|
||||||
vector<int> path = hmm.decodeViterbi(obsProb, scale);
|
vector<int> path = hmm.decodeViterbi(obsProb, scale);
|
||||||
|
|
||||||
for (size_t iFrame = 0; iFrame < path.size(); ++iFrame)
|
for (size_t iFrame = 0; iFrame < path.size(); ++iFrame)
|
||||||
{
|
{
|
||||||
double currPitch = -1;
|
double currPitch = -1;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
@ -28,7 +28,7 @@ class MonoNote {
|
|||||||
public:
|
public:
|
||||||
MonoNote();
|
MonoNote();
|
||||||
virtual ~MonoNote();
|
virtual ~MonoNote();
|
||||||
|
|
||||||
struct FrameOutput {
|
struct FrameOutput {
|
||||||
size_t frameNumber;
|
size_t frameNumber;
|
||||||
double pitch;
|
double pitch;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
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)
|
MonoNoteHMM::calculateObsProb(const vector<pair<double, double> > pitchProb)
|
||||||
{
|
{
|
||||||
// pitchProb is a list of pairs (pitches and their probabilities)
|
// pitchProb is a list of pairs (pitches and their probabilities)
|
||||||
|
|
||||||
size_t nCandidate = pitchProb.size();
|
size_t nCandidate = pitchProb.size();
|
||||||
|
|
||||||
// what is the probability of pitched
|
// what is the probability of pitched
|
||||||
double pIsPitched = 0;
|
double pIsPitched = 0;
|
||||||
for (size_t iCandidate = 0; iCandidate < nCandidate; ++iCandidate)
|
for (size_t iCandidate = 0; iCandidate < nCandidate; ++iCandidate)
|
||||||
@ -68,8 +68,8 @@ MonoNoteHMM::calculateObsProb(const vector<pair<double, double> > pitchProb)
|
|||||||
minDistCandidate = iCandidate;
|
minDistCandidate = iCandidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tempProb = std::pow(minDistProb, par.yinTrust) *
|
tempProb = std::pow(minDistProb, par.yinTrust) *
|
||||||
boost::math::pdf(pitchDistr[i],
|
boost::math::pdf(pitchDistr[i],
|
||||||
pitchProb[minDistCandidate].first);
|
pitchProb[minDistCandidate].first);
|
||||||
} else {
|
} else {
|
||||||
tempProb = 1;
|
tempProb = 1;
|
||||||
@ -78,12 +78,12 @@ MonoNoteHMM::calculateObsProb(const vector<pair<double, double> > pitchProb)
|
|||||||
out[i] = tempProb;
|
out[i] = tempProb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < par.n; ++i)
|
for (size_t i = 0; i < par.n; ++i)
|
||||||
{
|
{
|
||||||
if (i % par.nSPP != 2)
|
if (i % par.nSPP != 2)
|
||||||
{
|
{
|
||||||
if (tempProbSum > 0)
|
if (tempProbSum > 0)
|
||||||
{
|
{
|
||||||
out[i] = out[i] / tempProbSum * pIsPitched;
|
out[i] = out[i] / tempProbSum * pIsPitched;
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ MonoNoteHMM::build()
|
|||||||
// 3-5. second-lowest pitch
|
// 3-5. second-lowest pitch
|
||||||
// 3. attack state
|
// 3. attack state
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
// observation distributions
|
// observation distributions
|
||||||
for (size_t iState = 0; iState < par.n; ++iState)
|
for (size_t iState = 0; iState < par.n; ++iState)
|
||||||
{
|
{
|
||||||
@ -116,7 +116,7 @@ MonoNoteHMM::build()
|
|||||||
// silent state starts tracking
|
// silent state starts tracking
|
||||||
init.push_back(1.0/(par.nS * par.nPPS));
|
init.push_back(1.0/(par.nS * par.nPPS));
|
||||||
} else {
|
} 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+1] = boost::math::normal(mu, par.sigmaYinPitchStable);
|
||||||
pitchDistr[index+2] = boost::math::normal(mu, 1.0); // dummy
|
pitchDistr[index+2] = boost::math::normal(mu, 1.0); // dummy
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::math::normal noteDistanceDistr(0, par.sigma2Note);
|
boost::math::normal noteDistanceDistr(0, par.sigma2Note);
|
||||||
|
|
||||||
for (size_t iPitch = 0; iPitch < (par.nS * par.nPPS); ++iPitch)
|
for (size_t iPitch = 0; iPitch < (par.nS * par.nPPS); ++iPitch)
|
||||||
@ -149,7 +149,7 @@ MonoNoteHMM::build()
|
|||||||
from.push_back(index+1);
|
from.push_back(index+1);
|
||||||
to.push_back(index+1); // to itself
|
to.push_back(index+1); // to itself
|
||||||
transProb.push_back(par.pStableSelftrans);
|
transProb.push_back(par.pStableSelftrans);
|
||||||
|
|
||||||
from.push_back(index+1);
|
from.push_back(index+1);
|
||||||
to.push_back(index+2); // to silent
|
to.push_back(index+2); // to silent
|
||||||
transProb.push_back(par.pStable2Silent);
|
transProb.push_back(par.pStable2Silent);
|
||||||
@ -158,8 +158,7 @@ MonoNoteHMM::build()
|
|||||||
from.push_back(index+2);
|
from.push_back(index+2);
|
||||||
to.push_back(index+2);
|
to.push_back(index+2);
|
||||||
transProb.push_back(par.pSilentSelftrans);
|
transProb.push_back(par.pSilentSelftrans);
|
||||||
|
|
||||||
|
|
||||||
// the more complicated transitions from the silent
|
// the more complicated transitions from the silent
|
||||||
double probSumSilent = 0;
|
double probSumSilent = 0;
|
||||||
|
|
||||||
@ -168,17 +167,17 @@ MonoNoteHMM::build()
|
|||||||
{
|
{
|
||||||
int fromPitch = iPitch;
|
int fromPitch = iPitch;
|
||||||
int toPitch = jPitch;
|
int toPitch = jPitch;
|
||||||
double semitoneDistance =
|
double semitoneDistance =
|
||||||
std::abs(fromPitch - toPitch) * 1.0 / par.nPPS;
|
std::abs(fromPitch - toPitch) * 1.0 / par.nPPS;
|
||||||
|
|
||||||
// if (std::fmod(semitoneDistance, 1) == 0 && semitoneDistance > par.minSemitoneDistance)
|
// if (std::fmod(semitoneDistance, 1) == 0 && semitoneDistance > par.minSemitoneDistance)
|
||||||
if (semitoneDistance == 0 ||
|
if (semitoneDistance == 0 ||
|
||||||
(semitoneDistance > par.minSemitoneDistance
|
(semitoneDistance > par.minSemitoneDistance
|
||||||
&& semitoneDistance < par.maxJump))
|
&& semitoneDistance < par.maxJump))
|
||||||
{
|
{
|
||||||
size_t toIndex = jPitch * par.nSPP; // note attack index
|
size_t toIndex = jPitch * par.nSPP; // note attack index
|
||||||
|
|
||||||
double tempWeightSilent = boost::math::pdf(noteDistanceDistr,
|
double tempWeightSilent = boost::math::pdf(noteDistanceDistr,
|
||||||
semitoneDistance);
|
semitoneDistance);
|
||||||
probSumSilent += tempWeightSilent;
|
probSumSilent += tempWeightSilent;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
@ -14,23 +14,23 @@
|
|||||||
#include "MonoNoteParameters.h"
|
#include "MonoNoteParameters.h"
|
||||||
|
|
||||||
MonoNoteParameters::MonoNoteParameters() :
|
MonoNoteParameters::MonoNoteParameters() :
|
||||||
minPitch(35),
|
minPitch(35),
|
||||||
nPPS(3),
|
nPPS(3),
|
||||||
nS(69),
|
nS(69),
|
||||||
nSPP(3), // states per pitch
|
nSPP(3), // states per pitch
|
||||||
n(0),
|
n(0),
|
||||||
initPi(0),
|
initPi(0),
|
||||||
pAttackSelftrans(0.9),
|
pAttackSelftrans(0.9),
|
||||||
pStableSelftrans(0.99),
|
pStableSelftrans(0.99),
|
||||||
pStable2Silent(0.01),
|
pStable2Silent(0.01),
|
||||||
pSilentSelftrans(0.9999),
|
pSilentSelftrans(0.9999),
|
||||||
sigma2Note(0.7),
|
sigma2Note(0.7),
|
||||||
maxJump(13),
|
maxJump(13),
|
||||||
pInterSelftrans(0.0),
|
pInterSelftrans(0.0),
|
||||||
priorPitchedProb(.7),
|
priorPitchedProb(.7),
|
||||||
priorWeight(0.5),
|
priorWeight(0.5),
|
||||||
minSemitoneDistance(.5),
|
minSemitoneDistance(.5),
|
||||||
sigmaYinPitchAttack(5),
|
sigmaYinPitchAttack(5),
|
||||||
sigmaYinPitchStable(0.8),
|
sigmaYinPitchStable(0.8),
|
||||||
sigmaYinPitchInter(.1),
|
sigmaYinPitchInter(.1),
|
||||||
yinTrust(0.1)
|
yinTrust(0.1)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
@ -25,17 +25,17 @@ class MonoNoteParameters
|
|||||||
public:
|
public:
|
||||||
MonoNoteParameters();
|
MonoNoteParameters();
|
||||||
virtual ~MonoNoteParameters();
|
virtual ~MonoNoteParameters();
|
||||||
|
|
||||||
// model architecture parameters
|
// model architecture parameters
|
||||||
size_t minPitch; // lowest pitch in MIDI notes
|
size_t minPitch; // lowest pitch in MIDI notes
|
||||||
size_t nPPS; // number of pitches per semitone
|
size_t nPPS; // number of pitches per semitone
|
||||||
size_t nS; // number of semitones
|
size_t nS; // number of semitones
|
||||||
size_t nSPP; // number of states per pitch
|
size_t nSPP; // number of states per pitch
|
||||||
size_t n; // number of states (will be calcualted from other parameters)
|
size_t n; // number of states (will be calcualted from other parameters)
|
||||||
|
|
||||||
// initial state probabilities
|
// initial state probabilities
|
||||||
vector<double> initPi;
|
vector<double> initPi;
|
||||||
|
|
||||||
// transition parameters
|
// transition parameters
|
||||||
double pAttackSelftrans;
|
double pAttackSelftrans;
|
||||||
double pStableSelftrans;
|
double pStableSelftrans;
|
||||||
@ -44,18 +44,17 @@ public:
|
|||||||
double sigma2Note; // standard deviation of next note Gaussian distribution
|
double sigma2Note; // standard deviation of next note Gaussian distribution
|
||||||
double maxJump;
|
double maxJump;
|
||||||
double pInterSelftrans;
|
double pInterSelftrans;
|
||||||
|
|
||||||
double priorPitchedProb;
|
double priorPitchedProb;
|
||||||
double priorWeight;
|
double priorWeight;
|
||||||
|
|
||||||
double minSemitoneDistance; // minimum distance for a transition
|
double minSemitoneDistance; // minimum distance for a transition
|
||||||
|
|
||||||
double sigmaYinPitchAttack;
|
double sigmaYinPitchAttack;
|
||||||
double sigmaYinPitchStable;
|
double sigmaYinPitchStable;
|
||||||
double sigmaYinPitchInter;
|
double sigmaYinPitchInter;
|
||||||
|
|
||||||
double yinTrust;
|
double yinTrust;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
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]));
|
obsProb.push_back(hmm.calculateObsProb(pitchProb[iFrame]));
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<double> *scale = new vector<double>(0);
|
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;
|
// std::cerr << "before Viterbi decoding" << obsProb.size() << "ng" << obsProb[1].size() << std::endl;
|
||||||
vector<int> path = hmm.decodeViterbi(obsProb, scale);
|
vector<int> path = hmm.decodeViterbi(obsProb, scale);
|
||||||
// std::cerr << "after Viterbi decoding" << std::endl;
|
// std::cerr << "after Viterbi decoding" << std::endl;
|
||||||
|
|
||||||
for (size_t iFrame = 0; iFrame < path.size(); ++iFrame)
|
for (size_t iFrame = 0; iFrame < path.size(); ++iFrame)
|
||||||
{
|
{
|
||||||
// std::cerr << path[iFrame] << " " << hmm.m_freqs[path[iFrame]] << std::endl;
|
// std::cerr << path[iFrame] << " " << hmm.m_freqs[path[iFrame]] << std::endl;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
@ -27,7 +27,7 @@ class MonoPitch {
|
|||||||
public:
|
public:
|
||||||
MonoPitch();
|
MonoPitch();
|
||||||
virtual ~MonoPitch();
|
virtual ~MonoPitch();
|
||||||
|
|
||||||
// pitchProb is a frame-wise vector carrying a vector of pitch-probability pairs
|
// pitchProb is a frame-wise vector carrying a vector of pitch-probability pairs
|
||||||
const vector<float> process(const vector<vector<pair<double, double> > > pitchProb);
|
const vector<float> process(const vector<vector<pair<double, double> > > pitchProb);
|
||||||
private:
|
private:
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
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;
|
oldd = d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double probReallyPitched = m_yinTrust * probYinPitched;
|
double probReallyPitched = m_yinTrust * probYinPitched;
|
||||||
// std::cerr << probReallyPitched << " " << probYinPitched << std::endl;
|
// std::cerr << probReallyPitched << " " << probYinPitched << std::endl;
|
||||||
// damn, I forget what this is all about...
|
// damn, I forget what this is all about...
|
||||||
@ -84,14 +84,14 @@ MonoPitchHMM::build()
|
|||||||
{
|
{
|
||||||
// INITIAL VECTOR
|
// INITIAL VECTOR
|
||||||
init = vector<double>(2*m_nPitch, 1.0 / 2*m_nPitch);
|
init = vector<double>(2*m_nPitch, 1.0 / 2*m_nPitch);
|
||||||
|
|
||||||
// TRANSITIONS
|
// TRANSITIONS
|
||||||
for (size_t iPitch = 0; iPitch < m_nPitch; ++iPitch)
|
for (size_t iPitch = 0; iPitch < m_nPitch; ++iPitch)
|
||||||
{
|
{
|
||||||
int theoreticalMinNextPitch = static_cast<int>(iPitch)-static_cast<int>(m_transitionWidth/2);
|
int theoreticalMinNextPitch = static_cast<int>(iPitch)-static_cast<int>(m_transitionWidth/2);
|
||||||
int minNextPitch = iPitch>m_transitionWidth/2 ? iPitch-m_transitionWidth/2 : 0;
|
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;
|
int maxNextPitch = iPitch<m_nPitch-m_transitionWidth/2 ? iPitch+m_transitionWidth/2 : m_nPitch-1;
|
||||||
|
|
||||||
// WEIGHT VECTOR
|
// WEIGHT VECTOR
|
||||||
double weightSum = 0;
|
double weightSum = 0;
|
||||||
vector<double> weights;
|
vector<double> weights;
|
||||||
@ -107,7 +107,7 @@ MonoPitchHMM::build()
|
|||||||
}
|
}
|
||||||
weightSum += weights[weights.size()-1];
|
weightSum += weights[weights.size()-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::cerr << minNextPitch << " " << maxNextPitch << std::endl;
|
// std::cerr << minNextPitch << " " << maxNextPitch << std::endl;
|
||||||
// TRANSITIONS TO CLOSE PITCH
|
// TRANSITIONS TO CLOSE PITCH
|
||||||
for (size_t i = minNextPitch; i <= maxNextPitch; ++i)
|
for (size_t i = minNextPitch; i <= maxNextPitch; ++i)
|
||||||
@ -124,7 +124,7 @@ MonoPitchHMM::build()
|
|||||||
to.push_back(i+m_nPitch);
|
to.push_back(i+m_nPitch);
|
||||||
transProb.push_back(weights[i-minNextPitch] / weightSum * m_selfTrans);
|
transProb.push_back(weights[i-minNextPitch] / weightSum * m_selfTrans);
|
||||||
// transProb.push_back(weights[i-minNextPitch] / weightSum * 0.5);
|
// transProb.push_back(weights[i-minNextPitch] / weightSum * 0.5);
|
||||||
|
|
||||||
from.push_back(iPitch+m_nPitch);
|
from.push_back(iPitch+m_nPitch);
|
||||||
to.push_back(i);
|
to.push_back(i);
|
||||||
transProb.push_back(weights[i-minNextPitch] / weightSum * (1-m_selfTrans));
|
transProb.push_back(weights[i-minNextPitch] / weightSum * (1-m_selfTrans));
|
||||||
@ -135,7 +135,7 @@ MonoPitchHMM::build()
|
|||||||
// from.push_back(iPitch+m_nPitch);
|
// from.push_back(iPitch+m_nPitch);
|
||||||
// to.push_back(2*m_nPitch);
|
// to.push_back(2*m_nPitch);
|
||||||
// transProb.push_back(1-m_selfTrans);
|
// transProb.push_back(1-m_selfTrans);
|
||||||
|
|
||||||
// TRANSITION FROM UNVOICED TO PITCH
|
// TRANSITION FROM UNVOICED TO PITCH
|
||||||
// from.push_back(2*m_nPitch);
|
// from.push_back(2*m_nPitch);
|
||||||
// to.push_back(iPitch+m_nPitch);
|
// to.push_back(iPitch+m_nPitch);
|
||||||
@ -145,9 +145,9 @@ MonoPitchHMM::build()
|
|||||||
// from.push_back(2*m_nPitch);
|
// from.push_back(2*m_nPitch);
|
||||||
// to.push_back(2*m_nPitch);
|
// to.push_back(2*m_nPitch);
|
||||||
// transProb.push_back(m_selfTrans);
|
// transProb.push_back(m_selfTrans);
|
||||||
|
|
||||||
// for (size_t i = 0; i < from.size(); ++i) {
|
// for (size_t i = 0; i < from.size(); ++i) {
|
||||||
// std::cerr << "P(["<< from[i] << " --> " << to[i] << "]) = " << transProb[i] << std::endl;
|
// std::cerr << "P(["<< from[i] << " --> " << to[i] << "]) = " << transProb[i] << std::endl;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
@ -109,7 +109,7 @@ PYinVamp::getPreferredBlockSize() const
|
|||||||
return 2048;
|
return 2048;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
PYinVamp::getPreferredStepSize() const
|
PYinVamp::getPreferredStepSize() const
|
||||||
{
|
{
|
||||||
return 256;
|
return 256;
|
||||||
@ -131,7 +131,7 @@ PYinVamp::ParameterList
|
|||||||
PYinVamp::getParameterDescriptors() const
|
PYinVamp::getParameterDescriptors() const
|
||||||
{
|
{
|
||||||
ParameterList list;
|
ParameterList list;
|
||||||
|
|
||||||
ParameterDescriptor d;
|
ParameterDescriptor d;
|
||||||
|
|
||||||
d.identifier = "threshdistr";
|
d.identifier = "threshdistr";
|
||||||
@ -241,7 +241,7 @@ PYinVamp::getParameter(string identifier) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PYinVamp::setParameter(string identifier, float value)
|
PYinVamp::setParameter(string identifier, float value)
|
||||||
{
|
{
|
||||||
if (identifier == "threshdistr")
|
if (identifier == "threshdistr")
|
||||||
{
|
{
|
||||||
@ -293,7 +293,7 @@ PYinVamp::getOutputDescriptors() const
|
|||||||
OutputList outputs;
|
OutputList outputs;
|
||||||
|
|
||||||
OutputDescriptor d;
|
OutputDescriptor d;
|
||||||
|
|
||||||
int outputNumber = 0;
|
int outputNumber = 0;
|
||||||
|
|
||||||
d.identifier = "f0candidates";
|
d.identifier = "f0candidates";
|
||||||
@ -327,7 +327,7 @@ PYinVamp::getOutputDescriptors() const
|
|||||||
d.hasDuration = false;
|
d.hasDuration = false;
|
||||||
outputs.push_back(d);
|
outputs.push_back(d);
|
||||||
m_oF0Probs = outputNumber++;
|
m_oF0Probs = outputNumber++;
|
||||||
|
|
||||||
d.identifier = "voicedprob";
|
d.identifier = "voicedprob";
|
||||||
d.name = "Voiced Probability";
|
d.name = "Voiced Probability";
|
||||||
d.description = "Probability that the signal is voiced according to Probabilistic Yin.";
|
d.description = "Probability that the signal is voiced according to Probabilistic Yin.";
|
||||||
@ -358,7 +358,7 @@ PYinVamp::getOutputDescriptors() const
|
|||||||
d.hasDuration = false;
|
d.hasDuration = false;
|
||||||
outputs.push_back(d);
|
outputs.push_back(d);
|
||||||
m_oCandidateSalience = outputNumber++;
|
m_oCandidateSalience = outputNumber++;
|
||||||
|
|
||||||
d.identifier = "smoothedpitchtrack";
|
d.identifier = "smoothedpitchtrack";
|
||||||
d.name = "Smoothed Pitch Track";
|
d.name = "Smoothed Pitch Track";
|
||||||
d.description = ".";
|
d.description = ".";
|
||||||
@ -407,7 +407,7 @@ PYinVamp::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
|||||||
m_channels = channels;
|
m_channels = channels;
|
||||||
m_stepSize = stepSize;
|
m_stepSize = stepSize;
|
||||||
m_blockSize = blockSize;
|
m_blockSize = blockSize;
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -415,15 +415,15 @@ PYinVamp::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
|||||||
|
|
||||||
void
|
void
|
||||||
PYinVamp::reset()
|
PYinVamp::reset()
|
||||||
{
|
{
|
||||||
m_yin.setThresholdDistr(m_threshDistr);
|
m_yin.setThresholdDistr(m_threshDistr);
|
||||||
m_yin.setFrameSize(m_blockSize);
|
m_yin.setFrameSize(m_blockSize);
|
||||||
m_yin.setFast(!m_preciseTime);
|
m_yin.setFast(!m_preciseTime);
|
||||||
|
|
||||||
m_pitchProb.clear();
|
m_pitchProb.clear();
|
||||||
m_timestamp.clear();
|
m_timestamp.clear();
|
||||||
m_level.clear();
|
m_level.clear();
|
||||||
/*
|
/*
|
||||||
std::cerr << "PYinVamp::reset"
|
std::cerr << "PYinVamp::reset"
|
||||||
<< ", blockSize = " << m_blockSize
|
<< ", blockSize = " << m_blockSize
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
@ -437,9 +437,9 @@ PYinVamp::process(const float *const *inputBuffers, RealTime timestamp)
|
|||||||
timestamp = timestamp + Vamp::RealTime::frame2RealTime(offset, lrintf(m_inputSampleRate));
|
timestamp = timestamp + Vamp::RealTime::frame2RealTime(offset, lrintf(m_inputSampleRate));
|
||||||
|
|
||||||
FeatureSet fs;
|
FeatureSet fs;
|
||||||
|
|
||||||
float rms = 0;
|
float rms = 0;
|
||||||
|
|
||||||
double *dInputBuffers = new double[m_blockSize];
|
double *dInputBuffers = new double[m_blockSize];
|
||||||
for (size_t i = 0; i < m_blockSize; ++i) {
|
for (size_t i = 0; i < m_blockSize; ++i) {
|
||||||
dInputBuffers[i] = inputBuffers[0][i];
|
dInputBuffers[i] = inputBuffers[0][i];
|
||||||
@ -447,15 +447,15 @@ PYinVamp::process(const float *const *inputBuffers, RealTime timestamp)
|
|||||||
}
|
}
|
||||||
rms /= m_blockSize;
|
rms /= m_blockSize;
|
||||||
rms = sqrt(rms);
|
rms = sqrt(rms);
|
||||||
|
|
||||||
bool isLowAmplitude = (rms < m_lowAmp);
|
bool isLowAmplitude = (rms < m_lowAmp);
|
||||||
|
|
||||||
Yin::YinOutput yo = m_yin.processProbabilisticYin(dInputBuffers);
|
Yin::YinOutput yo = m_yin.processProbabilisticYin(dInputBuffers);
|
||||||
delete [] dInputBuffers;
|
delete [] dInputBuffers;
|
||||||
|
|
||||||
m_level.push_back(yo.rms);
|
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.
|
// immediately, but instead save for later.
|
||||||
vector<pair<double, double> > tempPitchProb;
|
vector<pair<double, double> > tempPitchProb;
|
||||||
for (size_t iCandidate = 0; iCandidate < yo.freqProb.size(); ++iCandidate)
|
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);
|
f.values.push_back(yo.freqProb[i].first);
|
||||||
}
|
}
|
||||||
fs[m_oF0Candidates].push_back(f);
|
fs[m_oF0Candidates].push_back(f);
|
||||||
|
|
||||||
// VOICEDPROB
|
// VOICEDPROB
|
||||||
f.values.clear();
|
f.values.clear();
|
||||||
float voicedProb = 0;
|
float voicedProb = 0;
|
||||||
@ -493,7 +493,7 @@ PYinVamp::process(const float *const *inputBuffers, RealTime timestamp)
|
|||||||
voicedProb += yo.freqProb[i].second;
|
voicedProb += yo.freqProb[i].second;
|
||||||
}
|
}
|
||||||
fs[m_oF0Probs].push_back(f);
|
fs[m_oF0Probs].push_back(f);
|
||||||
|
|
||||||
f.values.push_back(voicedProb);
|
f.values.push_back(voicedProb);
|
||||||
fs[m_oVoicedProb].push_back(f);
|
fs[m_oVoicedProb].push_back(f);
|
||||||
|
|
||||||
@ -517,7 +517,7 @@ PYinVamp::getRemainingFeatures()
|
|||||||
Feature f;
|
Feature f;
|
||||||
f.hasTimestamp = true;
|
f.hasTimestamp = true;
|
||||||
f.hasDuration = false;
|
f.hasDuration = false;
|
||||||
|
|
||||||
if (m_pitchProb.empty()) {
|
if (m_pitchProb.empty()) {
|
||||||
return fs;
|
return fs;
|
||||||
}
|
}
|
||||||
@ -536,10 +536,10 @@ PYinVamp::getRemainingFeatures()
|
|||||||
} else {
|
} else {
|
||||||
f.values.push_back(mpOut[iFrame]);
|
f.values.push_back(mpOut[iFrame]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs[m_oSmoothedPitchTrack].push_back(f);
|
fs[m_oSmoothedPitchTrack].push_back(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// MONO-NOTE STUFF
|
// MONO-NOTE STUFF
|
||||||
// std::cerr << "Mono Note Stuff" << std::endl;
|
// std::cerr << "Mono Note Stuff" << std::endl;
|
||||||
MonoNote mn;
|
MonoNote mn;
|
||||||
@ -555,19 +555,19 @@ PYinVamp::getRemainingFeatures()
|
|||||||
}
|
}
|
||||||
// vector<MonoNote::FrameOutput> mnOut = mn.process(m_pitchProb);
|
// vector<MonoNote::FrameOutput> mnOut = mn.process(m_pitchProb);
|
||||||
vector<MonoNote::FrameOutput> mnOut = mn.process(smoothedPitch);
|
vector<MonoNote::FrameOutput> mnOut = mn.process(smoothedPitch);
|
||||||
|
|
||||||
// turning feature into a note feature
|
// turning feature into a note feature
|
||||||
f.hasTimestamp = true;
|
f.hasTimestamp = true;
|
||||||
f.hasDuration = true;
|
f.hasDuration = true;
|
||||||
f.values.clear();
|
f.values.clear();
|
||||||
|
|
||||||
int onsetFrame = 0;
|
int onsetFrame = 0;
|
||||||
bool isVoiced = 0;
|
bool isVoiced = 0;
|
||||||
bool oldIsVoiced = 0;
|
bool oldIsVoiced = 0;
|
||||||
size_t nFrame = m_pitchProb.size();
|
size_t nFrame = m_pitchProb.size();
|
||||||
|
|
||||||
float minNoteFrames = (m_inputSampleRate*m_pruneThresh) / m_stepSize;
|
float minNoteFrames = (m_inputSampleRate*m_pruneThresh) / m_stepSize;
|
||||||
|
|
||||||
std::vector<float> notePitchTrack; // collects pitches for one note at a time
|
std::vector<float> notePitchTrack; // collects pitches for one note at a time
|
||||||
for (size_t iFrame = 0; iFrame < nFrame; ++iFrame)
|
for (size_t iFrame = 0; iFrame < nFrame; ++iFrame)
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
@ -62,7 +62,7 @@ protected:
|
|||||||
float m_fmin;
|
float m_fmin;
|
||||||
float m_fmax;
|
float m_fmax;
|
||||||
Yin m_yin;
|
Yin m_yin;
|
||||||
|
|
||||||
mutable int m_oF0Candidates;
|
mutable int m_oF0Candidates;
|
||||||
mutable int m_oF0Probs;
|
mutable int m_oF0Probs;
|
||||||
mutable int m_oVoicedProb;
|
mutable int m_oVoicedProb;
|
||||||
|
2
libs/vamp-pyin/README
Normal file
2
libs/vamp-pyin/README
Normal 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
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
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>());
|
return(vector<double>());
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<int>
|
const std::vector<int>
|
||||||
SparseHMM::decodeViterbi(std::vector<vector<double> > obsProb,
|
SparseHMM::decodeViterbi(std::vector<vector<double> > obsProb,
|
||||||
vector<double> *scale)
|
vector<double> *scale)
|
||||||
{
|
{
|
||||||
if (obsProb.size() < 1) {
|
if (obsProb.size() < 1) {
|
||||||
return vector<int>();
|
return vector<int>();
|
||||||
@ -36,10 +36,10 @@ SparseHMM::decodeViterbi(std::vector<vector<double> > obsProb,
|
|||||||
|
|
||||||
size_t nState = init.size();
|
size_t nState = init.size();
|
||||||
size_t nFrame = obsProb.size();
|
size_t nFrame = obsProb.size();
|
||||||
|
|
||||||
// check for consistency
|
// check for consistency
|
||||||
size_t nTrans = transProb.size();
|
size_t nTrans = transProb.size();
|
||||||
|
|
||||||
// declaring variables
|
// declaring variables
|
||||||
std::vector<double> delta = std::vector<double>(nState);
|
std::vector<double> delta = std::vector<double>(nState);
|
||||||
std::vector<double> oldDelta = 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;
|
size_t toState;
|
||||||
double currentTransProb;
|
double currentTransProb;
|
||||||
double currentValue;
|
double currentValue;
|
||||||
|
|
||||||
// this is the "sparse" loop
|
// this is the "sparse" loop
|
||||||
for (size_t iTrans = 0; iTrans < nTrans; ++iTrans)
|
for (size_t iTrans = 0; iTrans < nTrans; ++iTrans)
|
||||||
{
|
{
|
||||||
fromState = from[iTrans];
|
fromState = from[iTrans];
|
||||||
toState = to[iTrans];
|
toState = to[iTrans];
|
||||||
currentTransProb = transProb[iTrans];
|
currentTransProb = transProb[iTrans];
|
||||||
|
|
||||||
currentValue = oldDelta[fromState] * currentTransProb;
|
currentValue = oldDelta[fromState] * currentTransProb;
|
||||||
if (currentValue > delta[toState])
|
if (currentValue > delta[toState])
|
||||||
{
|
{
|
||||||
delta[toState] = currentValue; // will be multiplied by the right obs later!
|
delta[toState] = currentValue; // will be multiplied by the right obs later!
|
||||||
psi[iFrame][toState] = fromState;
|
psi[iFrame][toState] = fromState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t jState = 0; jState < nState; ++jState)
|
for (size_t jState = 0; jState < nState; ++jState)
|
||||||
{
|
{
|
||||||
delta[jState] *= obsProb[iFrame][jState];
|
delta[jState] *= obsProb[iFrame][jState];
|
||||||
@ -125,7 +125,7 @@ SparseHMM::decodeViterbi(std::vector<vector<double> > obsProb,
|
|||||||
double currentValue = oldDelta[iState];
|
double currentValue = oldDelta[iState];
|
||||||
if (currentValue > bestValue)
|
if (currentValue > bestValue)
|
||||||
{
|
{
|
||||||
bestValue = currentValue;
|
bestValue = currentValue;
|
||||||
path[nFrame-1] = iState;
|
path[nFrame-1] = iState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,11 +135,11 @@ SparseHMM::decodeViterbi(std::vector<vector<double> > obsProb,
|
|||||||
{
|
{
|
||||||
path[iFrame] = psi[iFrame+1][path[iFrame+1]];
|
path[iFrame] = psi[iFrame+1][path[iFrame+1]];
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (size_t iState = 0; iState < nState; ++iState)
|
// for (size_t iState = 0; iState < nState; ++iState)
|
||||||
// {
|
// {
|
||||||
// // std::cerr << psi[2][iState] << std::endl;
|
// // std::cerr << psi[2][iState] << std::endl;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
@ -24,7 +24,7 @@ class SparseHMM
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual const std::vector<double> calculateObsProb(const vector<pair<double, double> >);
|
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> *scale);
|
||||||
vector<double> init;
|
vector<double> init;
|
||||||
vector<size_t> from;
|
vector<size_t> from;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
using std::vector;
|
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_frameSize(frameSize),
|
||||||
m_inputSampleRate(inputSampleRate),
|
m_inputSampleRate(inputSampleRate),
|
||||||
m_thresh(thresh),
|
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::YinOutput
|
||||||
Yin::process(const double *in) const {
|
Yin::process(const double *in) const {
|
||||||
|
|
||||||
double* yinBuffer = new double[m_yinBufferSize];
|
double* yinBuffer = new double[m_yinBufferSize];
|
||||||
|
|
||||||
// calculate aperiodicity function for all periods
|
// calculate aperiodicity function for all periods
|
||||||
@ -55,11 +55,11 @@ Yin::process(const double *in) const {
|
|||||||
|
|
||||||
int tau = 0;
|
int tau = 0;
|
||||||
tau = YinUtil::absoluteThreshold(yinBuffer, m_yinBufferSize, m_thresh);
|
tau = YinUtil::absoluteThreshold(yinBuffer, m_yinBufferSize, m_thresh);
|
||||||
|
|
||||||
double interpolatedTau;
|
double interpolatedTau;
|
||||||
double aperiodicity;
|
double aperiodicity;
|
||||||
double f0;
|
double f0;
|
||||||
|
|
||||||
if (tau!=0)
|
if (tau!=0)
|
||||||
{
|
{
|
||||||
interpolatedTau = YinUtil::parabolicInterpolation(yinBuffer, abs(tau), m_yinBufferSize);
|
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?
|
yo.salience.push_back(yinBuffer[iBuf] < 1 ? 1-yinBuffer[iBuf] : 0); // why are the values sometimes < 0 if I don't check?
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] yinBuffer;
|
delete [] yinBuffer;
|
||||||
return yo;
|
return yo;
|
||||||
}
|
}
|
||||||
|
|
||||||
Yin::YinOutput
|
Yin::YinOutput
|
||||||
Yin::processProbabilisticYin(const double *in) const {
|
Yin::processProbabilisticYin(const double *in) const {
|
||||||
|
|
||||||
double* yinBuffer = new double[m_yinBufferSize];
|
double* yinBuffer = new double[m_yinBufferSize];
|
||||||
|
|
||||||
// calculate aperiodicity function for all periods
|
// calculate aperiodicity function for all periods
|
||||||
@ -95,7 +95,7 @@ Yin::processProbabilisticYin(const double *in) const {
|
|||||||
YinUtil::cumulativeDifference(yinBuffer, m_yinBufferSize);
|
YinUtil::cumulativeDifference(yinBuffer, m_yinBufferSize);
|
||||||
|
|
||||||
vector<double> peakProbability = YinUtil::yinProb(yinBuffer, m_threshDistr, m_yinBufferSize);
|
vector<double> peakProbability = YinUtil::yinProb(yinBuffer, m_threshDistr, m_yinBufferSize);
|
||||||
|
|
||||||
// calculate overall "probability" from peak probability
|
// calculate overall "probability" from peak probability
|
||||||
double probSum = 0;
|
double probSum = 0;
|
||||||
for (size_t iBin = 0; iBin < m_yinBufferSize; ++iBin)
|
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]);
|
yo.salience.push_back(peakProbability[iBuf]);
|
||||||
if (peakProbability[iBuf] > 0)
|
if (peakProbability[iBuf] > 0)
|
||||||
{
|
{
|
||||||
double currentF0 =
|
double currentF0 =
|
||||||
m_inputSampleRate * (1.0 /
|
m_inputSampleRate * (1.0 /
|
||||||
YinUtil::parabolicInterpolation(yinBuffer, iBuf, m_yinBufferSize));
|
YinUtil::parabolicInterpolation(yinBuffer, iBuf, m_yinBufferSize));
|
||||||
yo.freqProb.push_back(pair<double, double>(currentF0, peakProbability[iBuf]));
|
yo.freqProb.push_back(pair<double, double>(currentF0, peakProbability[iBuf]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::cerr << yo.freqProb.size() << std::endl;
|
// std::cerr << yo.freqProb.size() << std::endl;
|
||||||
|
|
||||||
delete [] yinBuffer;
|
delete [] yinBuffer;
|
||||||
return yo;
|
return yo;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
@ -27,7 +27,6 @@ using std::vector;
|
|||||||
using std::pair;
|
using std::pair;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Yin
|
class Yin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -40,16 +39,16 @@ public:
|
|||||||
double rms;
|
double rms;
|
||||||
vector<double> salience;
|
vector<double> salience;
|
||||||
vector<pair<double, double> > freqProb;
|
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)) { }
|
salience(vector<double>(0)), freqProb(vector<pair<double, double> >(0)) { }
|
||||||
YinOutput(double _f, double _p, double _r) :
|
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)) { }
|
salience(vector<double>(0)), freqProb(vector<pair<double, double> >(0)) { }
|
||||||
YinOutput(double _f, double _p, double _r, vector<double> _salience) :
|
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)) { }
|
freqProb(vector<pair<double, double> >(0)) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
int setThreshold(double parameter);
|
int setThreshold(double parameter);
|
||||||
int setThresholdDistr(float parameter);
|
int setThresholdDistr(float parameter);
|
||||||
int setFrameSize(size_t frameSize);
|
int setFrameSize(size_t frameSize);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
#include <boost/math/distributions.hpp>
|
#include <boost/math/distributions.hpp>
|
||||||
|
|
||||||
void
|
void
|
||||||
YinUtil::slowDifference(const double *in, double *yinBuffer, const size_t yinBufferSize)
|
YinUtil::slowDifference(const double *in, double *yinBuffer, const size_t yinBufferSize)
|
||||||
{
|
{
|
||||||
yinBuffer[0] = 0;
|
yinBuffer[0] = 0;
|
||||||
double delta ;
|
double delta ;
|
||||||
@ -36,19 +36,19 @@ YinUtil::slowDifference(const double *in, double *yinBuffer, const size_t yinBuf
|
|||||||
delta = in[i+j] - in[j];
|
delta = in[i+j] - in[j];
|
||||||
yinBuffer[i] += delta * delta;
|
yinBuffer[i] += delta * delta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
YinUtil::fastDifference(const double *in, double *yinBuffer, const size_t yinBufferSize)
|
YinUtil::fastDifference(const double *in, double *yinBuffer, const size_t yinBufferSize)
|
||||||
{
|
{
|
||||||
|
|
||||||
// DECLARE AND INITIALISE
|
// DECLARE AND INITIALISE
|
||||||
// initialisation of most of the arrays here was done in a separate function,
|
// 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.
|
// with all the arrays as members of the class... moved them back here.
|
||||||
|
|
||||||
size_t frameSize = 2 * yinBufferSize;
|
size_t frameSize = 2 * yinBufferSize;
|
||||||
|
|
||||||
double *audioTransformedReal = new double[frameSize];
|
double *audioTransformedReal = new double[frameSize];
|
||||||
double *audioTransformedImag = new double[frameSize];
|
double *audioTransformedImag = new double[frameSize];
|
||||||
double *nullImag = 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 *yinStyleACFReal = new double[frameSize];
|
||||||
double *yinStyleACFImag = new double[frameSize];
|
double *yinStyleACFImag = new double[frameSize];
|
||||||
double *powerTerms = new double[yinBufferSize];
|
double *powerTerms = new double[yinBufferSize];
|
||||||
|
|
||||||
for (size_t j = 0; j < yinBufferSize; ++j)
|
for (size_t j = 0; j < yinBufferSize; ++j)
|
||||||
{
|
{
|
||||||
yinBuffer[j] = 0.; // set to zero
|
yinBuffer[j] = 0.; // set to zero
|
||||||
powerTerms[j] = 0.; // set to zero
|
powerTerms[j] = 0.; // set to zero
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t j = 0; j < frameSize; ++j)
|
for (size_t j = 0; j < frameSize; ++j)
|
||||||
{
|
{
|
||||||
nullImag[j] = 0.;
|
nullImag[j] = 0.;
|
||||||
@ -76,7 +76,7 @@ YinUtil::fastDifference(const double *in, double *yinBuffer, const size_t yinBuf
|
|||||||
yinStyleACFReal[j] = 0.;
|
yinStyleACFReal[j] = 0.;
|
||||||
yinStyleACFImag[j] = 0.;
|
yinStyleACFImag[j] = 0.;
|
||||||
}
|
}
|
||||||
|
|
||||||
// POWER TERM CALCULATION
|
// POWER TERM CALCULATION
|
||||||
// ... for the power terms in equation (7) in the Yin paper
|
// ... for the power terms in equation (7) in the Yin paper
|
||||||
powerTerms[0] = 0.0;
|
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)
|
// now iteratively calculate all others (saves a few multiplications)
|
||||||
for (size_t tau = 1; tau < yinBufferSize; ++tau) {
|
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
|
// YIN-STYLE AUTOCORRELATION via FFT
|
||||||
// 1. data
|
// 1. data
|
||||||
Vamp::FFT::forward(frameSize, in, nullImag, audioTransformedReal, audioTransformedImag);
|
Vamp::FFT::forward(frameSize, in, nullImag, audioTransformedReal, audioTransformedImag);
|
||||||
|
|
||||||
// 2. half of the data, disguised as a convolution kernel
|
// 2. half of the data, disguised as a convolution kernel
|
||||||
for (size_t j = 0; j < yinBufferSize; ++j) {
|
for (size_t j = 0; j < yinBufferSize; ++j) {
|
||||||
kernel[j] = in[yinBufferSize-1-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
|
yinStyleACFImag[j] = audioTransformedReal[j]*kernelTransformedImag[j] + audioTransformedImag[j]*kernelTransformedReal[j]; // imaginary
|
||||||
}
|
}
|
||||||
Vamp::FFT::inverse(frameSize, yinStyleACFReal, yinStyleACFImag, audioTransformedReal, audioTransformedImag);
|
Vamp::FFT::inverse(frameSize, yinStyleACFReal, yinStyleACFImag, audioTransformedReal, audioTransformedImag);
|
||||||
|
|
||||||
// CALCULATION OF difference function
|
// CALCULATION OF difference function
|
||||||
// ... according to (7) in the Yin paper.
|
// ... according to (7) in the Yin paper.
|
||||||
for (size_t j = 0; j < yinBufferSize; ++j) {
|
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;
|
delete [] powerTerms;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
YinUtil::cumulativeDifference(double *yinBuffer, const size_t yinBufferSize)
|
YinUtil::cumulativeDifference(double *yinBuffer, const size_t yinBufferSize)
|
||||||
{
|
{
|
||||||
size_t tau;
|
size_t tau;
|
||||||
|
|
||||||
yinBuffer[0] = 1;
|
yinBuffer[0] = 1;
|
||||||
|
|
||||||
double runningSum = 0;
|
double runningSum = 0;
|
||||||
|
|
||||||
for (tau = 1; tau < yinBufferSize; ++tau) {
|
for (tau = 1; tau < yinBufferSize; ++tau) {
|
||||||
runningSum += yinBuffer[tau];
|
runningSum += yinBuffer[tau];
|
||||||
if (runningSum == 0)
|
if (runningSum == 0)
|
||||||
@ -140,16 +140,16 @@ YinUtil::cumulativeDifference(double *yinBuffer, const size_t yinBufferSize)
|
|||||||
} else {
|
} else {
|
||||||
yinBuffer[tau] *= tau / runningSum;
|
yinBuffer[tau] *= tau / runningSum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
YinUtil::absoluteThreshold(const double *yinBuffer, const size_t yinBufferSize, const double thresh)
|
YinUtil::absoluteThreshold(const double *yinBuffer, const size_t yinBufferSize, const double thresh)
|
||||||
{
|
{
|
||||||
size_t tau;
|
size_t tau;
|
||||||
size_t minTau = 0;
|
size_t minTau = 0;
|
||||||
double minVal = 1000.;
|
double minVal = 1000.;
|
||||||
|
|
||||||
// using Joren Six's "loop construct" from TarsosDSP
|
// using Joren Six's "loop construct" from TarsosDSP
|
||||||
tau = 2;
|
tau = 2;
|
||||||
while (tau < yinBufferSize)
|
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};
|
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>
|
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 minTau = 2;
|
||||||
size_t maxTau = yinBufferSize;
|
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> thresholds;
|
||||||
std::vector<float> distribution;
|
std::vector<float> distribution;
|
||||||
std::vector<double> peakProb = std::vector<double>(yinBufferSize);
|
std::vector<double> peakProb = std::vector<double>(yinBufferSize);
|
||||||
|
|
||||||
size_t nThreshold = 100;
|
size_t nThreshold = 100;
|
||||||
int nThresholdInt = nThreshold;
|
int nThresholdInt = nThreshold;
|
||||||
|
|
||||||
for (int i = 0; i < nThresholdInt; ++i)
|
for (int i = 0; i < nThresholdInt; ++i)
|
||||||
{
|
{
|
||||||
switch (prior) {
|
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);
|
thresholds.push_back(0.01 + i*0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int currThreshInd = nThreshold-1;
|
int currThreshInd = nThreshold-1;
|
||||||
tau = minTau;
|
tau = minTau;
|
||||||
|
|
||||||
// double factor = 1.0 / (0.25 * (nThresholdInt+1) * (nThresholdInt + 1)); // factor to scale down triangular weight
|
// double factor = 1.0 / (0.25 * (nThresholdInt+1) * (nThresholdInt + 1)); // factor to scale down triangular weight
|
||||||
size_t minInd = 0;
|
size_t minInd = 0;
|
||||||
float minVal = 42.f;
|
float minVal = 42.f;
|
||||||
@ -270,7 +269,7 @@ YinUtil::yinProb(const double *yinBuffer, const size_t prior, const size_t yinBu
|
|||||||
// {
|
// {
|
||||||
// nonPeakProb -= peakProb[i];
|
// nonPeakProb -= peakProb[i];
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// std::cerr << tau << " " << currThreshInd << " "<< thresholds[currThreshInd] << " " << distribution[currThreshInd] << std::endl;
|
// std::cerr << tau << " " << currThreshInd << " "<< thresholds[currThreshInd] << " " << distribution[currThreshInd] << std::endl;
|
||||||
float sumProb = 0;
|
float sumProb = 0;
|
||||||
while (tau+1 < maxTau)
|
while (tau+1 < maxTau)
|
||||||
@ -300,12 +299,12 @@ YinUtil::yinProb(const double *yinBuffer, const size_t prior, const size_t yinBu
|
|||||||
tau++;
|
tau++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peakProb[minInd] > 1) {
|
if (peakProb[minInd] > 1) {
|
||||||
std::cerr << "WARNING: yin has prob > 1 ??? I'm returning all zeros instead." << std::endl;
|
std::cerr << "WARNING: yin has prob > 1 ??? I'm returning all zeros instead." << std::endl;
|
||||||
return(std::vector<double>(yinBufferSize));
|
return(std::vector<double>(yinBufferSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
double nonPeakProb = 1;
|
double nonPeakProb = 1;
|
||||||
if (sumProb > 0) {
|
if (sumProb > 0) {
|
||||||
for (size_t i = minTau; i < maxTau; ++i)
|
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)
|
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;
|
peakProb[minInd] += nonPeakProb * minWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
return peakProb;
|
return peakProb;
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
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
|
// this is taken almost literally from Joren Six's Java implementation
|
||||||
if (tau == yinBufferSize) // not valid anyway.
|
if (tau == yinBufferSize) // not valid anyway.
|
||||||
{
|
{
|
||||||
return static_cast<double>(tau);
|
return static_cast<double>(tau);
|
||||||
}
|
}
|
||||||
|
|
||||||
double betterTau = 0.0;
|
double betterTau = 0.0;
|
||||||
if (tau > 0 && tau < yinBufferSize-1) {
|
if (tau > 0 && tau < yinBufferSize-1) {
|
||||||
float s0, s1, s2;
|
float s0, s1, s2;
|
||||||
s0 = yinBuffer[tau-1];
|
s0 = yinBuffer[tau-1];
|
||||||
s1 = yinBuffer[tau];
|
s1 = yinBuffer[tau];
|
||||||
s2 = yinBuffer[tau+1];
|
s2 = yinBuffer[tau+1];
|
||||||
|
|
||||||
double adjustment = (s2 - s0) / (2 * (2 * s1 - s2 - s0));
|
double adjustment = (s2 - s0) / (2 * (2 * s1 - s2 - s0));
|
||||||
|
|
||||||
if (abs(adjustment)>1) adjustment = 0;
|
if (abs(adjustment)>1) adjustment = 0;
|
||||||
|
|
||||||
betterTau = tau + adjustment;
|
betterTau = tau + adjustment;
|
||||||
} else {
|
} else {
|
||||||
// std::cerr << "WARNING: can't do interpolation at the edge (tau = " << tau << "), will return un-interpolated value.\n";
|
// 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;
|
return betterTau;
|
||||||
}
|
}
|
||||||
|
|
||||||
double
|
double
|
||||||
YinUtil::sumSquare(const double *in, const size_t start, const size_t end)
|
YinUtil::sumSquare(const double *in, const size_t start, const size_t end)
|
||||||
{
|
{
|
||||||
double out = 0;
|
double out = 0;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
@ -99,7 +99,7 @@ YinVamp::getPreferredBlockSize() const
|
|||||||
return 2048;
|
return 2048;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
YinVamp::getPreferredStepSize() const
|
YinVamp::getPreferredStepSize() const
|
||||||
{
|
{
|
||||||
return 256;
|
return 256;
|
||||||
@ -121,7 +121,7 @@ YinVamp::ParameterList
|
|||||||
YinVamp::getParameterDescriptors() const
|
YinVamp::getParameterDescriptors() const
|
||||||
{
|
{
|
||||||
ParameterList list;
|
ParameterList list;
|
||||||
|
|
||||||
ParameterDescriptor d;
|
ParameterDescriptor d;
|
||||||
d.identifier = "yinThreshold";
|
d.identifier = "yinThreshold";
|
||||||
d.name = "Yin threshold";
|
d.name = "Yin threshold";
|
||||||
@ -132,7 +132,7 @@ YinVamp::getParameterDescriptors() const
|
|||||||
d.defaultValue = 0.15f;
|
d.defaultValue = 0.15f;
|
||||||
d.isQuantized = true;
|
d.isQuantized = true;
|
||||||
d.quantizeStep = 0.025f;
|
d.quantizeStep = 0.025f;
|
||||||
|
|
||||||
list.push_back(d);
|
list.push_back(d);
|
||||||
|
|
||||||
d.identifier = "outputunvoiced";
|
d.identifier = "outputunvoiced";
|
||||||
@ -166,7 +166,7 @@ YinVamp::getParameter(string identifier) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
YinVamp::setParameter(string identifier, float value)
|
YinVamp::setParameter(string identifier, float value)
|
||||||
{
|
{
|
||||||
if (identifier == "yinThreshold")
|
if (identifier == "yinThreshold")
|
||||||
{
|
{
|
||||||
@ -202,7 +202,7 @@ YinVamp::getOutputDescriptors() const
|
|||||||
OutputList outputs;
|
OutputList outputs;
|
||||||
|
|
||||||
OutputDescriptor d;
|
OutputDescriptor d;
|
||||||
|
|
||||||
int outputNumber = 0;
|
int outputNumber = 0;
|
||||||
|
|
||||||
d.identifier = "f0";
|
d.identifier = "f0";
|
||||||
@ -285,7 +285,7 @@ YinVamp::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
|||||||
m_channels = channels;
|
m_channels = channels;
|
||||||
m_stepSize = stepSize;
|
m_stepSize = stepSize;
|
||||||
m_blockSize = blockSize;
|
m_blockSize = blockSize;
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -293,10 +293,10 @@ YinVamp::initialise(size_t channels, size_t stepSize, size_t blockSize)
|
|||||||
|
|
||||||
void
|
void
|
||||||
YinVamp::reset()
|
YinVamp::reset()
|
||||||
{
|
{
|
||||||
m_yin.setThreshold(m_yinParameter);
|
m_yin.setThreshold(m_yinParameter);
|
||||||
m_yin.setFrameSize(m_blockSize);
|
m_yin.setFrameSize(m_blockSize);
|
||||||
/*
|
/*
|
||||||
std::cerr << "YinVamp::reset: yin threshold set to " << (m_yinParameter)
|
std::cerr << "YinVamp::reset: yin threshold set to " << (m_yinParameter)
|
||||||
<< ", blockSize = " << m_blockSize
|
<< ", blockSize = " << m_blockSize
|
||||||
<< std::endl;
|
<< 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));
|
timestamp = timestamp + Vamp::RealTime::frame2RealTime(m_blockSize/2, lrintf(m_inputSampleRate));
|
||||||
FeatureSet fs;
|
FeatureSet fs;
|
||||||
|
|
||||||
double *dInputBuffers = new double[m_blockSize];
|
double *dInputBuffers = new double[m_blockSize];
|
||||||
for (size_t i = 0; i < m_blockSize; ++i) dInputBuffers[i] = inputBuffers[0][i];
|
for (size_t i = 0; i < m_blockSize; ++i) dInputBuffers[i] = inputBuffers[0][i];
|
||||||
|
|
||||||
Yin::YinOutput yo = m_yin.process(dInputBuffers);
|
Yin::YinOutput yo = m_yin.process(dInputBuffers);
|
||||||
// std::cerr << "f0 in YinVamp: " << yo.f0 << std::endl;
|
// std::cerr << "f0 in YinVamp: " << yo.f0 << std::endl;
|
||||||
Feature f;
|
Feature f;
|
||||||
@ -341,19 +341,19 @@ YinVamp::process(const float *const *inputBuffers, RealTime timestamp)
|
|||||||
f.values.clear();
|
f.values.clear();
|
||||||
f.values.push_back(yo.rms);
|
f.values.push_back(yo.rms);
|
||||||
fs[m_outNoRms].push_back(f);
|
fs[m_outNoRms].push_back(f);
|
||||||
|
|
||||||
f.values.clear();
|
f.values.clear();
|
||||||
for (size_t iBin = 0; iBin < yo.salience.size(); ++iBin)
|
for (size_t iBin = 0; iBin < yo.salience.size(); ++iBin)
|
||||||
{
|
{
|
||||||
f.values.push_back(yo.salience[iBin]);
|
f.values.push_back(yo.salience[iBin]);
|
||||||
}
|
}
|
||||||
fs[m_outNoSalience].push_back(f);
|
fs[m_outNoSalience].push_back(f);
|
||||||
|
|
||||||
f.values.clear();
|
f.values.clear();
|
||||||
// f.values[0] = yo.periodicity;
|
// f.values[0] = yo.periodicity;
|
||||||
f.values.push_back(yo.periodicity);
|
f.values.push_back(yo.periodicity);
|
||||||
fs[m_outNoPeriodicity].push_back(f);
|
fs[m_outNoPeriodicity].push_back(f);
|
||||||
|
|
||||||
delete [] dInputBuffers;
|
delete [] dInputBuffers;
|
||||||
|
|
||||||
return fs;
|
return fs;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
@ -62,7 +62,7 @@ protected:
|
|||||||
float m_fmin;
|
float m_fmin;
|
||||||
float m_fmax;
|
float m_fmax;
|
||||||
Yin m_yin;
|
Yin m_yin;
|
||||||
|
|
||||||
mutable int m_outNoF0;
|
mutable int m_outNoF0;
|
||||||
mutable int m_outNoPeriodicity;
|
mutable int m_outNoPeriodicity;
|
||||||
mutable int m_outNoRms;
|
mutable int m_outNoRms;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
pYIN - A fundamental frequency estimator for monophonic audio
|
pYIN - A fundamental frequency estimator for monophonic audio
|
||||||
Centre for Digital Music, Queen Mary, University of London.
|
Centre for Digital Music, Queen Mary, University of London.
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License as
|
modify it under the terms of the GNU General Public License as
|
||||||
published by the Free Software Foundation; either version 2 of the
|
published by the Free Software Foundation; either version 2 of the
|
||||||
|
Loading…
Reference in New Issue
Block a user