% Vibrato 
% THIS FUNCTION WAS SOURCED FROM: 
% 
% Book on DAFX - Digital Audio Effects
% 
% Edited by Udo Zolzer
% ISBN: 0-471-49078-4
% John Wiley & Sons, 2011
% Author: S. Disch
% Edited for DESC9115: Ella Manor 2017
% Appropriate and used by Muhammad Hussain for Assignmment 2 DESC 9115.
function y=vibratoDAS(x,SAMPLERATE,Modfreq,Width)

WIDTH=round(Width*SAMPLERATE); % modulation width in # samples
MODFREQ=Modfreq/SAMPLERATE; % modulation frequency in # samples
LEN=length(x); % # of samples in WAV-file
L=2+WIDTH+WIDTH*2; % length of the entire delay
Delayline=zeros(L,1); % memory allocation for delay
y=zeros(size(x)); % memory allocation for output vector
for n=1:(LEN-1)
    MOD=sin(MODFREQ*2*pi*n);
    TAP=1+WIDTH+WIDTH*MOD;
    i=floor(TAP);
    frac=TAP-i;
    Delayline=[x(n);Delayline(1:L-1)];
    %---Linear Interpolation-----------------------------
    y(n,1)=Delayline(i+1)*frac+Delayline(i)*(1-frac);
end
