diff data/model/AggregateWaveModel.cpp @ 1008:d9e0e59a1581

When using an aggregate model to pass data to a transform, zero-pad the shorter input to the duration of the longer rather than truncating the longer. (This is better behaviour for e.g. MATCH, and in any case the code was previously truncating incorrectly and ending up with garbage data at the end.)
author Chris Cannam
date Fri, 14 Nov 2014 13:51:33 +0000
parents cd42620e3f40
children cc27f35aa75c
line wrap: on
line diff
--- a/data/model/AggregateWaveModel.cpp	Wed Oct 15 17:02:48 2014 +0100
+++ b/data/model/AggregateWaveModel.cpp	Fri Nov 14 13:51:33 2014 +0000
@@ -118,14 +118,21 @@
         }
     }
 
-    int sz = count;
-
+    int longest = 0;
+    
     for (int c = ch0; c <= ch1; ++c) {
-        int szHere = 
+        int here = 
             m_components[c].model->getData(m_components[c].channel,
                                            start, count,
                                            readbuf);
-        if (szHere < sz) sz = szHere;
+        if (here > longest) {
+            longest = here;
+        }
+        if (here < count) {
+            for (int i = here; i < count; ++i) {
+                readbuf[i] = 0.f;
+            }
+        }
         if (mixing) {
             for (int i = 0; i < count; ++i) {
                 buffer[i] += readbuf[i];
@@ -134,7 +141,7 @@
     }
 
     if (mixing) delete[] readbuf;
-    return sz;
+    return longest;
 }
          
 int
@@ -157,14 +164,21 @@
         }
     }
 
-    int sz = count;
+    int longest = 0;
     
     for (int c = ch0; c <= ch1; ++c) {
-        int szHere = 
+        int here = 
             m_components[c].model->getData(m_components[c].channel,
                                            start, count,
                                            readbuf);
-        if (szHere < sz) sz = szHere;
+        if (here > longest) {
+            longest = here;
+        }
+        if (here < count) {
+            for (int i = here; i < count; ++i) {
+                readbuf[i] = 0.;
+            }
+        }
         if (mixing) {
             for (int i = 0; i < count; ++i) {
                 buffer[i] += readbuf[i];
@@ -173,7 +187,7 @@
     }
     
     if (mixing) delete[] readbuf;
-    return sz;
+    return longest;
 }
 
 int