Mercurial > hg > pyin
comparison MonoNote.cpp @ 150:729cc1da9b8d memory
Use fixed-lag HMM in note tracking as well (when fixed-lag mode is selected)
author | Chris Cannam |
---|---|
date | Wed, 17 May 2017 16:29:43 +0100 |
parents | 8404827a4b02 |
children |
comparison
equal
deleted
inserted
replaced
149:b83e6fbe22cc | 150:729cc1da9b8d |
---|---|
19 #include <complex> | 19 #include <complex> |
20 | 20 |
21 using std::vector; | 21 using std::vector; |
22 using std::pair; | 22 using std::pair; |
23 | 23 |
24 MonoNote::MonoNote() : | 24 MonoNote::MonoNote(bool fixedLag) : |
25 hmm(0) | 25 m_fixedLag(fixedLag), |
26 hmm(m_fixedLag ? 1000 : 0) | |
26 { | 27 { |
27 } | 28 } |
28 | 29 |
29 MonoNote::~MonoNote() | 30 MonoNote::~MonoNote() |
30 { | 31 { |
47 // Since the matrix is very sparse, we can avoid some of this by | 48 // Since the matrix is very sparse, we can avoid some of this by |
48 // feeding the (sparse implementation of) HMM one column at a | 49 // feeding the (sparse implementation of) HMM one column at a |
49 // time. | 50 // time. |
50 | 51 |
51 vector<int> path; | 52 vector<int> path; |
53 path.reserve(pitchProb.size()); | |
52 | 54 |
53 if (!pitchProb.empty()) { | 55 if (!pitchProb.empty()) { |
54 | 56 |
55 hmm.initialise(hmm.calculateObsProb(pitchProb[0])); | 57 hmm.initialise(hmm.calculateObsProb(pitchProb[0])); |
56 | 58 |
57 for (size_t iFrame = 1; iFrame < pitchProb.size(); ++iFrame) | 59 for (size_t iFrame = 1; iFrame < pitchProb.size(); ++iFrame) |
58 { | 60 { |
61 if (m_fixedLag && (int(iFrame) >= hmm.m_fixedLag)) | |
62 { | |
63 vector<int> rawPath = hmm.track(); | |
64 path.push_back(rawPath[0]); | |
65 } | |
66 | |
59 hmm.process(hmm.calculateObsProb(pitchProb[iFrame])); | 67 hmm.process(hmm.calculateObsProb(pitchProb[iFrame])); |
60 } | 68 } |
61 | 69 |
62 path = hmm.track(); | 70 vector<int> rawPath = hmm.track(); |
71 path.insert(path.end(), rawPath.begin(), rawPath.end()); | |
63 } | 72 } |
64 | 73 |
65 vector<MonoNote::FrameOutput> out; | 74 vector<MonoNote::FrameOutput> out; |
75 out.reserve(path.size()); | |
66 | 76 |
67 for (size_t iFrame = 0; iFrame < path.size(); ++iFrame) | 77 for (size_t iFrame = 0; iFrame < path.size(); ++iFrame) |
68 { | 78 { |
69 double currPitch = -1; | 79 double currPitch = -1; |
70 int stateKind = 0; | 80 int stateKind = 0; |