% sinkdata - write sequence of arrays to sink
%
% sinkdata :: 
%    seq [[C,N]]  ~'sequence of arrays of C channel signal',
%    sigsink(C,R) ~'sink'
%    natural      ~'maximum size of arrays in input'
% -> action.
%
% Third argument defaults to maximum dimension of signal arrays.
% This function does not control the timing of the writes and
% so is suitable for non-real-time writes to eg audio files.

function res=sinkdata(Y,S,maxbuf)
	if nargin<3, maxbuf=max(size(Y)); end
	u=construct(S);
	try
		W=u.writer(maxbuf);
		u.start(); foreach(@write,Y); u.stop();
	catch ex
		u.dispose();
		rethrow(ex);
	end
	u.dispose();

	function write(x)
		rem=W(x);
		if rem>0, error('Sink is full'); end
	end
end


