%Written by Darell and Anne
%This envelope uses linear calculations
function output = DarellAnnePitchEnvelope(input, Fs, attack,decay,sustain,release) %percentages for attack, decay, sustain, release
len = length(input);
T = (len-1)/Fs;
attacktime = attack * T * Fs;
decaytime = attacktime + decay * T * Fs;
sustaintime = (T - (release * T)) * Fs;
output = zeros([1,len]);
tcounter = 1;
%attack phase
curr = attacktime;
while tcounter <= curr
ncount = round(curr*log(tcounter)/log(curr)+1);
output(tcounter) = input(ncount);
tcounter = tcounter+1;
end
%decay phase
prevcur = curr;
tcounter = prevcur;
curr = decaytime;
ncount = round(sustain*curr*(1-log(tcounter)/log(prevcur)) + prevcur);
tcounter = round(tcounter);
output(tcounter)
%sustain phase
prevncount = ncount;
curr = sustaintime;
ncount = round(sustain*(tcounter - prevcur) + prevncount);
%release phase
curr = Fs;
while tcounter <= Fs
ncount = round(curr*(1-log(tcounter)/log(prevcur)) + prevncount);