% reverb_moorer_eg.m
% Script to call the Moorer Reverb Algoritm

close all;
clear all;

filename='../acoustic.wav';

% read the sample waveform
[x,Fs,bits] = wavread(filename);

% Call moorer reverb
%set delay of each comb filter
%set delay of each allpass filter in number of samples
%Compute a random set of milliseconds and use sample rate
rand('state',sum(100*clock))
cd = floor(0.05*rand([1,6])*Fs);

% set gains of 6 comb pass filters
g1 = 0.5*ones(1,6);
%set feedback of each comb filter
g2 = 0.5*ones(1,6);
% set input cg and cg1 for moorer function see help moorer
cg = g2./(1-g1);
cg1 = g1;


%set gain of allpass filter
ag = 0.7;
%set delay of allpass filter
ad = 0.08*Fs;
%set direct signal gain
k = 0.5;


[y b a] = moorer(x,cg,cg1,cd,ag,ad,k);


% write output
wavwrite(y,Fs,bits,'out_moorerreverb.wav');

figure(1);
hold on
plot(y,'r');
plot(x,'b');
title('Moorer Reverberated Signal');

