Merge pull request #5 from ltcptgeneral/DarellsAnnex
DarellsAnnex updates to include DarellPitchEnvelope and DarellBandPassFilter Examples
This commit is contained in:
commit
210575ea62
10
README.md
10
README.md
@ -6,14 +6,16 @@
|
|||||||
|
|
||||||
## Function Prototypes
|
## 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)
|
fuction x = envelope(input, fs, period, attack , decay, sustain, release)
|
||||||
where attack, decay, sustain release are percentages between 0 to 1 of the period
|
where attack, decay, release are percentages between 0 to 1 of the period
|
||||||
where period is the time in seconds
|
sustain is the percentage of the amplitude it should sustain for
|
||||||
|
**envelope can be pitch or amplitude envelope**
|
||||||
|
|
||||||
function output_timedomain = Filter(input_soundin_timedomain, Fs, LOW, MED, HIGH)
|
function output_timedomain = Filter(input_soundin_timedomain, Fs, LOW, MED, HIGH)
|
||||||
where LOW, MED, HIGH are user-selected variables of any value. **try to make an envelope for the filter as well**
|
where LOW, MED, HIGH are user-selected variables of any value.
|
||||||
|
**output should be in time domain for all functions (new sound)**
|
||||||
|
|
||||||
## Useful websites
|
## Useful websites
|
||||||
|
|
||||||
|
BIN
src/.DS_Store
vendored
Normal file
BIN
src/.DS_Store
vendored
Normal file
Binary file not shown.
37
src/DarellPitchEnvelope.m
Normal file
37
src/DarellPitchEnvelope.m
Normal file
@ -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
|
20
src/DarellbandpassFilter.m
Normal file
20
src/DarellbandpassFilter.m
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
function output_y = DarellbandpassFilter(y,Fs,LOW,MED,HIGH)
|
||||||
|
Len = length(y);
|
||||||
|
F = Fs * (-Len/2 : (Len/2 - 1))/Len ;
|
||||||
|
Mod_Freq = fftshift(fft(y));
|
||||||
|
lenf = length(F);
|
||||||
|
output = 0 .* Mod_Freq; % zero array of len f
|
||||||
|
|
||||||
|
for n = 1:lenf
|
||||||
|
if ((LOW < abs(F(n))) && HIGH > abs(F(n)))
|
||||||
|
output(n) = 1;
|
||||||
|
else
|
||||||
|
output(n) = 0;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
filtered_Mod_Freq = fftshift(Mod_Freq .* output);
|
||||||
|
|
||||||
|
output_y = real(ifft(filtered_Mod_Freq));
|
||||||
|
|
||||||
|
end
|
@ -11,7 +11,7 @@ duty = 0;
|
|||||||
x = generate_sine(amplitude, frequency, phase, fs, duration, duty);
|
x = generate_sine(amplitude, frequency, phase, fs, duration, duty);
|
||||||
x = x + generate_sine(amplitude, (frequency+5), phase, fs, duration, duty);
|
x = x + generate_sine(amplitude, (frequency+5), phase, fs, duration, duty);
|
||||||
|
|
||||||
%play over 5 counts, should hear both frequencies, 5 beats between the 2 frequencies
|
%play over 5 counts, should hear both frequencies, 5 beats per second between the 2 frequencies
|
||||||
playtime = 5;
|
playtime = 5;
|
||||||
play_continuous(x, fs, playtime)
|
play_continuous(x, fs, playtime)
|
||||||
|
|
||||||
@ -22,4 +22,15 @@ x = DarellbandpassFilter(x,fs,LOW,MED,HIGH);
|
|||||||
|
|
||||||
%play over 5 counts, should only hear 200hz
|
%play over 5 counts, should only hear 200hz
|
||||||
playtime = 5;
|
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 = 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)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user