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<double> *scale = new vector<double>(pitchProb.size());
|
matthiasm@0
|
43
|
matthiasm@0
|
44 vector<MonoNote::FrameOutput> out;
|
matthiasm@0
|
45
|
matthiasm@0
|
46 vector<int> path = hmm.decodeViterbi(obsProb, scale);
|
matthiasm@0
|
47
|
matthiasm@0
|
48 for (size_t iFrame = 0; iFrame < path.size(); ++iFrame)
|
matthiasm@0
|
49 {
|
matthiasm@0
|
50 double currPitch = -1;
|
matthiasm@0
|
51 int stateKind = 0;
|
matthiasm@0
|
52
|
matthiasm@0
|
53 currPitch = hmm.par.minPitch + (path[iFrame]/hmm.par.nSPP) * 1.0/hmm.par.nPPS;
|
matthiasm@0
|
54 stateKind = (path[iFrame]) % hmm.par.nSPP + 1;
|
matthiasm@0
|
55
|
matthiasm@0
|
56 out.push_back(FrameOutput(iFrame, currPitch, stateKind));
|
matthiasm@0
|
57 // std::cerr << path[iFrame] << " -- "<< pitchProb[iFrame][0].first << " -- "<< currPitch << " -- " << stateKind << std::endl;
|
matthiasm@0
|
58 }
|
matthiasm@0
|
59 delete scale;
|
matthiasm@0
|
60 return(out);
|
Chris@9
|
61 }
|