%% Fun with Music

tVals = linspace(0, 5, 5*8192);

A = @(x) cos(2*pi*220*x);
AS = @(x) cos(2*pi*220*2^(1/12)*x);
B = @(x) cos(2*pi*220*2^(2/12)*x);
C = @(x) cos(2*pi*220*2^(3/12)*x);
CS = @(x) cos(2*pi*220*2^(4/12)*x);
D = @(x) cos(2*pi*220*2^(5/12)*x);
DS = @(x) cos(2*pi*220*2^(6/12)*x);
E = @(x) cos(2*pi*220*2^(7/12)*x);
F = @(x) cos(2*pi*220*2^(8/12)*x);
FS = @(x) cos(2*pi*220*2^(9/12)*x);
G = @(x) cos(2*pi*220*2^(10/12)*x);
GS = @(x) cos(2*pi*220*2^(11/12)*x);
A2 = @(x) cos(2*pi*220*2^(12/12)*x);

AMaj = @(x) (A(x) + CS(x) + E(x) + A2(x))/4;
EMaj = @(x) (E(x) + GS(x) + B(x) + D(x))/4;
DMaj = @(x) (D(x) + FS(x) + A(x) + A2(x))/4;
BMin = @(x) (B(x) + D(x) + FS(x))/3;

prog = @(x) (x < 1).*AMaj(x) + (x >= 1) .* (x < 2).*DMaj(x) + (x >= 2).*( x < 3).*BMin(x) + (x >= 3).*(x < 4).*EMaj(x) + (x >= 4).*AMaj(x);

sound(prog(tVals));
