function synWave=delay_mod(Input,FS,Width, lpc_filter_order);
%DELAY_MOD modulation delay
%       This function allows you to create a more realistic version of vibrato 
%       applied for violin. Using a modified sine, sawtooth and square wave. It is based on an
%       adapted allpass interpolation vibrarto designed by William Martens.
%
%             Input = Input Audio Signal (This should be a Column Vector)
%             FS = Sample Rate (Sample rate of audio input in Hz)
%             Widht = Width of the imput vector Rate (Value between 0.0001 and 0.0005)
%             lpc_filter_order = Number of coefficients for the filters (Value between 3 and 6)
%              
%
%
%      Example:
%              synWave=delay_mod(Input,FS,0.0003, 6)
% 
%      See Also: do_fractal_delay and proclpc





% original function synWave=delay_mod(Input,FS,Mod_sig,Width,q,freq, lpc_filter_order)
% Mod_sig,q,freq have been deleted to make the function more neat, since
% the user has no control about these variables.
% 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




%call proclpc function which will have an oputput called stream
[aCoeff,~,~,G,~,stream] = proclpc(Input,FS, lpc_filter_order); %added
% this separates the fundamental sound from a number of filters determined
% by the user, the best range is from 3-6
stream = stream';

%call 'get_LP_filtered_mod' function/script
get_LP_filtered_mod %added

load mod_1Hz_2;
Mod_sig = mod_1Hz_2;


LEN=length(stream);

Mod_sig = Mod_sig(1:LEN);



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(stream));     % memory allocation for output vector

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

for n=1:(LEN-1)
   ZEIGER=1+DELAY+WIDTH*Mod_sig(n);
   i=floor(ZEIGER);
   frac=ZEIGER-i;
   Delayline=[stream(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

%call synlpc function using y as input wave and FS as sampling frequency
end

synWave = synlpc(aCoeff,y,FS,G); %added

