changeset 285:be39f21456a1

More on overlap-add for frames
author Chris Cannam
date Thu, 30 May 2013 17:34:35 +0100
parents 7932bbb7bacb
children 6ed6af2fc794
files yetilab/stream/framer.yeti yetilab/stream/test/test_framer.yeti
diffstat 2 files changed, 34 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/yetilab/stream/framer.yeti	Wed May 29 22:59:23 2013 +0100
+++ b/yetilab/stream/framer.yeti	Thu May 30 17:34:35 2013 +0100
@@ -94,11 +94,25 @@
         close = \(),
     });
 
+overlapAdd channels framesize hop frames =
+   (ola fr acc =
+        if empty? fr then
+           [acc]
+        else
+            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;
+        fi;
+    mat.concat (Horizontal ()) (ola frames (mat.zeroSizeMatrix ())));
+
 streamOverlapping rate framesize hop frames =
    (var remaining = frames;
     var buffered = mat.zeroSizeMatrix ();
     var position = 0;
-    w = win.hann framesize;
+    w = win.windowFunction (Hann ()) [ Symmetric true ] framesize;
     channels = mat.height (head frames); // so we don't need to keep a head ptr
     filt.delayedBy (- (framesize - hop))
         {
@@ -125,7 +139,9 @@
                         remaining := tail remaining;
                         framesFor (samples - hop) (acc ++ [this])
                     fi;
-                source = mat.concat (Horizontal ()) (framesFor count [buffered]);
+                source = overlapAdd channels framesize hop
+                   (framesFor count [buffered]);
+//                println "source = \(source)";
                 toReturn = mat.columnSlice source 0 count;
                 buffered := mat.columnSlice source count (mat.width source);
                 toReturn),
@@ -169,6 +185,8 @@
     frequencyDomainFramesOfFile parameters filename = 
         frequencyDomainFrames parameters (af.open filename),
 
+    overlapAdd,
+
     streamed,
 }
 
--- a/yetilab/stream/test/test_framer.yeti	Wed May 29 22:59:23 2013 +0100
+++ b/yetilab/stream/test/test_framer.yeti	Thu May 30 17:34:35 2013 +0100
@@ -23,12 +23,17 @@
     ts = testStream length;
     compareFrames f expected and
         compareUsing mat.equal
+           (str.read length) (ts.read length) and
+        compare str.position length and
+        compare str.available (Known (sz - (length % sz))));
+/*
+        compareUsing mat.equal
            (str.read 2) (ts.read 2) and
         compareUsing mat.equal
            (str.read (length - 2)) (ts.read (length - 2)) and
         compare str.position length and
         compare str.available (Known (sz - (length % sz))));
-
+*/
 [
 
 "framecount-2x2": \( 
@@ -104,6 +109,14 @@
           [3,4,5], [4,5,6], [5,6,0], [6,0,0] ];
 ),
 
+"overlapAdd": \(
+    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 ]) ])
+       (mat.newRowVector (vec.fromList [ 1,6,15,14,9 ]))
+),
+
 ] is hash<string, () -> boolean>;