view sinks/@sinkdrop/sinkdrop.m @ 2:7357e1dc2ad6

Simplified scheduler library with new schedule representation.
author samer
date Sat, 22 Dec 2012 16:17:51 +0000
parents 672052bd81f8
children
line wrap: on
line source
% sinkdrop - sink that discards first N samples before sending to subsink.
%
% sinkdrop :: N:natural, sink(C,R) -> sink(C,R).
classdef sinkdrop < sink
	properties (GetAccess=private,SetAccess=immutable)
		todrop % natural
		dest   % sink(C,R)
	end
	methods
		function s=sinkdrop(n,sig)
			s.todrop=n;
			s.dest=sig;
		end
		function s=tostring(sig)
			s=sprintf('drop(%d,%s)',sig.todrop,tostring(sig.dest));
		end
		function c=rate(s), c=rate(s.dest); end
		function c=channels(s), c=channels(s.dest); end
		function s=construct(sig)
			s1=construct(sig.dest);
			todrop=sig.todrop;

			s.start=s1.start;
			s.stop=s1.stop;
			s.dispose=s1.dispose;
			s.writer=@writer

			function f=writer(n)
				w1=s1.writer(n);
				f=@next
				function rem=next(x)
					n=uint32(size(x,2));
					if todrop==0, rem=w1.next(x);
					elseif n<=todrop
						todrop=todrop-n;
					else
						rem=sinkwriten(s1,n-todrop,x(:,todrop+1:end));
						todrop=0;
					end
				end
			end
		end
	end
end