Envelope Example
Updated Main Test to include Envelope Example
This commit is contained in:
parent
74586d31c6
commit
e3c4b4931d
@ -6,7 +6,7 @@
|
||||
|
||||
## Function Prototypes
|
||||
|
||||
function x = generate_wave(amplitude, frequency, phase, fs, duration, duty)
|
||||
function x = generate_wave(amplitude, frequency, phase, fs, duration, duty)
|
||||
|
||||
fuction x = envelope(input, fs, period, attack , decay, sustain, release)
|
||||
where attack, decay, sustain release are percentages between 0 to 1 of the period
|
||||
|
37
src/DarellEnvelope.m
Normal file
37
src/DarellEnvelope.m
Normal file
@ -0,0 +1,37 @@
|
||||
function output = DarellEnvelope(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;
|
||||
|
||||
x = 0:1/Fs:T;
|
||||
y = 0 .* x; %create zero array of y of len x
|
||||
output = y;%create zero array of output of len x
|
||||
tcounter = 1;
|
||||
%attack phase
|
||||
while tcounter <= attacktime
|
||||
y(tcounter) = (1/attacktime) * tcounter;
|
||||
tcounter = tcounter+1;
|
||||
end
|
||||
istart = tcounter;
|
||||
while tcounter<= decaytime
|
||||
y(tcounter) = 1 - (((1-sustain)/(decay * T * Fs)) * (tcounter - istart));
|
||||
tcounter = tcounter+1;
|
||||
end
|
||||
|
||||
while tcounter<= sustaintime
|
||||
y(tcounter) = sustain;
|
||||
tcounter = tcounter+1;
|
||||
end
|
||||
istart = tcounter;
|
||||
while tcounter < (T * Fs)
|
||||
y(tcounter) = sustain - ((sustain/(release * T * Fs)) * (tcounter - istart));
|
||||
tcounter = tcounter+1;
|
||||
end
|
||||
|
||||
for counter = 1:1:len
|
||||
output(counter) = y(counter) * input(counter);
|
||||
end
|
||||
|
||||
end
|
@ -22,4 +22,14 @@ x = DarellbandpassFilter(x,fs,LOW,MED,HIGH);
|
||||
|
||||
%play over 5 counts, should only hear 200hz
|
||||
playtime = 5;
|
||||
play_continuous(x, fs, playtime)
|
||||
play_continuous(x, fs, playtime)
|
||||
|
||||
attack = 0.2;
|
||||
decay = 0.2;
|
||||
sustain = 0.2;
|
||||
release = 0.1;
|
||||
|
||||
x = DarellEnvelope(x, fs, attack,decay,sustain,release);
|
||||
%play over 5 counts, should only hear 200hz
|
||||
playtime = 5;
|
||||
play_continuous(x, fs, playtime)
|
||||
|
Reference in New Issue
Block a user