changeset 772:8280f7a363d1 pitch-align

Prefer diagonal if the cost is the same - this makes the results the same as our earlier test aligner
author Chris Cannam
date Mon, 01 Jun 2020 17:12:12 +0100
parents 1d6cca5a5621
children 699b5b130ea2
files align/DTW.h
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/align/DTW.h	Fri May 29 17:39:02 2020 +0100
+++ b/align/DTW.h	Mon Jun 01 17:12:12 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;
                 }
             }