%%%%%%%%%%%%%%%%%%% Universal Comb Filter Based Delay %%%%%%%%%%%%%%%%%%%
% Script Modified by Trenton Smith 2016, Based of script from DaFX(edition 2)
% 2011 by P. Dutilleux, U Z¨olzer

function y = my_delay(x, FB , M , fs); 
BL=0.5; %Blend Paramiter
FF=5; % feedforward parameter
%FB=-0.5;  %Feedback
%M=1000;% delay in MS

delay_in_seconds = M./1000;% Converts dealy time from ms to s

delay = round(delay_in_seconds.*fs);% Changes delay from samples to seconds 

x=[x;zeros(delay*2,1)]; % padd the input signal with zeros to include all delay lines for the output signal  
Delayline=zeros(delay,1); % memory allocation for length M
for n=1:length(x);
    xh=x(n)+FB*Delayline(delay);
    y(n)=FF*Delayline(delay)+BL*xh;
    Delayline=[xh;Delayline(1:delay-1)];
end

