function x=unbuffer(X,hop,H)
% unbuffer - overlap-and-add signal reconstruction (opposite of buffer)
% 
% unbuffer ::
%    [[N,T]] ~'overlapping frames',
%    natural ~'hop size',
%    ([[N]] | N:natural->[[N]]) ~'window or window function'
% -> [[T]].


[N L]=size(X);
T=N+(L-1)*hop;
x=zeros(T,1);
K=1:N;
if (nargin<3), H=hanning(N); 
elseif ~isnumeric(H)
	% assume it's a window function handle
	H=feval(H,N);
end

for k=1:L
	x(K)=x(K)+H.*X(:,k);
	K=K+hop;
end

