changeset 312:df707a61b23f

* interpolate in AlignmentModel
author Chris Cannam
date Wed, 10 Oct 2007 16:21:27 +0000
parents 1c9143b2b658
children 29485aa03da4
files data/model/AlignmentModel.cpp
diffstat 1 files changed, 30 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/data/model/AlignmentModel.cpp	Wed Oct 10 15:32:16 2007 +0000
+++ b/data/model/AlignmentModel.cpp	Wed Oct 10 16:21:27 2007 +0000
@@ -177,7 +177,7 @@
             (SparseTimeValueModel::Point(rframe, rvalue, ""));
     }
 
-    std::cerr << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points" << std::endl;
+    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;
 }
 
 size_t
@@ -198,13 +198,37 @@
     SparseTimeValueModel::Point point(frame);
     SparseTimeValueModel::PointList::const_iterator i = points.lower_bound(point);
     if (i == points.end()) --i;
-    float time = i->value;
-    size_t rv = lrintf(time * getSampleRate());
+    while (i != points.begin() && i->frame > frame) --i;
 
-    //!!! interpolate!
+    long foundFrame = i->frame;
+    float foundTime = i->value;
 
-//    std::cerr << "AlignmentModel::align: rv = " << rv << std::endl;
+    long followingFrame = foundFrame;
+    float followingTime = foundTime;
 
-    return rv;
+    if (++i != points.end()) {
+        followingFrame = i->frame;
+        followingTime = i->value;
+    }
+
+    float resultTime = foundTime;
+
+    if (followingFrame != foundFrame && frame > foundFrame) {
+
+        std::cerr << "AlignmentModel::align: foundFrame = " << foundFrame << ", frame = " << frame << ", followingFrame = " << followingFrame << std::endl;
+
+        float interp = float(frame - foundFrame) / float(followingFrame - foundFrame);
+        std::cerr << "AlignmentModel::align: interp = " << interp << ", result " << resultTime << " -> ";
+
+        resultTime += (followingTime - foundTime) * interp;
+
+        std::cerr << resultTime << std::endl;
+    }
+
+    size_t resultFrame = lrintf(resultTime * getSampleRate());
+
+    std::cerr << "AlignmentModel::align: resultFrame = " << resultFrame << std::endl;
+
+    return resultFrame;
 }