Mercurial > hg > svcore
comparison data/model/AlignmentModel.cpp @ 376:ab24af1271e9
* just some debug stuff
author | Chris Cannam |
---|---|
date | Thu, 07 Feb 2008 12:36:59 +0000 |
parents | d77e1fa49e26 |
children | 62789d79b98f |
comparison
equal
deleted
inserted
replaced
375:f1ff248a793e | 376:ab24af1271e9 |
---|---|
15 | 15 |
16 #include "AlignmentModel.h" | 16 #include "AlignmentModel.h" |
17 | 17 |
18 #include "SparseTimeValueModel.h" | 18 #include "SparseTimeValueModel.h" |
19 | 19 |
20 //#define DEBUG_ALIGNMENT_MODEL 1 | |
21 | |
20 AlignmentModel::AlignmentModel(Model *reference, | 22 AlignmentModel::AlignmentModel(Model *reference, |
21 Model *aligned, | 23 Model *aligned, |
22 Model *inputModel, | 24 Model *inputModel, |
23 SparseTimeValueModel *path) : | 25 SparseTimeValueModel *path) : |
24 m_reference(reference), | 26 m_reference(reference), |
125 } | 127 } |
126 | 128 |
127 size_t | 129 size_t |
128 AlignmentModel::toReference(size_t frame) const | 130 AlignmentModel::toReference(size_t frame) const |
129 { | 131 { |
130 // std::cerr << "AlignmentModel::toReference(" << frame << ")" << std::endl; | 132 #ifdef DEBUG_ALIGNMENT_MODEL |
133 std::cerr << "AlignmentModel::toReference(" << frame << ")" << std::endl; | |
134 #endif | |
131 if (!m_path) { | 135 if (!m_path) { |
132 if (!m_rawPath) return frame; | 136 if (!m_rawPath) return frame; |
133 constructPath(); | 137 constructPath(); |
134 } | 138 } |
135 return align(m_path, frame); | 139 return align(m_path, frame); |
136 } | 140 } |
137 | 141 |
138 size_t | 142 size_t |
139 AlignmentModel::fromReference(size_t frame) const | 143 AlignmentModel::fromReference(size_t frame) const |
140 { | 144 { |
141 // std::cerr << "AlignmentModel::fromReference(" << frame << ")" << std::endl; | 145 #ifdef DEBUG_ALIGNMENT_MODEL |
146 std::cerr << "AlignmentModel::fromReference(" << frame << ")" << std::endl; | |
147 #endif | |
142 if (!m_reversePath) { | 148 if (!m_reversePath) { |
143 if (!m_rawPath) return frame; | 149 if (!m_rawPath) return frame; |
144 constructReversePath(); | 150 constructReversePath(); |
145 } | 151 } |
146 return align(m_reversePath, frame); | 152 return align(m_reversePath, frame); |
173 if (!m_pathComplete) { | 179 if (!m_pathComplete) { |
174 | 180 |
175 int completion = 0; | 181 int completion = 0; |
176 m_rawPath->isReady(&completion); | 182 m_rawPath->isReady(&completion); |
177 | 183 |
178 // std::cerr << "AlignmentModel::pathCompletionChanged: completion = " | 184 #ifdef DEBUG_ALIGNMENT_MODEL |
179 // << completion << std::endl; | 185 std::cerr << "AlignmentModel::pathCompletionChanged: completion = " |
186 << completion << std::endl; | |
187 #endif | |
180 | 188 |
181 m_pathComplete = (completion == 100); | 189 m_pathComplete = (completion == 100); |
182 | 190 |
183 if (m_pathComplete) { | 191 if (m_pathComplete) { |
184 | 192 |
218 float value = i->value; | 226 float value = i->value; |
219 long rframe = lrintf(value * m_aligned->getSampleRate()); | 227 long rframe = lrintf(value * m_aligned->getSampleRate()); |
220 m_path->addPoint(PathPoint(frame, rframe)); | 228 m_path->addPoint(PathPoint(frame, rframe)); |
221 } | 229 } |
222 | 230 |
223 // std::cerr << "AlignmentModel::constructPath: " << m_path->getPointCount() << " points, at least " << (2 * m_path->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; | 231 #ifdef DEBUG_ALIGNMENT_MODEL |
232 std::cerr << "AlignmentModel::constructPath: " << m_path->getPointCount() << " points, at least " << (2 * m_path->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; | |
233 #endif | |
224 } | 234 } |
225 | 235 |
226 void | 236 void |
227 AlignmentModel::constructReversePath() const | 237 AlignmentModel::constructReversePath() const |
228 { | 238 { |
248 float value = i->value; | 258 float value = i->value; |
249 long rframe = lrintf(value * m_aligned->getSampleRate()); | 259 long rframe = lrintf(value * m_aligned->getSampleRate()); |
250 m_reversePath->addPoint(PathPoint(rframe, frame)); | 260 m_reversePath->addPoint(PathPoint(rframe, frame)); |
251 } | 261 } |
252 | 262 |
253 // std::cerr << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points, at least " << (2 * m_reversePath->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; | 263 #ifdef DEBUG_ALIGNMENT_MODEL |
264 std::cerr << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points, at least " << (2 * m_reversePath->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; | |
265 #endif | |
254 } | 266 } |
255 | 267 |
256 size_t | 268 size_t |
257 AlignmentModel::align(PathModel *path, size_t frame) const | 269 AlignmentModel::align(PathModel *path, size_t frame) const |
258 { | 270 { |
264 // increasing. | 276 // increasing. |
265 | 277 |
266 const PathModel::PointList &points = path->getPoints(); | 278 const PathModel::PointList &points = path->getPoints(); |
267 | 279 |
268 if (points.empty()) { | 280 if (points.empty()) { |
269 // std::cerr << "AlignmentModel::align: No points" << std::endl; | 281 std::cerr << "AlignmentModel::align: No points" << std::endl; |
270 return frame; | 282 return frame; |
271 } | 283 } |
272 | 284 |
285 #ifdef DEBUG_ALIGNMENT_MODEL | |
286 std::cerr << "AlignmentModel::align: frame " << frame << " requested" << std::endl; | |
287 #endif | |
288 | |
273 PathModel::Point point(frame); | 289 PathModel::Point point(frame); |
274 PathModel::PointList::const_iterator i = points.lower_bound(point); | 290 PathModel::PointList::const_iterator i = points.lower_bound(point); |
275 if (i == points.end()) --i; | 291 if (i == points.end()) { |
292 #ifdef DEBUG_ALIGNMENT_MODEL | |
293 std::cerr << "Note: i == points.end()" << std::endl; | |
294 #endif | |
295 --i; | |
296 } | |
276 while (i != points.begin() && i->frame > long(frame)) --i; | 297 while (i != points.begin() && i->frame > long(frame)) --i; |
277 | 298 |
278 long foundFrame = i->frame; | 299 long foundFrame = i->frame; |
279 long foundMapFrame = i->mapframe; | 300 long foundMapFrame = i->mapframe; |
280 | 301 |
281 long followingFrame = foundFrame; | 302 long followingFrame = foundFrame; |
282 long followingMapFrame = foundMapFrame; | 303 long followingMapFrame = foundMapFrame; |
283 | 304 |
284 if (++i != points.end()) { | 305 if (++i != points.end()) { |
306 #ifdef DEBUG_ALIGNMENT_MODEL | |
307 std::cerr << "another point available" << std::endl; | |
308 #endif | |
285 followingFrame = i->frame; | 309 followingFrame = i->frame; |
286 followingMapFrame = i->mapframe; | 310 followingMapFrame = i->mapframe; |
287 } | 311 } else { |
312 #ifdef DEBUG_ALIGNMENT_MODEL | |
313 std::cerr << "no other point available" << std::endl; | |
314 #endif | |
315 } | |
288 | 316 |
289 if (foundMapFrame < 0) return 0; | 317 if (foundMapFrame < 0) return 0; |
290 | 318 |
291 size_t resultFrame = foundMapFrame; | 319 size_t resultFrame = foundMapFrame; |
292 | 320 |
295 float(frame - foundFrame) / | 323 float(frame - foundFrame) / |
296 float(followingFrame - foundFrame); | 324 float(followingFrame - foundFrame); |
297 resultFrame += lrintf((followingMapFrame - foundMapFrame) * interp); | 325 resultFrame += lrintf((followingMapFrame - foundMapFrame) * interp); |
298 } | 326 } |
299 | 327 |
300 // std::cerr << "AlignmentModel::align: resultFrame = " << resultFrame << std::endl; | 328 #ifdef DEBUG_ALIGNMENT_MODEL |
329 std::cerr << "AlignmentModel::align: resultFrame = " << resultFrame << std::endl; | |
330 #endif | |
301 | 331 |
302 return resultFrame; | 332 return resultFrame; |
303 } | 333 } |
304 | 334 |