Reorganized Into Folders

This commit is contained in:
Darell Chua Yun Da
2021-12-10 10:01:30 +08:00
parent 88f77fed35
commit f856cdcd2b
41 changed files with 53 additions and 4 deletions

View File

@@ -0,0 +1,103 @@
%Written by Darell and Anne
%If there is a frequency of 200Hz:
%1. it needs to ramp up a frequency from 0Hz to the 200Hz over the attack time
%2. It needs to ramp down to a set sustained frequency over the decay time e.g. 160Hz < 200Hz
%3. It maintains this 160Hz until the release time
%4. Release time: It decays from 160Hz further all the way back to 0Hz.
%This envelope uses linear calculations
% CONTRIBUTORS:
% Person1: Darell
% Person2: Anne
% DOCUMENTATION:
% fs is the sampling frequency
% attack, decay, release are in percentages of the period
% sustain is in the percentage of amplitude
function output = DarellAnneLinearPitchEnvelope(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;
x = 1:len;
y = x .* 0;
g = x .* 0;
while tcounter <= curr
ncount = round((tcounter^2)/(2*curr)+ curr/2);
y(tcounter) = ncount; %For Debug Purposes
output(tcounter) = input(ncount);
tcounter = tcounter+1;
end
%decay phase
prevcur = curr;
tcounter = prevcur;
curr = decaytime;
while tcounter <= curr
t = round(tcounter-prevcur);
dur = round(curr-prevcur);
dsus = (1-sustain);
dn = (1 - (dsus)*t/(2*dur))*t;
ncount = round(prevcur + dn);
tcounter = round(tcounter);
y(tcounter) = ncount; %For Debug Purposes
output(tcounter) = input(ncount);
tcounter = tcounter+1;
end
hold on
plot(x,y)
plot(x,g)
hold off
%sustain phase
prevncount = ncount;
prevcur = curr;
tcounter = prevcur;
curr = sustaintime;
while tcounter <= curr
t = round(tcounter-prevcur);
ncount = round(sustain*(t) + prevncount);
tcounter = round(tcounter);
y(tcounter) = ncount; %For Debug Purposes
output(tcounter) = input(ncount);
tcounter = tcounter+1;
end
%release phase
prevncount = ncount;
prevcur = curr;
tcounter = prevcur;
curr = Fs;
while tcounter <= curr
t = round(tcounter-prevcur);
dur = round(curr-prevcur);
dn = (sustain - (sustain)*t/(2*dur))*t;
ncount = round(prevncount + dn);
%ncount = round(prevncount + ((curr-prevcur)*(tcounter-prevcur)/(curr))*(1-log(tcounter+1-prevcur)/log(curr-prevcur)));
%ncount = round(curr*(1-log(tcounter)/log(prevcur)) + prevncount);
tcounter = round(tcounter);
y(tcounter) = ncount; %For Debug Purposes
if ncount > len
output(tcounter) = 0;
else
output(tcounter) = input(ncount);
end
tcounter = tcounter+1;
end
plot(x,y) %For Debug Purposes
end

View File

@@ -0,0 +1,74 @@
%Written by Darell and Anne
%If there is a frequency of 200Hz:
%1. it needs to ramp up a frequency from 0Hz to the 200Hz over the attack time
%2. It needs to ramp down to a set sustained frequency over the decay time e.g. 160Hz < 200Hz
%3. It maintains this 160Hz until the release time
%4. Release time: It decays from 160Hz further all the way back to 0Hz.
%This envelope uses logarithmic calculations
% CONTRIBUTORS:
% Person1: Darell
% Person2: Anne
% DOCUMENTATION:
% phase shift is in number of periods
% fs is the sampling frequency: how many sample points per second
% duration is time in seconds
% duty is a number between 0 and 1
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;
while tcounter <= curr
ncount = round(sustain*curr*(1-log(tcounter)/log(prevcur)) + prevcur);
tcounter = round(tcounter);
output(tcounter)
output(tcounter) = input(ncount);
tcounter = tcounter+1;
end
%sustain phase
prevncount = ncount;
prevcur = curr;
tcounter = prevcur;
curr = sustaintime;
while tcounter <= curr
ncount = round(sustain*(tcounter - prevcur) + prevncount);
tcounter = round(tcounter);
output(tcounter) = input(ncount);
tcounter = tcounter+1;
end
%release phase
prevncount = ncount;
prevcur = curr;
tcounter = prevcur;
curr = Fs;
while tcounter <= Fs
ncount = round(curr*(1-log(tcounter)/log(prevcur)) + prevncount);
tcounter = round(tcounter);
output(tcounter) = input(ncount);
tcounter = tcounter+1;
end
end