changeset 290:21ec05237c1a

Revise overlap-add
author Chris Cannam
date Fri, 31 May 2013 10:58:00 +0100
parents b34960d2b519
children c40821ff70f8
files yetilab/matrix.yeti yetilab/stream/framer.yeti yetilab/stream/test/test_framer.yeti yetilab/vector.yeti
diffstat 4 files changed, 45 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/yetilab/matrix.yeti	Thu May 30 22:33:16 2013 +0100
+++ b/yetilab/matrix.yeti	Fri May 31 10:58:00 2013 +0100
@@ -609,7 +609,7 @@
         failWith "Matrix dimensions incompatible for concat (found \(map do m: counter (size m) done mm) not all of which are \(n))";
     fi);
 
-concat' direction mm = //!!! doc: storage order is taken from first matrix in sequence
+concat' direction mm = //!!! doc: storage order is taken from first matrix in sequence; concat is obviously not lazy (unlike std module)
     case length mm of
     0: zeroSizeMatrix ();
     1: head mm;
--- a/yetilab/stream/framer.yeti	Thu May 30 22:33:16 2013 +0100
+++ b/yetilab/stream/framer.yeti	Fri May 31 10:58:00 2013 +0100
@@ -94,17 +94,24 @@
         close = \(),
     });
 
-overlapAdd channels framesize hop frames =
+overlapAdd channels overlap frames =
    (ola fr acc =
         if empty? fr then
            [acc]
         else
+            pre = mat.columnSlice acc 0 (mat.width acc - overlap);
+            added = mat.sum (head fr) 
+               (mat.resizedTo { columns = mat.width (head fr), rows = channels }
+                   (mat.columnSlice acc (mat.width acc - overlap) (mat.width acc)));
+    /*               
             frameSized = mat.resizedTo
                { columns = framesize, rows = channels };
             extended = frameSized
                (mat.columnSlice acc hop (mat.width acc));
             added = mat.sum (frameSized (head fr)) extended;
            (mat.columnSlice acc 0 hop) :: ola (tail fr) added;
+*/
+            pre :: ola (tail fr) added;
         fi;
     mat.concat (Horizontal ()) (ola frames (mat.zeroSizeMatrix ())));
 
@@ -113,7 +120,8 @@
     var buffered = mat.zeroSizeMatrix ();
     var position = 0;
     factor = hop / (framesize/2);
-    w = bf.scaled factor (win.hann framesize);
+    w = bf.scaled factor (win.hann framesize); // periodic window, not symmetric
+    println "window is \(vec.list w)";
     channels = mat.height (head frames); // so we don't need to keep a head ptr
     filt.delayedBy (- framesize)
         {
@@ -127,16 +135,22 @@
                     if samples <= 0 or empty? remaining then
                         acc
                     else
-                        this = mat.newMatrix (RowMajor ())
-                           (map (bf.multiply w) (mat.asRows (head remaining)));
+                        println "multiplying \(head remaining) by window";
+                        this = mat.resizedTo
+                            { columns = framesize, rows = channels }
+                            (mat.newMatrix (RowMajor ())
+                                (map (bf.multiply w)
+                                    (mat.asRows (head remaining))));
                         remaining := tail remaining;
                         framesFor (samples - hop) (acc ++ [this])
                     fi;
-                source = overlapAdd channels framesize hop
+                source = overlapAdd channels (framesize - hop)
                    (framesFor count [buffered]);
                 toReturn = mat.columnSlice source 0 count;
                 position := position + mat.width toReturn;
                 buffered := mat.columnSlice source count (mat.width source);
+                println "count = \(count), framesize = \(framesize), hop = \(hop)";
+                println "leaving position = \(position), buffered = \(buffered), returning \(toReturn)";
                 toReturn),
             close = \(),
         });
--- a/yetilab/stream/test/test_framer.yeti	Thu May 30 22:33:16 2013 +0100
+++ b/yetilab/stream/test/test_framer.yeti	Fri May 31 10:58:00 2013 +0100
@@ -26,11 +26,11 @@
     incomplete = overlapping and // Can't reconstruct with < 50% overlap
         params.framesize < params.hop * 2; 
 
+    println "firstChunkSize = \(firstChunkSize):";
+
     firstChunk = str.read firstChunkSize;
     restChunk = str.read (length - firstChunkSize);
 
-    println "firstChunkSize = \(firstChunkSize)";
-
     compareFrames f expected and
        (incomplete or 
             compareUsing mat.equal
@@ -127,20 +127,36 @@
 
 "overlapAdd-3.1": \(
     compareUsing (mat.equal)
-       (fr.overlapAdd 1 3 1 [ mat.newRowVector (vec.fromList [ 1,2,3 ]),
-                              mat.newRowVector (vec.fromList [   4,5,6 ]),
-                              mat.newRowVector (vec.fromList [     7,8,9 ]) ])
+       (fr.overlapAdd 1 2 [ mat.newRowVector (vec.fromList [ 1,2,3 ]),
+                            mat.newRowVector (vec.fromList [   4,5,6 ]),
+                            mat.newRowVector (vec.fromList [     7,8,9 ]) ])
        (mat.newRowVector (vec.fromList [ 1,6,15,14,9 ]))
 ),
 
 "overlapAdd-3.2": \(
     compareUsing (mat.equal)
-       (fr.overlapAdd 1 3 2 [ mat.newRowVector (vec.fromList [ 1,2,3 ]),
-                              mat.newRowVector (vec.fromList [     4,5,6 ]),
-                              mat.newRowVector (vec.fromList [         7,8,9 ]) ])
+       (fr.overlapAdd 1 1 [ mat.newRowVector (vec.fromList [ 1,2,3 ]),
+                            mat.newRowVector (vec.fromList [     4,5,6 ]),
+                            mat.newRowVector (vec.fromList [         7,8,9 ]) ])
        (mat.newRowVector (vec.fromList [ 1,2,7,5,13,8,9 ]))
 ),
 
+"overlapAdd-4.2": \(
+    compareUsing (mat.equal)
+       (fr.overlapAdd 1 2 [ mat.newRowVector (vec.fromList [ 1,2,3,4 ]),
+                            mat.newRowVector (vec.fromList [     5,6,7,8 ]),
+                            mat.newRowVector (vec.fromList [         9,0,1,2 ]) ])
+       (mat.newRowVector (vec.fromList [ 1,2,8,10,16,8,1,2 ]))
+),
+
+"overlapAdd-6+4.2": \( // Must work even if blocks vary in length (what if shorter than overlap though?)
+    compareUsing (mat.equal)
+       (fr.overlapAdd 1 2 [ mat.newRowVector (vec.fromList [ 1,2,3,4,5,6 ]),
+                            mat.newRowVector (vec.fromList [         7,8,9,0 ]),
+                            mat.newRowVector (vec.fromList [             1,2,3,4 ]) ])
+       (mat.newRowVector (vec.fromList [ 1,2,3,4,12,14,10,2,3,4 ]))
+),
+
 ] is hash<string, () -> boolean>;
 
 
--- a/yetilab/vector.yeti	Thu May 30 22:33:16 2013 +0100
+++ b/yetilab/vector.yeti	Fri May 31 10:58:00 2013 +0100
@@ -93,7 +93,7 @@
     done;
     a);
 
-concat vv is list?<~double[]> -> ~double[] =
+concat vv is list?<~double[]> -> ~double[] = //!!! doc: concat is obviously not lazy (unlike std module)
    (len = sum (map length' vv);
     vout = zeros len;
     var base = 0;