samer@0: % sink - Base class for sink samer@0: % samer@0: % sink :: sink(C:natural,R:nonneg). samer@0: % samer@0: % The sink(C,R) type denotes the type of a sink with C samer@0: % channels and a sampling rate of R. samer@0: % samer@0: % The base sink class cannot be used without subclassing since samer@0: % any attempt to instantiate the live sink will throw samer@0: % an exception. samer@0: % samer@0: % METHODS samer@0: % channels :: sink(C,R) -> natural. samer@0: % rate :: sink(C,R) -> nonneg. samer@0: % construct:: sink(C,R) -> livesink(C,_). samer@0: % capacity :: sink(C,R) -> natural. samer@0: % samer@0: % livesink(C,Z) :== struct { samer@0: % start :: void->void; samer@0: % stop :: void->void; samer@0: % dispose :: void->Z; samer@0: % writer :: N:natural -> ([[C,N]] -> natural); samer@0: % } samer@0: samer@0: classdef sink samer@0: methods samer@0: function o=sink, end samer@0: function s=and(s1,s2), s=sinkcat(s1,s2); end samer@0: function r=rate(s), error('sampling rate undefined'); end samer@0: function c=channels(s), error('number of channels undefined'); end samer@0: function s=construct(sig), error('Cannot construct base sink class'); end samer@0: samer@0: function display(a) samer@0: disp(sprintf(' %s :: sink(%s,%s)',tostring(a),fmt(channels(a)),fmt(rate(a)))); samer@0: function s=fmt(x), if isnan(x), s='_'; else s=num2str(x); end; end samer@0: end samer@0: samer@0: function y=map(f,chf,x), y=sinkmap(f,chf,x); end samer@0: function y=drop(n,x), y=sinkdrop(n,x); end samer@0: function y=take(n,x), y=sinktake(n,x); end samer@0: function y=dropt(t,x), samer@0: if isnan(rate(x)), error('Cannot dropt without definite sampling rate'); end samer@0: y=sinkdropt(round(t*rate(x)),x); samer@0: end samer@0: samer@0: function y=taket(t,x), samer@0: if isnan(rate(x)), error('Cannot taket without definite sampling rate'); end samer@0: y=sinktake(round(t*rate(x)),x); samer@0: end samer@0: end samer@0: end