diff --git a/.DS_Store b/.DS_Store index 47b0a43..c85b185 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/DarellPitchEnvelope.m b/src/DarellPitchEnvelope.m new file mode 100644 index 0000000..f0922ca --- /dev/null +++ b/src/DarellPitchEnvelope.m @@ -0,0 +1,37 @@ +function output = DarellPitchEnvelope(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 \ No newline at end of file diff --git a/DarellsAnnex/DarellbandpassFilter.m b/src/DarellbandpassFilter.m similarity index 100% rename from DarellsAnnex/DarellbandpassFilter.m rename to src/DarellbandpassFilter.m diff --git a/src/Main_test.m b/src/Main_test.m index 034d0f6..140b7d8 100644 --- a/src/Main_test.m +++ b/src/Main_test.m @@ -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) \ No newline at end of file +play_continuous(x, fs, playtime) + +attack = 0.2; +decay = 0.2; +sustain = 0.2; +release = 0.1; + +x = DarellPitchEnvelope(x, fs, attack,decay,sustain,release); %output new sound in time domain +%play over 5 counts, should only hear 200hz +playtime = 5; +play_continuous(x, fs, playtime)