%Hw1 ECE301S11
%Bob Wujek
clc, clear
%%%%%Playing Music%%%%%
%Defining base variables
beat = 60/112; %Defines length of each beat using 112 bpm
delta = .00005; %Defines step size for the time variable
f_A = 440; %Defines frequency of an A4 note
%Defining note lengths
Qnote = 0:delta:beat; %Defines length of a quarter note
Hnote = 0:delta:beat*2; %Defines length of a half note
Enote = 0:delta:beat/2; %Defines length of an eighth note
DQnote = 0:delta:beat*3/2; %Defines length of a dotted quarter note
%Defining notes in terms of A4 note and appropriate lengths
Q_G = sin(2*pi*2^(-2/12)*f_A*Qnote); %Defines quarter G note
Q_Bflat = sin(2*pi*2^(1/12)*f_A*Qnote); %Defines quarter B flat note
DQ_C = sin(2*pi*2^(3/12)*f_A*DQnote); %Defines dotted quarter C note
E_Dflat = sin(2*pi*2^(4/12)*f_A*Enote); %Defines eighth D flat note
H_C = sin(2*pi*2^(3/12)*f_A*Hnote); %Defines half C note
%Defining transformed notes
nQ_G = sin(2*pi*2^(-2/12)*f_A*Qnote*2); %Defines new quarter G note
nQ_Bflat = sin(2*pi*2^(1/12)*f_A*Qnote*2); %Defines new quarter B flat note
nDQ_C = sin(2*pi*2^(3/12)*f_A*DQnote*2); %Defines new dotted quarter C note
nE_Dflat = sin(2*pi*2^(4/12)*f_A*Enote*2); %Defines new eighth D flat note
nH_C = sin(2*pi*2^(3/12)*f_A*Hnote*2); %Defines new half C note
%Defining rests
E_rest = zeros(1,beat/delta/2); %Defines an eighth rest
H_rest = zeros(1,beat/delta*2); %Defines a half rest
%Arranging the notes in the correct order according to the provided score
Smoke_Water_1 = [Q_G, Q_Bflat, DQ_C, Q_G, Q_Bflat, E_Dflat, H_C, Q_G,...
Q_Bflat, DQ_C, Q_Bflat, Q_G, E_rest, H_rest]; %The original score
Smoke_Water_2 = Smoke_Water_1;
Smoke_Water_3 = [nQ_G, nQ_Bflat, nDQ_C, nQ_G, nQ_Bflat, nE_Dflat, nH_C,...
nQ_G, nQ_Bflat, nDQ_C, nQ_Bflat, nQ_G, E_rest, H_rest]; %The transformed score
%Playing the 3 songs
sound(Smoke_Water_1, 1/delta); %Plays song at original tempo
sound(Smoke_Water_2, 2/delta); %Plays song at doubled tempo
sound(Smoke_Water_3, 1/delta); %Plays transformed song
%Creating wave files for each song
wavwrite(Smoke_Water_1, 1/delta, 'SmokeontheWater');
%Writes original song to a wav file
wavwrite(Smoke_Water_2, 2/delta, 'SmokeontheWater2xfast');
%Writes song at double speed to a wav file
wavwrite(Smoke_Water_3, 1/delta, 'SmokeontheWatertransformed');
%Writes transformed song to a wav file
%%%%%Hidden Backward Message%%%%%
clc, clear
[Beatles, f] = wavread('Beatles.wav'); %Records the song into 'Beatles'
Backward_Song = flipud(Beatles); %Records the song into 'Backward_Song'
sound(Backward_Song, f); %Plays the song, 'Backward_Song'
wavwrite(Backward_Song, f, 'BackwardBeatlesSong'); %Writes the song to a wav file
%%%The song plays the phrase "Number Nine" repeatedly
%%%While played in reverse, the phrase seems to be "Turn Me On Dead Man"
Media:SmokeontheWater2xfast.wav