Mercurial > hg > pyin
annotate MonoNote.cpp @ 130:080fe18f5ebf fixedlag
refactored Viterbi
* perhaps I even discovered a bug (probablity sum was not reset for every frame)
author | Matthias Mauch <mail@matthiasmauch.net> |
---|---|
date | Fri, 03 Jul 2015 12:22:44 +0100 |
parents | 5945b8905d1f |
children | 926c292fa3ff |
rev | line source |
---|---|
Chris@9 | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ |
Chris@9 | 2 |
Chris@9 | 3 /* |
Chris@9 | 4 pYIN - A fundamental frequency estimator for monophonic audio |
Chris@9 | 5 Centre for Digital Music, Queen Mary, University of London. |
Chris@9 | 6 |
Chris@9 | 7 This program is free software; you can redistribute it and/or |
Chris@9 | 8 modify it under the terms of the GNU General Public License as |
Chris@9 | 9 published by the Free Software Foundation; either version 2 of the |
Chris@9 | 10 License, or (at your option) any later version. See the file |
Chris@9 | 11 COPYING included with this distribution for more information. |
Chris@9 | 12 */ |
Chris@9 | 13 |
matthiasm@0 | 14 #include "MonoNote.h" |
matthiasm@0 | 15 #include <vector> |
matthiasm@0 | 16 |
matthiasm@0 | 17 #include <cstdio> |
matthiasm@0 | 18 #include <cmath> |
matthiasm@0 | 19 #include <complex> |
matthiasm@0 | 20 |
matthiasm@0 | 21 using std::vector; |
matthiasm@0 | 22 using std::pair; |
matthiasm@0 | 23 |
matthiasm@0 | 24 MonoNote::MonoNote() : |
matthiasm@0 | 25 hmm() |
matthiasm@0 | 26 { |
matthiasm@0 | 27 } |
matthiasm@0 | 28 |
matthiasm@0 | 29 MonoNote::~MonoNote() |
matthiasm@0 | 30 { |
matthiasm@0 | 31 } |
matthiasm@0 | 32 |
matthiasm@0 | 33 const vector<MonoNote::FrameOutput> |
matthiasm@0 | 34 MonoNote::process(const vector<vector<pair<double, double> > > pitchProb) |
matthiasm@0 | 35 { |
matthiasm@0 | 36 vector<vector<double> > obsProb; |
matthiasm@0 | 37 for (size_t iFrame = 0; iFrame < pitchProb.size(); ++iFrame) |
matthiasm@0 | 38 { |
matthiasm@0 | 39 obsProb.push_back(hmm.calculateObsProb(pitchProb[iFrame])); |
matthiasm@0 | 40 } |
matthiasm@0 | 41 |
matthiasm@0 | 42 vector<MonoNote::FrameOutput> out; |
matthiasm@0 | 43 |
mail@130 | 44 vector<int> path = hmm.decodeViterbi(obsProb); |
matthiasm@0 | 45 |
matthiasm@0 | 46 for (size_t iFrame = 0; iFrame < path.size(); ++iFrame) |
matthiasm@0 | 47 { |
matthiasm@0 | 48 double currPitch = -1; |
matthiasm@0 | 49 int stateKind = 0; |
matthiasm@0 | 50 |
matthiasm@0 | 51 currPitch = hmm.par.minPitch + (path[iFrame]/hmm.par.nSPP) * 1.0/hmm.par.nPPS; |
matthiasm@0 | 52 stateKind = (path[iFrame]) % hmm.par.nSPP + 1; |
matthiasm@0 | 53 |
matthiasm@0 | 54 out.push_back(FrameOutput(iFrame, currPitch, stateKind)); |
matthiasm@0 | 55 // std::cerr << path[iFrame] << " -- "<< pitchProb[iFrame][0].first << " -- "<< currPitch << " -- " << stateKind << std::endl; |
matthiasm@0 | 56 } |
matthiasm@0 | 57 return(out); |
Chris@9 | 58 } |