Mercurial > hg > svcore
comparison data/model/AlignmentModel.cpp @ 312:df707a61b23f
* interpolate in AlignmentModel
author | Chris Cannam |
---|---|
date | Wed, 10 Oct 2007 16:21:27 +0000 |
parents | c022976d18e8 |
children | 29485aa03da4 |
comparison
equal
deleted
inserted
replaced
311:1c9143b2b658 | 312:df707a61b23f |
---|---|
175 float rvalue = (float)frame / (float)m_reference->getSampleRate(); | 175 float rvalue = (float)frame / (float)m_reference->getSampleRate(); |
176 m_reversePath->addPoint | 176 m_reversePath->addPoint |
177 (SparseTimeValueModel::Point(rframe, rvalue, "")); | 177 (SparseTimeValueModel::Point(rframe, rvalue, "")); |
178 } | 178 } |
179 | 179 |
180 std::cerr << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points" << std::endl; | 180 std::cerr << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points, at least " << (2 * m_reversePath->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(SparseTimeValueModel::Point))) << " bytes" << std::endl; |
181 } | 181 } |
182 | 182 |
183 size_t | 183 size_t |
184 AlignmentModel::align(SparseTimeValueModel *path, size_t frame) const | 184 AlignmentModel::align(SparseTimeValueModel *path, size_t frame) const |
185 { | 185 { |
196 } | 196 } |
197 | 197 |
198 SparseTimeValueModel::Point point(frame); | 198 SparseTimeValueModel::Point point(frame); |
199 SparseTimeValueModel::PointList::const_iterator i = points.lower_bound(point); | 199 SparseTimeValueModel::PointList::const_iterator i = points.lower_bound(point); |
200 if (i == points.end()) --i; | 200 if (i == points.end()) --i; |
201 float time = i->value; | 201 while (i != points.begin() && i->frame > frame) --i; |
202 size_t rv = lrintf(time * getSampleRate()); | 202 |
203 | 203 long foundFrame = i->frame; |
204 //!!! interpolate! | 204 float foundTime = i->value; |
205 | 205 |
206 // std::cerr << "AlignmentModel::align: rv = " << rv << std::endl; | 206 long followingFrame = foundFrame; |
207 | 207 float followingTime = foundTime; |
208 return rv; | 208 |
209 if (++i != points.end()) { | |
210 followingFrame = i->frame; | |
211 followingTime = i->value; | |
212 } | |
213 | |
214 float resultTime = foundTime; | |
215 | |
216 if (followingFrame != foundFrame && frame > foundFrame) { | |
217 | |
218 std::cerr << "AlignmentModel::align: foundFrame = " << foundFrame << ", frame = " << frame << ", followingFrame = " << followingFrame << std::endl; | |
219 | |
220 float interp = float(frame - foundFrame) / float(followingFrame - foundFrame); | |
221 std::cerr << "AlignmentModel::align: interp = " << interp << ", result " << resultTime << " -> "; | |
222 | |
223 resultTime += (followingTime - foundTime) * interp; | |
224 | |
225 std::cerr << resultTime << std::endl; | |
226 } | |
227 | |
228 size_t resultFrame = lrintf(resultTime * getSampleRate()); | |
229 | |
230 std::cerr << "AlignmentModel::align: resultFrame = " << resultFrame << std::endl; | |
231 | |
232 return resultFrame; | |
209 } | 233 } |
210 | 234 |