% ------------------------------------------------------------
% REVERBERATION DEMO (CLAP-LIKE SOUND)
% ------------------------------------------------------------

clear; close all; clc;

fs = 44100;
t = 0:1/fs:2;

% -----------------------------
% Clap-like signal (noise burst)
% -----------------------------
noise = randn(size(t));
env = exp(-40*t);          % πολύ γρήγορο decay (σαν παλαμάκι)
dry = noise .* env;

% -----------------------------
% Impulse response (room)
% -----------------------------
h = zeros(size(t));

% Direct sound
h(1) = 1;

% Early reflections
delays = [0.02 0.04 0.06 0.08];
gains  = [0.7  0.5  0.4  0.3];

for i = 1:length(delays)
    idx = round(delays(i)*fs);
    h(idx) = gains(i);
end

% Dense reverberation tail
decay = exp(-3*t);
h = h + 0.1*randn(size(t)).*decay;

% -----------------------------
% Convolution
% -----------------------------
wet = conv(dry, h);
wet = wet(1:length(t));

% normalize
dry = dry / max(abs(dry));
wet = wet / max(abs(wet));

% -----------------------------
% Plot
% -----------------------------
figure;

subplot(2,1,1)
plot(t, dry)
title('Dry (clap-like)')
grid on

subplot(2,1,2)
plot(t, wet)
title('With reverberation')
grid on

% -----------------------------
% Play
% -----------------------------
disp('Dry...')
sound(dry, fs)
pause(2)

disp('Reverb...')
sound(wet, fs)