classdef sigfun < signal
	properties (GetAccess=private, SetAccess=immutable)
		fun
		fs
	end
	methods
		function s=sigfun(fun,rate)
			s.fun=fun;
			s.fs=rate;
		end

		function s=tostring(sig), s=sprintf('sigfun(%s)',tostring(sig.fun)); end
		function c=channels(s), c=size(s.fun(0),1); end
		function c=rate(s), c=s.fs; end

		function s=construct(sig)
			fun=sig.fun;
			t=0;

			s.start   = @nop;
			s.stop    = @nop;
			s.dispose = @nop;
			s.reader = @reader;

			function r=reader(n)
				r = @next;
				T=(0:n-1)/sig.fs;
				dt=n/sig.fs;
				function [x,rem]=next, 
					x=fun(t+T); rem=0; 
					t=t+dt;
				end
			end
		end
	end
end
