function y = allpass(x,Fe,t,gain)
%        y = allpass(x,Fe,t,gain)
% passe-tout pour reverb
%--------------------------------

% y_k - gain*y_{k-N} = -gain*x_k + x_{k-N}
% H(z) = [z^(-N) - gain] / [1 - gain*z^(-N)]
% |H(exp(iwt))| = 1

h = 1/Fe; 
N = ceil(t/h);
lx = length(x);
y = zeros(1,lx+N);

for k = 1:N
    y(k) = -gain*x(k);
end
for  k = N+1:lx
    y(k) = gain*(y(k-N)-x(k)) + x(k-N);
end
for  k = lx+1:lx+N
    y(k) = gain*y(k-N) + x(k-N);
end

% lissage de la fin
%ly = length(y); df = ceil(ly/20);
%y(ly-df+1:ly) = y(ly-df+1:ly).*(1+cos((1:df)*pi/df))/2;
