function y = reverb(x,Fe,T,P)
%        y = reverb(x,Fe,T,P)
% reverberation via reflexions, echos et passe-tout
% modele de Moorer, P = poids de la reverb / x
%--------------------------------------------------

d = [3 5 7 11 13 17];
t = [51 57 61 67 71 79]/1000;
c = 340;

% premieres reflexions
g = 1./d;
ret = d/c;
ld = length(d);
y = x;
for k = 1:ld
    r = (-1)^k*g(k)*retard(x,Fe,ret(k));
    y = somme(y,P*r);
end

% echos multiples
g = 10.^(-3*t/(T+1e-16));
lg = length(g);
z = [];
for k = 1:lg
    r = echfiltre(x,Fe,t(k),g(k))/lg;
    z = somme(z,r);
end

% passe-tout et sortie
z = allpass(z,Fe,.006,.7);
y = somme(y,P*z);

% attenuation de la queue (pour enlever le clic)
ly = length(y); df = ceil(ly/5);
y(ly-df+1:ly) = y(ly-df+1:ly).*(1+cos((1:df)*pi/df))/2;
y = .98*y/max(abs(y));
