samer@0
|
1 % sink - Base class for sink
|
samer@0
|
2 %
|
samer@0
|
3 % sink :: sink(C:natural,R:nonneg).
|
samer@0
|
4 %
|
samer@0
|
5 % The sink(C,R) type denotes the type of a sink with C
|
samer@0
|
6 % channels and a sampling rate of R.
|
samer@0
|
7 %
|
samer@0
|
8 % The base sink class cannot be used without subclassing since
|
samer@0
|
9 % any attempt to instantiate the live sink will throw
|
samer@0
|
10 % an exception.
|
samer@0
|
11 %
|
samer@0
|
12 % METHODS
|
samer@0
|
13 % channels :: sink(C,R) -> natural.
|
samer@0
|
14 % rate :: sink(C,R) -> nonneg.
|
samer@0
|
15 % construct:: sink(C,R) -> livesink(C,_).
|
samer@0
|
16 % capacity :: sink(C,R) -> natural.
|
samer@0
|
17 %
|
samer@0
|
18 % livesink(C,Z) :== struct {
|
samer@0
|
19 % start :: void->void;
|
samer@0
|
20 % stop :: void->void;
|
samer@0
|
21 % dispose :: void->Z;
|
samer@0
|
22 % writer :: N:natural -> ([[C,N]] -> natural);
|
samer@0
|
23 % }
|
samer@0
|
24
|
samer@0
|
25 classdef sink
|
samer@0
|
26 methods
|
samer@0
|
27 function o=sink, end
|
samer@0
|
28 function s=and(s1,s2), s=sinkcat(s1,s2); end
|
samer@0
|
29 function r=rate(s), error('sampling rate undefined'); end
|
samer@0
|
30 function c=channels(s), error('number of channels undefined'); end
|
samer@0
|
31 function s=construct(sig), error('Cannot construct base sink class'); end
|
samer@0
|
32
|
samer@0
|
33 function display(a)
|
samer@0
|
34 disp(sprintf(' %s :: sink(%s,%s)',tostring(a),fmt(channels(a)),fmt(rate(a))));
|
samer@0
|
35 function s=fmt(x), if isnan(x), s='_'; else s=num2str(x); end; end
|
samer@0
|
36 end
|
samer@0
|
37
|
samer@0
|
38 function y=map(f,chf,x), y=sinkmap(f,chf,x); end
|
samer@0
|
39 function y=drop(n,x), y=sinkdrop(n,x); end
|
samer@0
|
40 function y=take(n,x), y=sinktake(n,x); end
|
samer@0
|
41 function y=dropt(t,x),
|
samer@0
|
42 if isnan(rate(x)), error('Cannot dropt without definite sampling rate'); end
|
samer@0
|
43 y=sinkdropt(round(t*rate(x)),x);
|
samer@0
|
44 end
|
samer@0
|
45
|
samer@0
|
46 function y=taket(t,x),
|
samer@0
|
47 if isnan(rate(x)), error('Cannot taket without definite sampling rate'); end
|
samer@0
|
48 y=sinktake(round(t*rate(x)),x);
|
samer@0
|
49 end
|
samer@0
|
50 end
|
samer@0
|
51 end
|