classdef sigmap < signal
	properties (GetAccess=private, SetAccess=immutable)
		fun
		sig
		chans
	end
	methods
		function s=sigmap(f,sig,chf)
			if nargin<3, chf=@(c1)size(f(zeros(c1,1)),1); end
			s.fun=f;
			s.sig=sig;
			s.chans=chf(channels(sig));
		end

		function s=tostring(sig)
			s=sprintf('map(%s,%s)',tostring(sig.fun),tostring(sig.sig));
		end

		function c=rate(s), c=rate(s.sig); end
		function c=channels(s), c=s.chans; end

		function s=construct(sig)
			f=sig.fun;
			s1=construct(sig.sig);
			s.start   = s1.start;
			s.stop    = s1.stop;
			s.dispose = s1.dispose;
			s.reader  = @reader;

			function r=reader(n)
				r1=s1.reader(n);
				r =@next;
				function [x,rem]=next
					[x1,rem]=r1();
					x=f(x1);
				end
			end
		end
	end
end
