diff align/DTW.h @ 778:83a7b10b7415

Merge from branch pitch-align
author Chris Cannam
date Fri, 26 Jun 2020 13:48:52 +0100
parents 8280f7a363d1
children 8fa98f89eda8
line wrap: on
line diff
--- a/align/DTW.h	Wed Jun 03 13:58:29 2020 +0100
+++ b/align/DTW.h	Fri Jun 26 13:48:52 2020 +0100
@@ -18,6 +18,8 @@
 #include <vector>
 #include <functional>
 
+//#define DEBUG_DTW 1
+
 template <typename Value>
 class DTW
 {
@@ -38,6 +40,16 @@
 
         auto costs = costSeries(s1, s2);
 
+#ifdef DEBUG_DTW
+        SVCERR << "Cost matrix:" << endl;
+        for (auto v: costs) {
+            for (auto x: v) {
+                SVCERR << x << " ";
+            }
+            SVCERR << "\n";
+        }
+#endif
+        
         size_t j = s1.size() - 1;
         size_t i = s2.size() - 1;
 
@@ -51,12 +63,12 @@
 
             if (a < b) {
                 --j;
-                if (both < a) {
+                if (both <= a) {
                     --i;
                 }
             } else {
                 --i;
-                if (both < b) {
+                if (both <= b) {
                     --j;
                 }
             }
@@ -189,4 +201,11 @@
     }
 };
 
+inline std::ostream &operator<<(std::ostream &s, const RiseFallDTW::Value v) {
+    return (s <<
+            (v.direction == RiseFallDTW::Direction::None ? "=" :
+             v.direction == RiseFallDTW::Direction::Up ? "+" : "-")
+            << v.distance);
+}
+
 #endif