function o=aolapadd(N,hop)
% aolapadd - overlap-and-add signal reconstruction arrow
% 
% aolapadd ::
%    N:natural ~'frame size',
%    M:natural ~'hop size'
% -> arrow( {[[N]]}, {[[M]]}, [[N-M]]).


	I=1:hop;
	ol=N-hop;

	o=loop1(1,1,@olapadd);

	function [fn,s0]=olapadd(sz)
		s0=zeros(ol,1);
		if ol<=hop, J=1:ol; K=hop+1:N; fn=ifx(sz(2)==1,@st1,@st2);
		else    J=hop+1:ol; K=ol+1:N; fn=ifx(sz(2)==1,@st3,@st4);
		end

		function [y,s]=st1(x,s)
			y=x(I);
			y(J)=y(J)+s;
			s=x(K);
		end

		function [y,s]=st2(x,s)
			width=size(x,2);
			y=zeros(hop,width);
			for i=1:width
				y(:,i)=x(I,i);
				y(J,i)=y(J,i)+s;
				s=x(K,i);
			end
		end

		function [y,s]=st3(x,s)
			y=(s(I)+x(I));
			s=[s(J)+x(J);x(K)];
		end

		function [y,s]=st4(x,s)
			width=size(x,2);
			y=zeros(hop,width);
			for i=1:width
				y(:,i)=(s(I)+x(I,i));
				s=[s(J)+x(J,i);x(K,i)];
			end
		end
	end
end

