
function y=delay_mod(Input,FS,Mod_sig,Width)
% function y=delay_mod(Input,FS,Mod_sig,Width)
%
% Input is the audio input signal
% y is the audio output, the delay-modulated version of the input signal
% FS in Hz
% Mod_sig is also sampled at FS, but has sub-audio frequency content
% Width is Modulation width in sec
% Found at 11_Semester1/DESC9115/Matlab/DAFx/delays_ch3

ya_alt=0;
% Note that Delay=Width, the basic delay of input sample in sec
DELAY=round(Width*FS); % basic delay in # samples
WIDTH=round(Width*FS); % modulation width in # samples
L=2+DELAY+WIDTH*2;    % length of the entire delay 
Delayline=zeros(L,1); % memory allocation for delay
y=zeros(size(Input));     % memory allocation for output vector

LEN=length(Input);        % # of samples in WAV-file

for n=1:(LEN-1)
   ZEIGER=1+DELAY+WIDTH*Mod_sig(n);
   i=floor(ZEIGER);
   frac=ZEIGER-i;
   Delayline=[Input(n);Delayline(1:L-1)];
   %---Allpass Interpolation------------------------------
   y(n,1)=(Delayline(i+1)+(1-frac)*Delayline(i)-(1-frac)*ya_alt); 
   ya_alt=y(n,1);
end

