comparison LocalCandidatePYIN.cpp @ 132:926c292fa3ff fixedlag

fixed lag smoothing for pitch track working
author Matthias Mauch <mail@matthiasmauch.net>
date Fri, 03 Jul 2015 17:34:38 +0100
parents c3a4aa614e33
children 72bda34e0e64
comparison
equal deleted inserted replaced
131:b877df85ad9e 132:926c292fa3ff
10 License, or (at your option) any later version. See the file 10 License, or (at your option) any later version. See the file
11 COLocalCandidatePYING included with this distribution for more information. 11 COLocalCandidatePYING included with this distribution for more information.
12 */ 12 */
13 13
14 #include "LocalCandidatePYIN.h" 14 #include "LocalCandidatePYIN.h"
15 #include "MonoPitch.h" 15 #include "MonoPitchHMM.h"
16 #include "YinUtil.h" 16 #include "YinUtil.h"
17 17
18 #include "vamp-sdk/FFT.h" 18 #include "vamp-sdk/FFT.h"
19 19
20 #include <vector> 20 #include <vector>
343 if (m_pitchProb.empty()) { 343 if (m_pitchProb.empty()) {
344 return FeatureSet(); 344 return FeatureSet();
345 } 345 }
346 346
347 // MONO-PITCH STUFF 347 // MONO-PITCH STUFF
348 MonoPitch mp; 348 MonoPitchHMM hmm(0);
349 size_t nFrame = m_timestamp.size(); 349 size_t nFrame = m_timestamp.size();
350 vector<vector<float> > pitchTracks; 350 vector<vector<float> > pitchTracks;
351 vector<float> freqSum = vector<float>(m_nCandidate); 351 vector<float> freqSum = vector<float>(m_nCandidate);
352 vector<float> freqNumber = vector<float>(m_nCandidate); 352 vector<float> freqNumber = vector<float>(m_nCandidate);
353 vector<float> freqMean = vector<float>(m_nCandidate); 353 vector<float> freqMean = vector<float>(m_nCandidate);
357 357
358 // Viterbi-decode multiple times with different frequencies emphasised 358 // Viterbi-decode multiple times with different frequencies emphasised
359 for (size_t iCandidate = 0; iCandidate < m_nCandidate; ++iCandidate) 359 for (size_t iCandidate = 0; iCandidate < m_nCandidate; ++iCandidate)
360 { 360 {
361 pitchTracks.push_back(vector<float>(nFrame)); 361 pitchTracks.push_back(vector<float>(nFrame));
362 vector<vector<pair<double,double> > > tempPitchProb; 362 vector<pair<double,double> > tempPitchProb;
363 vector<vector<double> > tempObsProb;
363 float centrePitch = 45 + 3 * iCandidate; 364 float centrePitch = 45 + 3 * iCandidate;
364 365
365 for (size_t iFrame = 0; iFrame < nFrame; ++iFrame) { 366 for (size_t iFrame = 0; iFrame < nFrame; ++iFrame) {
366 tempPitchProb.push_back(vector<pair<double,double> >());
367 float sumProb = 0; 367 float sumProb = 0;
368 float pitch = 0; 368 float pitch = 0;
369 float prob = 0; 369 float prob = 0;
370 for (size_t iProb = 0; iProb < m_pitchProb[iFrame].size(); ++iProb) 370 for (size_t iProb = 0; iProb < m_pitchProb[iFrame].size(); ++iProb)
371 { 371 {
372 pitch = m_pitchProb[iFrame][iProb].first; 372 pitch = m_pitchProb[iFrame][iProb].first;
373 prob = m_pitchProb[iFrame][iProb].second * 373 prob = m_pitchProb[iFrame][iProb].second *
374 boost::math::pdf(normalDist, pitch-centrePitch) / 374 boost::math::pdf(normalDist, pitch-centrePitch) /
375 maxNormalDist * 2; 375 maxNormalDist * 2;
376 sumProb += prob; 376 sumProb += prob;
377 tempPitchProb[iFrame].push_back( 377 tempPitchProb.push_back(
378 pair<double,double>(pitch,prob)); 378 pair<double,double>(pitch,prob));
379 } 379 }
380 for (size_t iProb = 0; iProb < m_pitchProb[iFrame].size(); ++iProb) 380 for (size_t iProb = 0; iProb < m_pitchProb[iFrame].size(); ++iProb)
381 { 381 {
382 tempPitchProb[iFrame][iProb].second /= sumProb; 382 tempPitchProb[iProb].second /= sumProb;
383 } 383 }
384 } 384 tempObsProb.push_back(hmm.calculateObsProb(tempPitchProb));
385 385 }
386 vector<float> mpOut = mp.process(tempPitchProb); 386
387 vector<int> rawPitchPath = hmm.decodeViterbi(tempObsProb);
388 vector<float> mpOut;
389
390 for (size_t iFrame = 0; iFrame < rawPitchPath.size(); ++iFrame)
391 {
392 float freq = hmm.nearestFreq(rawPitchPath[iFrame],
393 m_pitchProb[iFrame]);
394 mpOut.push_back(freq); // for note processing below
395 }
396
387 float prevFreq = 0; 397 float prevFreq = 0;
388 for (size_t iFrame = 0; iFrame < nFrame; ++iFrame) 398 for (size_t iFrame = 0; iFrame < nFrame; ++iFrame)
389 { 399 {
390 if (mpOut[iFrame] > 0) { 400 if (mpOut[iFrame] > 0) {
391 401