# HG changeset patch # User Chris Cannam # Date 1367873138 -3600 # Node ID 0c81455270dc1f28befeaa507d3211306b69a1a1 # Parent ee3fbcc779d91b3f40faa464c3fcc14711db1880 Implement mixedTo in filter module. But this needs more thought, so I've left one of the tests failing diff -r ee3fbcc779d9 -r 0c81455270dc yetilab/stream/channels.yeti --- 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 } diff -r ee3fbcc779d9 -r 0c81455270dc yetilab/stream/filter.yeti --- 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, multiplexed is list -> stream, repeated is stream -> stream, diff -r ee3fbcc779d9 -r 0c81455270dc yetilab/stream/test/test_filter.yeti --- 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