diff signals/@siglzcat/construct.m @ 1:289445d368a7

import.
author samer
date Wed, 19 Dec 2012 22:46:05 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/signals/@siglzcat/construct.m	Wed Dec 19 22:46:05 2012 +0000
@@ -0,0 +1,35 @@
+function s=construct(sig)
+	fs=rate(sig.head);
+	ch=channels(sig.head);
+	sc=construct(sig.head);
+	sx=sig.tail;
+
+	s.start   = @start;
+	s.stop    = @stop;
+	s.dispose = @dispose;
+	s.reader  = @reader;
+
+	function start, sc.start(); end
+	function stop, sc.stop(); end
+	function dispose, sc.dispose(); end 
+	function r=reader(n)
+		rc=sc.reader(n);
+		r = @next;
+		function [x,rem]=next
+			[x,rem]=rc();
+			while rem>0 && ~isempty(sx) % current signal exhausted, try next
+				sc.dispose();
+				[sig2,sx]=sx();
+
+				fs=unify_rates(fs,rate(sig2));
+				if isinf(fs), error('sigcat:Signal sampling rate mismatch'); end
+				ch=unify_channels(ch,channels(sig2));
+				if isinf(ch), error('sigcat:Signal channels count mismatch'); end
+				sc=construct(sig2); 
+
+				[x(:,end-rem+1:end),rem]=sigreadn(sc,rem);
+				rc=sc.reader(n);
+			end
+		end
+	end
+end