samer@0
|
1 % sinkcat - sink concatentation combinator
|
samer@0
|
2 %
|
samer@0
|
3 % sinkcat :: S1:sink(C,R), S2:sink(C,R), ... -> sink(C,R).
|
samer@0
|
4 %
|
samer@0
|
5 % The resulting sink writes to S1 until it reports full,then
|
samer@0
|
6 % to S2, then S3 and so on, until the last one, then it reports full.
|
samer@0
|
7 classdef sinkcat < sink
|
samer@0
|
8 properties (GetAccess=private,SetAccess=immutable)
|
samer@0
|
9 sinks % {[M]->sink(C,R)}
|
samer@0
|
10 chans % natural
|
samer@0
|
11 fs % nonneg
|
samer@0
|
12 end
|
samer@0
|
13 methods
|
samer@0
|
14 function s=sinkcat(varargin)
|
samer@0
|
15 % use 0 to signal <any> sampling rate and nan to indicate failure
|
samer@0
|
16 fs=foldl(@unify_rates,nan,map(@rate,varargin));
|
samer@0
|
17 if isinf(fs), error('sampling rate mismatch'); end
|
samer@0
|
18 ch=foldl(@unify_channels,nan,map(@channels,varargin));
|
samer@0
|
19 if isinf(ch), error('channel count mismatch'); end
|
samer@0
|
20 s.sinks=varargin;
|
samer@0
|
21 s.fs=fs;
|
samer@0
|
22 s.chans=ch;
|
samer@0
|
23 end
|
samer@0
|
24
|
samer@0
|
25 function s=tostring(sig)
|
samer@0
|
26 n=length(sig.sinks);
|
samer@0
|
27 strx=map(@tostring,sig.sinks);
|
samer@0
|
28 if n==1, s=strx{1};
|
samer@0
|
29 elseif n==2, s=sprintf('%s & %s',strx{1},strx{2});
|
samer@0
|
30 else s=sprintf('sinkcat(%s,...)',strx{1});
|
samer@0
|
31 end
|
samer@0
|
32 end
|
samer@0
|
33
|
samer@0
|
34 function c=rate(s), c=s.fs; end
|
samer@0
|
35 function c=channels(s), c=s.chans; end
|
samer@0
|
36 end
|
samer@0
|
37 end
|