Mercurial > hg > ishara
view sinks/@sinkcat/sinkcat.m @ 2:7357e1dc2ad6
Simplified scheduler library with new schedule representation.
author | samer |
---|---|
date | Sat, 22 Dec 2012 16:17:51 +0000 |
parents | 672052bd81f8 |
children | 3f77126f7b5f |
line wrap: on
line source
% sinkcat - sink concatentation combinator % % sinkcat :: S1:sink(C,R), S2:sink(C,R), ... -> sink(C,R). % % The resulting sink writes to S1 until it reports full,then % to S2, then S3 and so on, until the last one, then it reports full. classdef sinkcat < sink properties (GetAccess=private,SetAccess=immutable) sinks % {[M]->sink(C,R)} chans % natural fs % nonneg end methods function s=sinkcat(varargin) % use 0 to signal <any> sampling rate and nan to indicate failure fs=foldl(@unify_rates,nan,map(@rate,varargin)); if isinf(fs), error('sampling rate mismatch'); end ch=foldl(@unify_channels,nan,map(@channels,varargin)); if isinf(ch), error('channel count mismatch'); end s.sinks=varargin; s.fs=fs; s.chans=ch; end function s=tostring(sig) n=length(sig.sinks); strx=map(@tostring,sig.sinks); if n==1, s=strx{1}; elseif n==2, s=sprintf('%s & %s',strx{1},strx{2}); else s=sprintf('sinkcat(%s,...)',strx{1}); end end function c=rate(s), c=s.fs; end function c=channels(s), c=s.chans; end end end