changeset 204:0c81455270dc

Implement mixedTo in filter module. But this needs more thought, so I've left one of the tests failing
author Chris Cannam
date Mon, 06 May 2013 21:45:38 +0100
parents ee3fbcc779d9
children 0a61f84c6a8f
files yetilab/stream/channels.yeti yetilab/stream/filter.yeti yetilab/stream/test/test_filter.yeti
diffstat 3 files changed, 88 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/yetilab/stream/channels.yeti	Mon May 06 18:33:30 2013 +0100
+++ b/yetilab/stream/channels.yeti	Mon May 06 21:45:38 2013 +0100
@@ -80,12 +80,11 @@
         block.block v';
     fi;
 
-mixedAndInterleavedTo targetChannels m = 
+mixedTo targetChannels m = 
     if targetChannels == 1 then
-        mixedDown m
+        deinterleaved 1 (mixedDown m)
     else
-       (interleaved .
-            mat.resizedTo { rows = targetChannels, columns = m.size.columns })
+        mat.resizedTo { rows = targetChannels, columns = m.size.columns }
             if m.size.rows == 1 then
                (mat.newMatrix (RowMajor ()) [ m.getRow 0, m.getRow 0 ])
             else
@@ -93,8 +92,17 @@
             fi;
     fi;
 
+mixedAndInterleavedTo targetChannels m = 
+    if targetChannels == 1 then
+        mixedDown m
+    else
+        interleaved (mixedTo targetChannels m);
+    fi;
+
+//!!! some of these names are terrible
 {
     interleaved, deinterleaved,
-    mixedDown, mixedDownFromInterleaved, mixedFromInterleavedTo, mixedAndInterleavedTo
+    mixedDown, mixedDownFromInterleaved,
+    mixedFromInterleavedTo, mixedTo, mixedAndInterleavedTo
 }
 
--- a/yetilab/stream/filter.yeti	Mon May 06 18:33:30 2013 +0100
+++ b/yetilab/stream/filter.yeti	Mon May 06 21:45:38 2013 +0100
@@ -3,6 +3,7 @@
 
 mat = load yetilab.matrix.matrix;
 bl = load yetilab.block.block;
+ch = load yetilab.stream.channels;
 
 load yetilab.stream.streamtype;
 
@@ -44,6 +45,7 @@
     });
 
 delayedBy nsamples s = //!!! should nsamples be a time in seconds? (no)
+//!!! should allow nsamples < 0!
    (var prepos = 0;
     delay = nsamples;
     zeros n = mat.toRowMajor
@@ -72,6 +74,14 @@
         close = s.close
     });
 
+//!!! poor name, confusion with mixed, but consistent with channels.yeti
+mixedTo targetChannels s =
+    s with //!!! should use this more in this module
+    {
+        get channels () = targetChannels,
+        read count = ch.mixedTo targetChannels (s.read count),
+    };
+
 //!!! what should happen if we mix or multiplex a finite-length and an
 //infinite-length stream? or even two streams with differing finite
 //lengths? write tests for this. At the moment the resulting stream
@@ -193,6 +203,7 @@
 {
     withDuration is number -> stream -> stream,
     delayedBy is number -> stream -> stream,
+    mixedTo is number -> stream -> stream,
     mixed is list<stream> -> stream,
     multiplexed is list<stream> -> stream,
     repeated is stream -> stream,
--- a/yetilab/stream/test/test_filter.yeti	Mon May 06 18:33:30 2013 +0100
+++ b/yetilab/stream/test/test_filter.yeti	Mon May 06 21:45:38 2013 +0100
@@ -182,6 +182,70 @@
         ( str.close (); true )
 ),
 
+"mixedTo-1-2-\(name)": \(
+    str = filt.mixedTo 2 (withDuration 3 (syn.generated 2 id));
+    compare str.position 0 and
+        compare str.channels 2 and
+        compare str.sampleRate 2 and
+        compare str.available (maybeKnown 3) and
+        compare str.finished? false and
+        compare (map bl.list (mat.asRows (str.read 4))) [[0,1,2],[0,1,2]] and
+        compare str.position 3 and
+        compare str.available (Known 0) and
+        compare str.finished? true and
+        ( str.close (); true )
+),
+
+"mixedTo-2-1-\(name)": \(
+    str = filt.mixedTo 1
+       (filt.multiplexed
+          [withDuration 3 (syn.generated 2 id),
+           withDuration 3 (syn.generated 2 id)]);
+    compare str.position 0 and
+        compare str.channels 1 and
+        compare str.sampleRate 2 and
+        compare str.available (maybeKnown 3) and
+        compare str.finished? false and
+        compare (map bl.list (mat.asRows (str.read 4))) [[0,2,4]] and
+        compare str.position 3 and
+        compare str.available (Known 0) and
+        compare str.finished? true and
+        ( str.close (); true )
+),
+
+//!!! is this what we want? zeros in subsequent channels? cross-check with channels module
+"mixedTo-2-3-\(name)": \(
+    str = filt.mixedTo 3
+       (filt.multiplexed
+          [withDuration 3 (syn.generated 2 id),
+           withDuration 3 (syn.generated 2 (+1))]);
+    compare str.position 0 and
+        compare str.channels 3 and
+        compare str.sampleRate 2 and
+        compare str.available (maybeKnown 3) and
+        compare str.finished? false and
+        compare (map bl.list (mat.asRows (str.read 4))) [[0,1,2],[1,2,3],[0,0,0]] and
+        compare str.position 3 and
+        compare str.available (Known 0) and
+        compare str.finished? true and
+        ( str.close (); true )
+),
+
+//!!! is this what we want? zeros in subsequent channels? cross-check with channels module and behaviour of 1->2 mixing
+"mixedTo-1-3-\(name)": \(
+    str = filt.mixedTo 3 (withDuration 3 (syn.generated 2 id));
+    compare str.position 0 and
+        compare str.channels 3 and
+        compare str.sampleRate 2 and
+        compare str.available (maybeKnown 3) and
+        compare str.finished? false and
+        compare (map bl.list (mat.asRows (str.read 4))) [[0,1,2],[0,0,0],[0,0,0]] and
+        compare str.position 3 and
+        compare str.available (Known 0) and
+        compare str.finished? true and
+        ( str.close (); true )
+),
+
 "mixed-inf-inf-\(name)": \(
     str = filt.mixed [syn.generated 2 (2*), syn.generated 2 (0-)];
     compare str.position 0 and