changeset 30:45a57e2fb4ae

Framer: make frames function delegate depending on whether overlapping or not, and have a single entry point either way
author Chris Cannam
date Fri, 21 Dec 2012 13:30:23 +0000
parents 3b237a05e785
children 102945485663
files framer.yeti test/test_framer.yeti
diffstat 2 files changed, 31 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/framer.yeti	Thu Dec 20 23:17:08 2012 +0000
+++ b/framer.yeti	Fri Dec 21 13:30:23 2012 +0000
@@ -42,21 +42,24 @@
         v :. \(overlappingBlockList bs hop stream remaining buffer);
     fi);
 
-frames blocksize stream =
-    blockList blocksize stream;
+frames { blocksize, hop } stream =
+    if blocksize == hop then
+        blockList blocksize stream
+    else
+        overlappingBlockList blocksize hop stream 
+            blocksize (vec.zeros blocksize);
+    fi;
 
-framesOfFile blocksize filename =
-    blockList blocksize (af.open filename);
-
-overlappingFrames { blocksize, hop } stream =
-    overlappingBlockList blocksize hop stream blocksize (vec.zeros blocksize);
-
-overlappingFramesOfFile { blocksize, hop } filename =
-    overlappingBlockList blocksize hop (af.open filename)
-        blocksize (vec.zeros blocksize);
+framesOfFile { blocksize, hop } filename =
+    if blocksize == hop then
+        blockList blocksize (af.open filename)
+    else
+        overlappingBlockList blocksize hop (af.open filename)
+            blocksize (vec.zeros blocksize);
+    fi;
 
 { 
-    frames, overlappingFrames,
-    framesOfFile, overlappingFramesOfFile,
+    frames,
+    framesOfFile,
 }
 
--- a/test/test_framer.yeti	Thu Dec 20 23:17:08 2012 +0000
+++ b/test/test_framer.yeti	Fri Dec 21 13:30:23 2012 +0000
@@ -8,83 +8,83 @@
 tests = [
 
 "framecount-2x2": \( 
-    fr = fr.frames 2 (test.testStream 2);
+    fr = fr.frames { blocksize = 2, hop = 2 } (test.testStream 2);
     test.compare (length fr) 1
 ),
 
 "framecount-2x3": \( 
-    fr = fr.frames 2 (test.testStream 3);
+    fr = fr.frames { blocksize = 2, hop = 2 } (test.testStream 3);
     test.compare (length fr) 2
 ),
 
 "framecount-2x4": \( 
-    fr = fr.frames 2 (test.testStream 4);
+    fr = fr.frames { blocksize = 2, hop = 2 } (test.testStream 4);
     test.compare (length fr) 2
 ),
 
 "framecount-2.1x0": \( 
-    fr = fr.overlappingFrames { blocksize = 2, hop = 1 } (test.testStream 0);
+    fr = fr.frames { blocksize = 2, hop = 1 } (test.testStream 0);
     test.compare (length fr) 1
 ),
 
 "framecount-2.1x1": \( 
-    fr = fr.overlappingFrames { blocksize = 2, hop = 1 } (test.testStream 1);
+    fr = fr.frames { blocksize = 2, hop = 1 } (test.testStream 1);
     test.compare (length fr) 2
 ),
 
 "framecount-2.1x2": \( 
-    fr = fr.overlappingFrames { blocksize = 2, hop = 1 } (test.testStream 2);
+    fr = fr.frames { blocksize = 2, hop = 1 } (test.testStream 2);
     test.compare (length fr) 3
 ),
 
 "framecount-2.1x3": \( 
-    fr = fr.overlappingFrames { blocksize = 2, hop = 1 } (test.testStream 3);
+    fr = fr.frames { blocksize = 2, hop = 1 } (test.testStream 3);
     test.compare (length fr) 4
 ),
 
 "framecount-4.1x4": \( 
-    fr = fr.overlappingFrames { blocksize = 4, hop = 1 } (test.testStream 4);
+    fr = fr.frames { blocksize = 4, hop = 1 } (test.testStream 4);
     test.compare (length fr) 7
 ),
 
 "framecount-4.3x4": \( 
-    fr = fr.overlappingFrames { blocksize = 4, hop = 3 } (test.testStream 4);
+    fr = fr.frames { blocksize = 4, hop = 3 } (test.testStream 4);
     test.compare (length fr) 2 
 ),
 
 "framecount-4.4x4": \( 
-    fr = fr.overlappingFrames { blocksize = 4, hop = 4 } (test.testStream 4);
+    fr = fr.frames { blocksize = 4, hop = 4 } (test.testStream 4);
     test.compare (length fr) 1
 ),
 
 "framecount-3.2x4": \(
-    fr = fr.overlappingFrames { blocksize = 3, hop = 2 } (test.testStream 4);
+    fr = fr.frames { blocksize = 3, hop = 2 } (test.testStream 4);
     test.compare (length fr) 3
 ),
 
 "frames-2x5": \( 
-    fr = fr.frames 2 (test.testStream 5);
+    fr = fr.frames { blocksize = 2, hop = 2 } (test.testStream 5);
     expected = array [ [1,2], [3,4], [5,0] ];
     obtained = array (map block.list fr);
     test.compare obtained expected;
 ),
 
 "frames-4.3x4": \( 
-    fr = fr.overlappingFrames { blocksize = 4, hop = 3 } (test.testStream 4);
+    fr = fr.frames { blocksize = 4, hop = 3 } (test.testStream 4);
     expected = array [ [0,1,2,3], [3,4,0,0] ];
     obtained = array (map block.list fr);
     test.compare obtained expected;
 ),
 
 "frames-3.2x4": \(
-    fr = fr.overlappingFrames { blocksize = 3, hop = 2 } (test.testStream 4);
+    fr = fr.frames { blocksize = 3, hop = 2 } (test.testStream 4);
     expected = array [ [0,1,2], [2,3,4], [4,0,0] ];
     obtained = array (map block.list fr);
     test.compare obtained expected;
 ),
 
 "frames-3.1x6": \(
-    fr = fr.overlappingFrames { blocksize = 3, hop = 1 } (test.testStream 6);
+    fr = fr.frames { blocksize = 3, hop = 1 } (test.testStream 6);
     expected = array [ [0,0,1], [0,1,2], [1,2,3], [2,3,4],
                        [3,4,5], [4,5,6], [5,6,0], [6,0,0] ];
     obtained = array (map block.list fr);