diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-01-25 04:09:18 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2016-01-25 04:09:18 +0100 |
commit | 9eb3c1ae817dd5853fa27bdc8da4b6d2f4992a8c (patch) | |
tree | 18ae63f25fde975ce5a1ebd2e125e993975e5c41 | |
parent | 906db8cb7d8b1e8797f9df7714ef833e430da910 (diff) | |
download | applause2-9eb3c1ae817dd5853fa27bdc8da4b6d2f4992a8c.tar.gz |
added DupMux() function and Stream:dupmux() method
These are useful whenever a single-channel stream should be muxed
into multi-channel stream (e.g. mono to stereo signal)
-rw-r--r-- | applause.lua | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/applause.lua b/applause.lua index 634bb93..b1c55d2 100644 --- a/applause.lua +++ b/applause.lua @@ -646,6 +646,10 @@ function Stream:mux(...) return MuxStream:new(self, ...) end +function Stream:dupmux(channels) + return DupMux(self, channels) +end + -- For single-channel streams only, see also MuxStream:demux() function Stream:demux(i, j) j = j or i @@ -806,6 +810,20 @@ function MuxStream:foreach(fnc) end end +-- FIXME: This should perhaps be a class +function DupMux(stream, channels) + channels = channels or 2 + + local synced = tostream(stream):sync() + -- FIXME: May need a list creation function + local streams = {} + for j = 1, channels do + streams[j] = synced + end + + return MuxStream:new(unpack(streams)) +end + -- Base class for all streams that operate on arbitrary numbers -- of other streams. Handles muxing opaquely. MuxableStream = DeriveClass(Stream) @@ -844,13 +862,7 @@ function MuxableStream:ctor(...) -- Single-channel (non-MuxStream) streams are blown up -- to the final number of channels if args[i].channels == 1 then - local synced = args[i]:sync() - -- FIXME: May need a list creation function - local duped_channels = {} - for j = 1, channels do - duped_channels[j] = synced - end - args[i] = MuxStream:new(unpack(duped_channels)) + args[i] = args[i]:dupmux(channels) end -- Otherwise all stream arguments must have the same number of channels |