Mercurial > hg > pyin
annotate MonoNote.cpp @ 0:99bac62ee2da
added PYIN sources, should be compileable
author | matthiasm |
---|---|
date | Wed, 27 Nov 2013 11:59:49 +0000 |
parents | |
children | 5945b8905d1f |
rev | line source |
---|---|
matthiasm@0 | 1 #include "MonoNote.h" |
matthiasm@0 | 2 #include <vector> |
matthiasm@0 | 3 |
matthiasm@0 | 4 #include <cstdio> |
matthiasm@0 | 5 #include <cmath> |
matthiasm@0 | 6 #include <complex> |
matthiasm@0 | 7 |
matthiasm@0 | 8 using std::vector; |
matthiasm@0 | 9 using std::pair; |
matthiasm@0 | 10 |
matthiasm@0 | 11 MonoNote::MonoNote() : |
matthiasm@0 | 12 hmm() |
matthiasm@0 | 13 { |
matthiasm@0 | 14 } |
matthiasm@0 | 15 |
matthiasm@0 | 16 MonoNote::~MonoNote() |
matthiasm@0 | 17 { |
matthiasm@0 | 18 } |
matthiasm@0 | 19 |
matthiasm@0 | 20 const vector<MonoNote::FrameOutput> |
matthiasm@0 | 21 MonoNote::process(const vector<vector<pair<double, double> > > pitchProb) |
matthiasm@0 | 22 { |
matthiasm@0 | 23 vector<vector<double> > obsProb; |
matthiasm@0 | 24 for (size_t iFrame = 0; iFrame < pitchProb.size(); ++iFrame) |
matthiasm@0 | 25 { |
matthiasm@0 | 26 obsProb.push_back(hmm.calculateObsProb(pitchProb[iFrame])); |
matthiasm@0 | 27 } |
matthiasm@0 | 28 |
matthiasm@0 | 29 vector<double> *scale = new vector<double>(pitchProb.size()); |
matthiasm@0 | 30 |
matthiasm@0 | 31 vector<MonoNote::FrameOutput> out; |
matthiasm@0 | 32 |
matthiasm@0 | 33 vector<int> path = hmm.decodeViterbi(obsProb, scale); |
matthiasm@0 | 34 |
matthiasm@0 | 35 for (size_t iFrame = 0; iFrame < path.size(); ++iFrame) |
matthiasm@0 | 36 { |
matthiasm@0 | 37 double currPitch = -1; |
matthiasm@0 | 38 int stateKind = 0; |
matthiasm@0 | 39 |
matthiasm@0 | 40 currPitch = hmm.par.minPitch + (path[iFrame]/hmm.par.nSPP) * 1.0/hmm.par.nPPS; |
matthiasm@0 | 41 stateKind = (path[iFrame]) % hmm.par.nSPP + 1; |
matthiasm@0 | 42 |
matthiasm@0 | 43 out.push_back(FrameOutput(iFrame, currPitch, stateKind)); |
matthiasm@0 | 44 // std::cerr << path[iFrame] << " -- "<< pitchProb[iFrame][0].first << " -- "<< currPitch << " -- " << stateKind << std::endl; |
matthiasm@0 | 45 } |
matthiasm@0 | 46 delete scale; |
matthiasm@0 | 47 return(out); |
matthiasm@0 | 48 } |