(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | == Sound File == | ||
+ | |||
+ | |||
+ | ==MATLAB Code== | ||
+ | |||
+ | <pre> | ||
%Cory Ocker (cocker@purdue.edu) | %Cory Ocker (cocker@purdue.edu) | ||
− | |||
%9/5/08 HW1 | %9/5/08 HW1 | ||
− | |||
%EE301 MWF 4:30 | %EE301 MWF 4:30 | ||
− | |||
clear; | clear; | ||
− | |||
clc; | clc; | ||
− | |||
%first i went to http://www.hoerl.com/Music/music1_basic.html and read a | %first i went to http://www.hoerl.com/Music/music1_basic.html and read a | ||
− | |||
%tutorial on music because I don't know diddly about music notes | %tutorial on music because I don't know diddly about music notes | ||
− | |||
%define notes using | %define notes using | ||
− | |||
%http://www.techlib.com/reference/musical_note_frequencies.htm | %http://www.techlib.com/reference/musical_note_frequencies.htm | ||
− | |||
A =220; | A =220; | ||
− | |||
B =246.94; | B =246.94; | ||
− | |||
C =261.64; | C =261.64; | ||
− | |||
Db =277.20; | Db =277.20; | ||
− | |||
D =293.68; | D =293.68; | ||
− | |||
E =329.64; | E =329.64; | ||
− | |||
F =349.24; | F =349.24; | ||
− | |||
Gb =370; | Gb =370; | ||
− | |||
G =392; | G =392; | ||
− | |||
− | |||
%define delta | %define delta | ||
− | |||
delta =1/20000; | delta =1/20000; | ||
− | |||
− | |||
%define beats (can range from 40 bpm to 200 bpm) | %define beats (can range from 40 bpm to 200 bpm) | ||
− | |||
e =.25; | e =.25; | ||
− | |||
q =.5; | q =.5; | ||
− | |||
dq =.75; | dq =.75; | ||
− | |||
h =1; | h =1; | ||
− | |||
dh =1.5; | dh =1.5; | ||
− | |||
w =2; | w =2; | ||
− | |||
− | |||
%timings for notes | %timings for notes | ||
− | |||
lengths =[h,q,q,dq,e,q,q,q,e,e,q,e,e,dh,h,q,q,dq,e,q,q,q,e,e,q,e,e,w,dq,e,... | lengths =[h,q,q,dq,e,q,q,q,e,e,q,e,e,dh,h,q,q,dq,e,q,q,q,e,e,q,e,e,w,dq,e,... | ||
− | |||
q,q,dq,e,q,e,e,q,q,q,q,w,dq,e,q,q,q,q,q,q,dq,e,dq,e,w,w]; | q,q,dq,e,q,e,e,q,q,q,q,w,dq,e,q,q,q,q,q,q,dq,e,dq,e,w,w]; | ||
− | |||
%notes for song | %notes for song | ||
− | |||
notes =[A,B,Db,D,E,Gb,Gb,G,G,G,D,E,F,Gb,Gb,Gb,E,D,E,Gb,Gb,E,B,Db,D,Db,B,E,... | notes =[A,B,Db,D,E,Gb,Gb,G,G,G,D,E,F,Gb,Gb,Gb,E,D,E,Gb,Gb,E,B,Db,D,Db,B,E,... | ||
− | |||
A,A,B,Db,D,E,Gb,Gb,Gb,G,G,D,E,Gb,B,Db,D,B,A,D,Gb,A,B,Gb,E,D,D]; | A,A,B,Db,D,E,Gb,Gb,Gb,G,G,D,E,Gb,B,Db,D,B,A,D,Gb,A,B,Gb,E,D,D]; | ||
− | |||
− | |||
− | |||
%regular speed | %regular speed | ||
− | |||
for lcv =1:length(notes) | for lcv =1:length(notes) | ||
− | |||
t =0:delta:lengths(lcv); | t =0:delta:lengths(lcv); | ||
− | |||
wave =sin(2*pi*t*notes(lcv)); | wave =sin(2*pi*t*notes(lcv)); | ||
− | |||
sound(wave,1/delta); | sound(wave,1/delta); | ||
− | |||
end | end | ||
− | |||
− | |||
− | |||
pause(5) | pause(5) | ||
− | |||
− | |||
%double speed | %double speed | ||
− | |||
for lcv =1:length(notes) | for lcv =1:length(notes) | ||
− | |||
t =0:delta:1/2*lengths(lcv); | t =0:delta:1/2*lengths(lcv); | ||
− | |||
wave =sin(2*pi*t*notes(lcv)); | wave =sin(2*pi*t*notes(lcv)); | ||
− | |||
sound(wave,1/delta); | sound(wave,1/delta); | ||
− | |||
end | end | ||
− | |||
− | |||
pause(5) | pause(5) | ||
− | |||
− | |||
%3/4 speed (sounds the best to me after testing) | %3/4 speed (sounds the best to me after testing) | ||
− | |||
for lcv =1:length(notes) | for lcv =1:length(notes) | ||
− | |||
t =0:delta:3/4*lengths(lcv); | t =0:delta:3/4*lengths(lcv); | ||
− | |||
wave =sin(2*pi*t*notes(lcv)); | wave =sin(2*pi*t*notes(lcv)); | ||
− | |||
sound(wave,1/delta); | sound(wave,1/delta); | ||
− | |||
end | end | ||
− | |||
− | |||
pause(5) | pause(5) | ||
− | |||
− | |||
%doubles the frequencies | %doubles the frequencies | ||
− | |||
for lcv =1:length(notes) | for lcv =1:length(notes) | ||
− | |||
t =0:delta:lengths(lcv); | t =0:delta:lengths(lcv); | ||
− | |||
wave =sin(2*2*pi*t*notes(lcv)); | wave =sin(2*2*pi*t*notes(lcv)); | ||
− | |||
sound(wave,1/delta); | sound(wave,1/delta); | ||
− | |||
end | end | ||
+ | </pre> |
Latest revision as of 15:27, 3 September 2008
Sound File
MATLAB Code
%Cory Ocker (cocker@purdue.edu) %9/5/08 HW1 %EE301 MWF 4:30 clear; clc; %first i went to http://www.hoerl.com/Music/music1_basic.html and read a %tutorial on music because I don't know diddly about music notes %define notes using %http://www.techlib.com/reference/musical_note_frequencies.htm A =220; B =246.94; C =261.64; Db =277.20; D =293.68; E =329.64; F =349.24; Gb =370; G =392; %define delta delta =1/20000; %define beats (can range from 40 bpm to 200 bpm) e =.25; q =.5; dq =.75; h =1; dh =1.5; w =2; %timings for notes lengths =[h,q,q,dq,e,q,q,q,e,e,q,e,e,dh,h,q,q,dq,e,q,q,q,e,e,q,e,e,w,dq,e,... q,q,dq,e,q,e,e,q,q,q,q,w,dq,e,q,q,q,q,q,q,dq,e,dq,e,w,w]; %notes for song notes =[A,B,Db,D,E,Gb,Gb,G,G,G,D,E,F,Gb,Gb,Gb,E,D,E,Gb,Gb,E,B,Db,D,Db,B,E,... A,A,B,Db,D,E,Gb,Gb,Gb,G,G,D,E,Gb,B,Db,D,B,A,D,Gb,A,B,Gb,E,D,D]; %regular speed for lcv =1:length(notes) t =0:delta:lengths(lcv); wave =sin(2*pi*t*notes(lcv)); sound(wave,1/delta); end pause(5) %double speed for lcv =1:length(notes) t =0:delta:1/2*lengths(lcv); wave =sin(2*pi*t*notes(lcv)); sound(wave,1/delta); end pause(5) %3/4 speed (sounds the best to me after testing) for lcv =1:length(notes) t =0:delta:3/4*lengths(lcv); wave =sin(2*pi*t*notes(lcv)); sound(wave,1/delta); end pause(5) %doubles the frequencies for lcv =1:length(notes) t =0:delta:lengths(lcv); wave =sin(2*2*pi*t*notes(lcv)); sound(wave,1/delta); end