Mercurial > hg > match-vamp
comparison src/Matcher.cpp @ 69:696f6e7f2f31 refactors
distYSize no longer needed, and some tidying and checks
author | Chris Cannam |
---|---|
date | Tue, 18 Nov 2014 16:35:15 +0000 |
parents | 331a17753663 |
children | cba231851957 |
comparison
equal
deleted
inserted
replaced
67:a3efb15e7faf | 69:696f6e7f2f31 |
---|---|
84 Matcher::init() | 84 Matcher::init() |
85 { | 85 { |
86 if (m_initialised) return; | 86 if (m_initialised) return; |
87 | 87 |
88 m_frames = vector<vector<double> > | 88 m_frames = vector<vector<double> > |
89 (m_blockSize, vector<double>(m_featureSize, 0)); | 89 (m_blockSize, vector<double>(m_featureSize, -1.0)); |
90 | 90 |
91 m_distXSize = m_blockSize * 2; | 91 m_distXSize = m_blockSize * 2; |
92 | 92 |
93 size(); | 93 size(); |
94 | 94 |
103 { | 103 { |
104 int distSize = (m_params.maxRunCount + 1) * m_blockSize; | 104 int distSize = (m_params.maxRunCount + 1) * m_blockSize; |
105 m_bestPathCost.resize(m_distXSize, vector<double>(distSize, 0)); | 105 m_bestPathCost.resize(m_distXSize, vector<double>(distSize, 0)); |
106 m_distance.resize(m_distXSize, vector<float>(distSize, 0)); | 106 m_distance.resize(m_distXSize, vector<float>(distSize, 0)); |
107 m_advance.resize(m_distXSize, vector<Advance>(distSize, AdvanceNone)); | 107 m_advance.resize(m_distXSize, vector<Advance>(distSize, AdvanceNone)); |
108 m_distYSizes.resize(m_distXSize, distSize); | |
109 m_first.resize(m_distXSize, 0); | 108 m_first.resize(m_distXSize, 0); |
110 m_last.resize(m_distXSize, 0); | 109 m_last.resize(m_distXSize, 0); |
111 } | 110 } |
112 | 111 |
113 vector<double> | 112 vector<double> |
151 | 150 |
152 // We need to copy distance[m_frameCount-m_blockSize] to | 151 // We need to copy distance[m_frameCount-m_blockSize] to |
153 // distance[m_frameCount], and then truncate | 152 // distance[m_frameCount], and then truncate |
154 // distance[m_frameCount-m_blockSize] to its first len elements. | 153 // distance[m_frameCount-m_blockSize] to its first len elements. |
155 // Same for bestPathCost. | 154 // Same for bestPathCost. |
156 /* | 155 |
157 std::cerr << "Matcher(" << this << "): moving " << distYSizes[m_frameCount - m_blockSize] << " from " << m_frameCount - m_blockSize << " to " | 156 vector<float> dOld = m_distance[m_frameCount - m_blockSize]; |
158 << m_frameCount << ", allocating " << len << " for " | 157 vector<float> dNew(len, 0.f); |
159 << m_frameCount - m_blockSize << std::endl; | 158 |
160 */ | 159 vector<double> bpcOld = m_bestPathCost[m_frameCount - m_blockSize]; |
161 m_distance[m_frameCount] = m_distance[m_frameCount - m_blockSize]; | 160 vector<double> bpcNew(len, 0.0); |
162 m_distance[m_frameCount - m_blockSize].resize(len, 0); | 161 |
163 | 162 vector<Advance> adOld = m_advance[m_frameCount - m_blockSize]; |
164 m_bestPathCost[m_frameCount] = m_bestPathCost[m_frameCount - m_blockSize]; | 163 vector<Advance> adNew(len, AdvanceNone); |
165 m_bestPathCost[m_frameCount - m_blockSize].resize(len, 0); | 164 |
166 | 165 for (int i = 0; i < len; ++i) { |
167 m_advance[m_frameCount] = m_advance[m_frameCount - m_blockSize]; | 166 dNew[i] = dOld[i]; |
168 m_advance[m_frameCount - m_blockSize].resize(len, AdvanceNone); | 167 bpcNew[i] = bpcOld[i]; |
168 adNew[i] = adOld[i]; | |
169 } | |
169 | 170 |
170 m_distYSizes[m_frameCount] = m_distYSizes[m_frameCount - m_blockSize]; | 171 m_distance[m_frameCount] = dOld; |
171 m_distYSizes[m_frameCount - m_blockSize] = len; | 172 m_distance[m_frameCount - m_blockSize] = dNew; |
173 | |
174 m_bestPathCost[m_frameCount] = bpcOld; | |
175 m_bestPathCost[m_frameCount - m_blockSize] = bpcNew; | |
176 | |
177 m_advance[m_frameCount] = adOld; | |
178 m_advance[m_frameCount - m_blockSize] = adNew; | |
172 } | 179 } |
173 | 180 |
174 int stop = m_otherMatcher->m_frameCount; | 181 int stop = m_otherMatcher->m_frameCount; |
175 int index = stop - m_blockSize; | 182 int index = stop - m_blockSize; |
176 if (index < 0) | 183 if (index < 0) |
270 dir = AdvanceThis; | 277 dir = AdvanceThis; |
271 } | 278 } |
272 | 279 |
273 int idx = i - m_otherMatcher->m_first[j]; | 280 int idx = i - m_otherMatcher->m_first[j]; |
274 | 281 |
275 if (idx == (int)m_otherMatcher->m_distYSizes[j]) { | 282 if (idx == (int)m_otherMatcher->m_distance[j].size()) { |
276 // This should never happen, but if we allow arbitrary | 283 // This should never happen, but if we allow arbitrary |
277 // pauses in either direction, and arbitrary lengths at | 284 // pauses in either direction, and arbitrary lengths at |
278 // end, it is better than a segmentation fault. | 285 // end, it is better than a segmentation fault. |
279 std::cerr << "Emergency resize: " << idx << " -> " << idx * 2 << std::endl; | 286 std::cerr << "Emergency resize: " << idx << " -> " << idx * 2 << std::endl; |
280 m_otherMatcher->m_distYSizes[j] = idx * 2; | |
281 m_otherMatcher->m_bestPathCost[j].resize(idx * 2, 0); | 287 m_otherMatcher->m_bestPathCost[j].resize(idx * 2, 0); |
282 m_otherMatcher->m_distance[j].resize(idx * 2, 0); | 288 m_otherMatcher->m_distance[j].resize(idx * 2, 0); |
283 m_otherMatcher->m_advance[j].resize(idx * 2, AdvanceNone); | 289 m_otherMatcher->m_advance[j].resize(idx * 2, AdvanceNone); |
284 } | 290 } |
285 | 291 |