admin 管理员组文章数量: 887021
2024年1月24日发(作者:变量名中包含非法字符什么意思)
function liyugang()
%Matlab版《新贵妃醉酒》
words1 = [3 5 6 1 7 1 7 5 7 7 6 3 5 6 1 6 1 6 2 5 5 3;
0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0;
0.5 0.5 1 1 0.5 0.25 0.25 0.5 0.5 1 2 0.5 0.5 1 1 0.5
0.25 0.25 0.5 0.5 1 3];
words2 = [6 3 2 7 6 1 6 5 3 5 3 2 1 6 5 1 1 6 3 5 6 1 7 5 7 7 6;
0 1 1 0 0 1 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 0 0 0 0
0;
1 1 0.5 0.5 0.5 0.25 0.25 0.5 0.5 3 1 1 0.5 0.5 0.5
0.5 1 2 0.5 0.5 1 1 1 0.5 0.5 1 2];
words3 = [3 5 6 1 6 2 5 5 3 6 3 2 7 6 1 6 5 3 5 3 2 1 6 5 1 1 6;
0 0 0 1 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 1 1 0 0 1 1
0;
0.5 0.5 1 1 1 0.5 0.5 1 3 1 1 0.5 0.5 0.5 0.25 0.25
0.5 0.5 3 1 1 0.5 0.5 0.5 0.5 1 3];
y1 = generaterhythm(words1, 3); % in bE tune
y2 = generaterhythm(words2, 3); % in bE tune
y3 = generaterhythm(words3, 3); % in bE tune
lxg = [y1,y2,y3];
sound(lxg,12000); % play it!
%% generate a piece of rhythm
function y = generaterhythm(rhythm, basetune)
fs = 8000;
soundpos = [0 2 4 5 7 9 11 0:12];
y = zeros(1, sum(rhythm(3,:))*fs + 1); % initialize
curpos = 1;
for count = 1 : length(rhythm)
cursoundname = rhythm(1, count);
cursoundpos = soundpos(cursoundname);
curfreq = 220 * 2 .^ ((cursoundpos + basetune + 3) / 12 + rhythm(2, count));
cursound = generatetune(curfreq, rhythm(3, count), fs);
y(1,curpos:(curpos + length(cursound) - 1)) = cursound;
curpos = curpos + length(cursound);
end
function y = generatetune (freq, time, fs)
y1 = generatetune2 (freq + 3, time, fs);
y2 = generatetune2 (freq - 3, time, fs);
y3 = generatetune2 (freq, time, fs);
y = (y1 + y2) / 8 + y3 * (3 / 4);
function y = generatetune2 (freq, time, fs)
c = [ 1 0.2 0.4 0.08 0.2 0.05 0.1 0.04 ];
t = 0:1/fs:(time - 1/fs);
y = zeros(1, length(t));
for j = 1 : 8
y = y + c(j) * sin(t*j*freq*2*pi);
end
for count1 = 1 : length(y)
y(1, count1) = y(1, count1) * amendment(count1 / 2000, length(y)
/ 2000);
end
function y = amendment(p, l)
if p < 0.2
y = p * 5;
elseif p < 0.3
y = 1.8 - p * 4;
else
y = 0.6 * exp((0.3 - p)/5);
end
% Cripple Pachebel's Canon on Matlab
% Have fun
fs = 44100; % sample rate
dt = 1/fs;
T16 = 0.125;
t16 = [0:dt:T16];
[temp k] = size(t16);
t4 = linspace(0,4*T16,4*k);
t8 = linspace(0,2*T16,2*k);
[temp i] = size(t4);
[temp j] = size(t8);
% Modification functions
mod4 = sin(pi*t4/t4(end));
mod8 = sin(pi*t8/t8(end));
mod16 = sin(pi*t16/t16(end));
f0 = 2*146.8; % reference frequency
ScaleTable = [2/3 3/4 5/6 15/16 ...
1 9/8 5/4 4/3 3/2 5/3 9/5 15/8 ...
2 9/4 5/2 8/3 3 10/3 15/4 4 ...
1/2 9/16 5/8];
% 1/4 notes
do0f = mod4.*cos(2*pi*ScaleTable(21)*f0*t4);
re0f = mod4.*cos(2*pi*ScaleTable(22)*f0*t4);
mi0f = mod4.*cos(2*pi*ScaleTable(23)*f0*t4);
fa0f = mod4.*cos(2*pi*ScaleTable(1)*f0*t4);
so0f = mod4.*cos(2*pi*ScaleTable(2)*f0*t4);
la0f = mod4.*cos(2*pi*ScaleTable(3)*f0*t4);
ti0f = mod4.*cos(2*pi*ScaleTable(4)*f0*t4);
do1f = mod4.*cos(2*pi*ScaleTable(5)*f0*t4);
re1f = mod4.*cos(2*pi*ScaleTable(6)*f0*t4);
mi1f = mod4.*cos(2*pi*ScaleTable(7)*f0*t4);
fa1f = mod4.*cos(2*pi*ScaleTable(8)*f0*t4);
so1f = mod4.*cos(2*pi*ScaleTable(9)*f0*t4);
la1f = mod4.*cos(2*pi*ScaleTable(10)*f0*t4);
tb1f = mod4.*cos(2*pi*ScaleTable(11)*f0*t4);
ti1f = mod4.*cos(2*pi*ScaleTable(12)*f0*t4);
do2f = mod4.*cos(2*pi*ScaleTable(13)*f0*t4);
re2f = mod4.*cos(2*pi*ScaleTable(14)*f0*t4);
mi2f = mod4.*cos(2*pi*ScaleTable(15)*f0*t4);
fa2f = mod4.*cos(2*pi*ScaleTable(16)*f0*t4);
so2f = mod4.*cos(2*pi*ScaleTable(17)*f0*t4);
la2f = mod4.*cos(2*pi*ScaleTable(18)*f0*t4);
ti2f = mod4.*cos(2*pi*ScaleTable(19)*f0*t4);
do3f = mod4.*cos(2*pi*ScaleTable(20)*f0*t4);
blkf = zeros(1,i);
% 1/8 notes
fa0e = mod8.*cos(2*pi*ScaleTable(1)*f0*t8);
so0e = mod8.*cos(2*pi*ScaleTable(2)*f0*t8);
la0e = mod8.*cos(2*pi*ScaleTable(3)*f0*t8);
ti0e = mod8.*cos(2*pi*ScaleTable(4)*f0*t8);
do1e = mod8.*cos(2*pi*ScaleTable(5)*f0*t8);
re1e = mod8.*cos(2*pi*ScaleTable(6)*f0*t8);
mi1e = mod8.*cos(2*pi*ScaleTable(7)*f0*t8);
fa1e = mod8.*cos(2*pi*ScaleTable(8)*f0*t8);
so1e = mod8.*cos(2*pi*ScaleTable(9)*f0*t8);
la1e = mod8.*cos(2*pi*ScaleTable(10)*f0*t8);
tb1e = mod8.*cos(2*pi*ScaleTable(11)*f0*t8);
ti1e = mod8.*cos(2*pi*ScaleTable(12)*f0*t8);
do2e = mod8.*cos(2*pi*ScaleTable(13)*f0*t8);
re2e = mod8.*cos(2*pi*ScaleTable(14)*f0*t8);
mi2e = mod8.*cos(2*pi*ScaleTable(15)*f0*t8);
fa2e = mod8.*cos(2*pi*ScaleTable(16)*f0*t8);
so2e = mod8.*cos(2*pi*ScaleTable(17)*f0*t8);
la2e = mod8.*cos(2*pi*ScaleTable(18)*f0*t8);
ti2e = mod8.*cos(2*pi*ScaleTable(19)*f0*t8);
do3e = mod8.*cos(2*pi*ScaleTable(20)*f0*t8);
blke = zeros(1,j);
% 1/16 notes
fa0s = mod16.*cos(2*pi*ScaleTable(1)*f0*t16);
so0s = mod16.*cos(2*pi*ScaleTable(2)*f0*t16);
la0s = mod16.*cos(2*pi*ScaleTable(3)*f0*t16);
ti0s = mod16.*cos(2*pi*ScaleTable(4)*f0*t16);
do1s = mod16.*cos(2*pi*ScaleTable(5)*f0*t16);
re1s = mod16.*cos(2*pi*ScaleTable(6)*f0*t16);
mi1s = mod16.*cos(2*pi*ScaleTable(7)*f0*t16);
fa1s = mod16.*cos(2*pi*ScaleTable(8)*f0*t16);
so1s = mod16.*cos(2*pi*ScaleTable(9)*f0*t16);
la1s = mod16.*cos(2*pi*ScaleTable(10)*f0*t16);
tb1s = mod16.*cos(2*pi*ScaleTable(11)*f0*t16);
ti1s = mod16.*cos(2*pi*ScaleTable(12)*f0*t16);
do2s = mod16.*cos(2*pi*ScaleTable(13)*f0*t16);
re2s = mod16.*cos(2*pi*ScaleTable(14)*f0*t16);
mi2s = mod16.*cos(2*pi*ScaleTable(15)*f0*t16);
fa2s = mod16.*cos(2*pi*ScaleTable(16)*f0*t16);
so2s = mod16.*cos(2*pi*ScaleTable(17)*f0*t16);
la2s = mod16.*cos(2*pi*ScaleTable(18)*f0*t16);
ti2s = mod16.*cos(2*pi*ScaleTable(19)*f0*t16);
do3s = mod16.*cos(2*pi*ScaleTable(20)*f0*t16);
blks = zeros(1,k);
% Blank Block
blkblock = [blkf blkf blkf blkf blkf blkf
blkf blkf blkf blkf blkf blkf blkf blkf];
% Base Melody
cello = [do1f do1f so0f so0f la0f la0f
fa0f fa0f do0f do0f fa0f fa0f so0f so0f];
% So-FUCKING-Long Melody
violin = [mi2f mi2f re2f re2f do2f do2f
la1f la1f so1f so1f la1f la1f ti1f ti1f ...%
do2f do2f ti1f ti1f la1f la1f
fa1f fa1f mi1f mi1f fa1f fa1f re1f re1f ...%
do1f mi1f so1f fa1f mi1f do1f
do1f la0f do1f so1f fa1f la1f %
mi1f do1f re1f ti1f do2f mi2f
la1f fa1f so1f mi1f do1f do2f blkf blke ti1e ...%
do2e ti1e do2e do1e ti0e so1e
do1e do2e ti1e la1e ti1e mi2e
fa2e mi2e re2e fa2e mi2e re2e
la1e so1e fa1e mi1e re1e fa1e %%
do1e re1e mi1e fa1e so1e re1e
mi1e la1e so1e fa1e so1e fa1e
do1e la0e la1e ti1e do2e ti1e
fa1e mi1e re1e la1e so1e la1e %
mi1f mi2e blke re2f re2f blkf do1f
la2f la2f so2f so2f la2f la2f %
do3e blke do2e blke ti1f ti1f blkf la1f
do2f do2f do2f do2f do2f fa2f %
so2e mi2s fa2s so2e mi2s fa2s so2s so1s la1s ti1s ...
do2s re2s mi2s fa2s mi2e
mi2e mi1s fa1s so1s la1s so1s fa1s so1s mi1s
fa1e la1s so1s fa1e mi1s re1s mi1s re1s do1s re1s mi1s fa1s
fa2e la1s so1s la1e ti1s do2s so1s la1s ti1s do2s re2s mi2s %
mi2e do2s re2s mi2e re2s do2s re2s ti1s do2s re2s mi2s re2s
do2e la1s ti1s do2e do1s re1s mi1s fa1s mi1s re1s mi1s do2s
la1e do2s ti1s la1e so1s fa1s so1s fa1s mi1s fa1s so1s la1s
la2e do2s ti1s do2e ti1s la1s ti1s do2s re2s do2s ti1s do1s %%
do2e blke blkf ti1e blke blkf la1e blke blkf do2e
do1e blke blkf do1e blke blkf do1e blke blkf do1e %
blkf so1e blke blkf so1e blke blkf mi1e blke blkf
blkf fa1e blke blkf mi1e blke blkf fa1e blke blkf %
mi2e mi1e fa1e mi1e re1e re2e mi2e re2e do2e mi1e do1e do2e ti1e so0e
la0e la1e so1e la1e so1e so0e fa0e so0e do1e la1e so1e la1e ti1e ti0e %
do1e do2e re2e do2e ti1e ti0e do1e ti0e la0e la1e so1e la1e ti1e ti0e
do1e do2e re2e fa2e mi2e mi1e so1e mi2e do2e fa2e mi2e fa2e re2e so1e %
mi1e so1e so1e so1e so1e so1e so1e so1e mi1e mi1e mi1e mi1e mi1e mi1e
fa1e fa1e fa1e do2e do2e do2e do2e do2e do2e do2e la1e la1e so1e so1e %%
so1e mi2e mi2e mi2e re2e re2e re2e re2e do2e do2e do2e do2e so2e so2e
la2e la2e la2e la2e so2e so2e so2e so2e la2e la2e la2e la2e ti2e ti1e %
do2e do1s re1s mi1e do1e ti0e ti1s do2s re2e ti1e la1e la0s ti0s do1e la0e ti0e so1s fa1s mi1e
do1e mi1s re1s do1e fa1e mi1e do1s re1s mi1e so1e fa1e la1s so1s fa1e mi1e re1e so1s fa1s
%
mi1e do2s ti1s do2e mi1e so1e so1s la1s ti1e so1e mi1e do2s re2s mi2e do2e mi2e mi2s re2s
la1e la1s so1s la1e ti1e do2e mi2s re2s do2e mi2e fa2e do2s ti1s la1e la1e so1e re1e so1e
%
so1f so1f so1f so1f do1f do1f
fa1f fa1f so1f so1f fa1f do1f do1f %
do1f do2f ti1f ti1f la1f la1f
do1f do1e re1e mi1f mi1f do2f do2f %%
do2f];
% cello
c1 = [cello cello cello
cello cello cello
cello cello cello
cello cello cello
cello cello cello blkf];
% violin1
v1 = [blkblock violin blkblock blkblock];
% violin2
v2 = [blkblock blkblock violin blkblock];
% violin3
v3 = [blkblock blkblock blkblock violin];
% Get dirty
s = c1+v1+v2+v3;
s = s/max(s);
sound(s,fs)
fs = 44100; % sample rate
dt = 1/fs;
T16 = 0.125;
t16 = [0:dt:T16];
[temp k] = size(t16);
t4 = linspace(0,4*T16,4*k);
t8 = linspace(0,2*T16,2*k);
[temp i] = size(t4);
[temp j] = size(t8);
% Modification functions
mod4=(t4.^4).*exp(-30*(t4.^0.5));
mod4=mod4*(1/max(mod4));
mod8=(t8.^4).*exp(-50*(t8.^0.5));
mod8=mod8*(1/max(mod8));
mod16=(t16.^4).*exp(-90*(t16.^0.5));
mod16=mod16*(1/max(mod16));
f0 = 2*146.8; % reference frequency
ScaleTable = [2/3 3/4 5/6 15/16 ...
1 9/8 5/4 4/3 3/2 5/3 9/5 15/8 ...
2 9/4 5/2 8/3 3 10/3 15/4 4 ...
1/2 9/16 5/8];
% 1/4 notes
do0f = mod4.*cos(2*pi*ScaleTable(21)*f0*t4);
re0f = mod4.*cos(2*pi*ScaleTable(22)*f0*t4);
mi0f = mod4.*cos(2*pi*ScaleTable(23)*f0*t4);
fa0f = mod4.*cos(2*pi*ScaleTable(1)*f0*t4);
so0f = mod4.*cos(2*pi*ScaleTable(2)*f0*t4);
la0f = mod4.*cos(2*pi*ScaleTable(3)*f0*t4);
ti0f = mod4.*cos(2*pi*ScaleTable(4)*f0*t4);
do1f = mod4.*cos(2*pi*ScaleTable(5)*f0*t4);
re1f = mod4.*cos(2*pi*ScaleTable(6)*f0*t4);
mi1f = mod4.*cos(2*pi*ScaleTable(7)*f0*t4);
fa1f = mod4.*cos(2*pi*ScaleTable(8)*f0*t4);
so1f = mod4.*cos(2*pi*ScaleTable(9)*f0*t4);
la1f = mod4.*cos(2*pi*ScaleTable(10)*f0*t4);
tb1f = mod4.*cos(2*pi*ScaleTable(11)*f0*t4);
ti1f = mod4.*cos(2*pi*ScaleTable(12)*f0*t4);
do2f = mod4.*cos(2*pi*ScaleTable(13)*f0*t4);
re2f = mod4.*cos(2*pi*ScaleTable(14)*f0*t4);
mi2f = mod4.*cos(2*pi*ScaleTable(15)*f0*t4);
fa2f = mod4.*cos(2*pi*ScaleTable(16)*f0*t4);
so2f = mod4.*cos(2*pi*ScaleTable(17)*f0*t4);
la2f = mod4.*cos(2*pi*ScaleTable(18)*f0*t4);
ti2f = mod4.*cos(2*pi*ScaleTable(19)*f0*t4);
do3f = mod4.*cos(2*pi*ScaleTable(20)*f0*t4);
blkf = zeros(1,i);
% 1/8 notes
do0e = mod8.*cos(2*pi*ScaleTable(21)*f0*t8);
re0e = mod8.*cos(2*pi*ScaleTable(22)*f0*t8);
mi0e = mod8.*cos(2*pi*ScaleTable(23)*f0*t8);
fa0e = mod8.*cos(2*pi*ScaleTable(1)*f0*t8);
so0e = mod8.*cos(2*pi*ScaleTable(2)*f0*t8);
la0e = mod8.*cos(2*pi*ScaleTable(3)*f0*t8);
ti0e = mod8.*cos(2*pi*ScaleTable(4)*f0*t8);
do1e = mod8.*cos(2*pi*ScaleTable(5)*f0*t8);
re1e = mod8.*cos(2*pi*ScaleTable(6)*f0*t8);
mi1e = mod8.*cos(2*pi*ScaleTable(7)*f0*t8);
fa1e = mod8.*cos(2*pi*ScaleTable(8)*f0*t8);
so1e = mod8.*cos(2*pi*ScaleTable(9)*f0*t8);
la1e = mod8.*cos(2*pi*ScaleTable(10)*f0*t8);
tb1e = mod8.*cos(2*pi*ScaleTable(11)*f0*t8);
ti1e = mod8.*cos(2*pi*ScaleTable(12)*f0*t8);
do2e = mod8.*cos(2*pi*ScaleTable(13)*f0*t8);
re2e = mod8.*cos(2*pi*ScaleTable(14)*f0*t8);
mi2e = mod8.*cos(2*pi*ScaleTable(15)*f0*t8);
fa2e = mod8.*cos(2*pi*ScaleTable(16)*f0*t8);
so2e = mod8.*cos(2*pi*ScaleTable(17)*f0*t8);
la2e = mod8.*cos(2*pi*ScaleTable(18)*f0*t8);
ti2e = mod8.*cos(2*pi*ScaleTable(19)*f0*t8);
do3e = mod8.*cos(2*pi*ScaleTable(20)*f0*t8);
blke = zeros(1,j);
% 1/16 notes
do0s = mod16.*cos(2*pi*ScaleTable(21)*f0*t16);
re0s = mod16.*cos(2*pi*ScaleTable(22)*f0*t16);
mi0s = mod16.*cos(2*pi*ScaleTable(23)*f0*t16);
fa0s = mod16.*cos(2*pi*ScaleTable(1)*f0*t16);
so0s = mod16.*cos(2*pi*ScaleTable(2)*f0*t16);
la0s = mod16.*cos(2*pi*ScaleTable(3)*f0*t16);
ti0s = mod16.*cos(2*pi*ScaleTable(4)*f0*t16);
do1s = mod16.*cos(2*pi*ScaleTable(5)*f0*t16);
re1s = mod16.*cos(2*pi*ScaleTable(6)*f0*t16);
mi1s = mod16.*cos(2*pi*ScaleTable(7)*f0*t16);
fa1s = mod16.*cos(2*pi*ScaleTable(8)*f0*t16);
so1s = mod16.*cos(2*pi*ScaleTable(9)*f0*t16);
la1s = mod16.*cos(2*pi*ScaleTable(10)*f0*t16);
tb1s = mod16.*cos(2*pi*ScaleTable(11)*f0*t16);
ti1s = mod16.*cos(2*pi*ScaleTable(12)*f0*t16);
do2s = mod16.*cos(2*pi*ScaleTable(13)*f0*t16);
re2s = mod16.*cos(2*pi*ScaleTable(14)*f0*t16);
mi2s = mod16.*cos(2*pi*ScaleTable(15)*f0*t16);
fa2s = mod16.*cos(2*pi*ScaleTable(16)*f0*t16);
so2s = mod16.*cos(2*pi*ScaleTable(17)*f0*t16);
la2s = mod16.*cos(2*pi*ScaleTable(18)*f0*t16);
ti2s = mod16.*cos(2*pi*ScaleTable(19)*f0*t16);
do3s = mod16.*cos(2*pi*ScaleTable(20)*f0*t16);
blks = zeros(1,k);
% Melody by Schau_mal
part0 = [mi1f la0e la0e do1f mi1f ...
re1e re1s mi1s re1e do1e re1e do1e la0f ...
mi1f la0e la0e do1f mi1f ...
so1e re1s mi1s re1e do1e re1e do1e ti0e so0e ...
mi1f la0e la0e do1f mi1f ...
re1e re1s mi1s re1e do1e re1e do1e la0e so0e ...
mi1f la0e la0e do1f mi1f ...
so1e mi1e blkf blkf blkf ...
];
part1 = [la0f la0e so0e la0f la0e do1e ...
do1f re1e do1e la0f la0f ...
do1f do1e so0e do1e re1e mi1e so1e ...
so1e mi1e re1f mi1f mi1f ...
la1e la1e la1e so1e mi1e mi1f do1e ...
la0e la0e la0e mi1e re1s mi1s re1e re1f ...
mi1e mi1e so1e mi1e re1e mi1e re1e do1e ...
la0f so0f la0f la0f ...
];
part2 = [mi1e mi1e so1e mi1e mi1e so1e so1e la1e ...
do2e la1e so1f la1s do2s la1e la1f ...
la0f la0e so0e la0f do1f ...
re1e mi1s re1s do1e re1e mi1f mi1f ...
la0e la1e la1e so1e re1e mi1s re1s do1e re1e ...
mi1f mi1f blke blke blkf ...
do1e la0e la0e do1e re1f so0e so0e ...
mi1e so1e mi1e re1e do1f do1f ...
la0e do1e re1e mi1e re1e do1e so0e mi0e ...
la0f la0f blke blke blkf ...
];
part3 = [la0f la0e so0e la0f do1f ...
re1e mi1s re1s do1e re1e mi1f mi1f ...
la0e la1e la1e so1e re1e mi1s re1s do1e re1e ...
mi1f mi1f blke blke blkf ...
do1e la0e la0e do1e re1f so0e so0e ...
mi1e so1e mi1e re1e do1f do1e do1e ...
la0e do1e re1e mi1e so1e mi1e mi1e so1e ...
la1f la1f la1f la1f ...
];
part4 = [la1e la1s la1s la1e la1e la1e la1s so1s mi1e re1e ...
re1e re1s re1s mi1e mi1s so1s mi1e mi1s re1s do1e do1s la0s ...
la0f la0e so0e la0f la0e do1e ...
re1e mi1s re1s do1e re1e mi1f mi1f ...
la1e so1e mi1e re1e so1e mi1e re1e do1e ...
do1f do1f la0s do1s re1s mi1s re1s do1s la0s do1s
];
part5 = [do2e do2s do2s la1e la1s la1s so1e so1s so1s mi1e mi1s mi1s ...
re1e mi1s re1s do1e la0s so0s la0s so0s do1s re1s mi1s so1s la1s re2s ...
do2f do2f blks blks blks blks do1e re1e ...
mi1f mi1f mi1f so1e mi1e ...
la1f la1f la1e do1e so1e mi1e ...
re1f re1e re1s re1s re1e re1e do1e re1e ...
mi1f mi1e mi1s mi1s mi1e re1s do1s ti0e do1s re1s ...
mi1f mi1f mi1f so1e mi1e ...
do2f la1f la1f la1e do1e ...
re1f so1f so1f la1f ...
ti1f ti1f ti1f ti1f ...
];
part6 = [blkf blkf mi1e so1e mi1e so1e ...
mi1f la0e la0s la0s do1f la0e mi1s la0s ...
do1e do1s do1s re1e do1s re1s mi1f mi1f ...
mi1f la0e la0s la0s so1f re1e re1s re1s ...
mi1f mi1f mi1s re1s do1s la0s mi0s re0s mi0s so0s ...
do1f la0e la0s la0s re1f so0e so0s so0s ...
mi0f so0e so0s so0s do1f do1f ...
la0f do1e do1s la0s mi1e mi1s mi1s re1e re1s mi1s ...
];
% Combination, v1 is complete version, v2 is simple version.
v1 = [part0 part1 part1 part2 part3 part4 part0 part1 part1 part2 part3 part5 part3 part6 part3];
v2 = [part0 part1 part1 part2 part3 part5 part3 part6 part3];
% Let's rock ^_^
s = v1;
s = s/max(s);
sound(s,fs);
fs=44100;
t=0: 1/fs: 0.5;
ddo= sin(pi*261.63*t);
dre= sin(pi*293.67*t);
dmi= sin(pi*329.63*t);
dfa= sin(pi*349.23*t);
dsol= sin(pi*391.99*t);
dla = sin(pi*440*t);
dxi= sin(pi*493.88*t);
kong=sin(pi*4*t);
zdo=sin(2*pi*261.63*t);
zre= sin(2*pi*293.67*t);
zmi= sin(2*pi*329.63*t);
zfa= sin(2*pi*349.23*t);
zsol= sin(2*pi*391.99*t);
zla = sin(2*pi*440*t);
zxi= sin(2*pi*493.88*t);
gdo= sin(4*pi*261.63*t);
gre= sin(4*pi*293.67*t);
gmi= sin(4*pi*329.63*t);
gfa= sin(4*pi*349.23*t);
gsol= sin(4*pi*391.99*t);
gla = sin(4*pi*440*t);
gxi= sin(4*pi*493.88*t);
part1=[zmi zmi zre zmi kong] %33230
part2=[zla zsol zmi zre zdo zdo kong] %6532110
part3=[zre zmi kong dla zre kong ] %230620
part4=[dla zre zmi zsol zre zmi zre kong] %62352320
part5=[zmi zla zsol zmi zsol zdo dla dla] %36535166
part6=[dsol zre zmi zmi zla zsol kong kong ] %52336500
part7=[zla zsol zsol zmi zsol kong] %655350
part8=[zsol zmi zsol zsol zsol zsol kong] %535550
part9=[gdo zxi zla zsol zmi zre zdo kong] %17653210
part10=[dla zre zmi kong ]
part11=[dsol zre zmi zmi zsol zla zsol kong]%5233565
part12=[zmi zsol zla zsol zmi zre zre zdo kong] %35653221
part13=[dla zre zmi kong dla zre kong] %6230620
part14=[dsol zsol zmi zre dsol zdo] %5532561
lengent=[part1 part2 part3 part4 part1 part5 part3 part6 part7 part8 part9 part10 part10 part11
part8 part10 part12 part13 part14]
sound(lengent, fs)
fs = 44100; % sample rate
dt = 1/fs;
T16 = 0.25;
t16 = [0:dt:T16];
[temp k] = size(t16);
t8=linspace(0,2*T16,2*k);
t8fd=linspace(0,3*T16,3*k);
t4=linspace(0,4*T16,4*k);
t4fd=linspace(0,5*T16,5*k);
t2fd=linspace(0,7*T16,7*k);
t2=linspace(0,6*T16,6*k);
[temp i] = size(t4);
[temp j] = size(t8);
% Modification functions
mod2 = sin(pi*t2/t2(end));
mod2fd=sin(pi*t2fd/t2fd(end));
mod4 = sin(pi*t4/t4(end));
mod4fd=sin(pi*t4fd/t4fd(end));
mod8 = sin(pi*t8/t8(end));
mod8fd=sin(pi*t8fd/t8fd(end));
mod16 = sin(pi*t16/t16(end));
f0 = 2*146.8;
% reference frequency
ScaleTable = 3*[2/3 3/4 5/6 15/16 ...
1 9/8 5/4 4/3 3/2 5/3 9/5 15/8 ...
2 9/4 5/2 8/3 3 10/3 15/4 4 ...
1/2 9/16 5/8]/((2^(1/12)))^5;
% half note
do1h = mod2.*cos(2*pi*ScaleTable(5)*f0*t2);
% dotted minim
so1hfd = mod2fd.*cos(2*pi*ScaleTable(9)*f0*t2fd);
% quarter note
do0f = mod4.*cos(2*pi*ScaleTable(21)*f0*t4);
re0f = mod4.*cos(2*pi*ScaleTable(22)*f0*t4);
mi0f = mod4.*cos(2*pi*ScaleTable(23)*f0*t4);
fa0f = mod4.*cos(2*pi*ScaleTable(1)*f0*t4);
so0f = mod4.*cos(2*pi*ScaleTable(2)*f0*t4);
la0f = mod4.*cos(2*pi*ScaleTable(3)*f0*t4);
ti0f = mod4.*cos(2*pi*ScaleTable(4)*f0*t4);
do1f = mod4.*cos(2*pi*ScaleTable(5)*f0*t4);
re1f = mod4.*cos(2*pi*ScaleTable(6)*f0*t4);
mi1f = mod4.*cos(2*pi*ScaleTable(7)*f0*t4);
fa1f = mod4.*cos(2*pi*ScaleTable(8)*f0*t4);
so1f = mod4.*cos(2*pi*ScaleTable(9)*f0*t4);
la1f = mod4.*cos(2*pi*ScaleTable(10)*f0*t4);
tb1f = mod4.*cos(2*pi*ScaleTable(11)*f0*t4);
ti1f = mod4.*cos(2*pi*ScaleTable(12)*f0*t4);
do2f = mod4.*cos(2*pi*ScaleTable(13)*f0*t4);
re2f = mod4.*cos(2*pi*ScaleTable(14)*f0*t4);
mi2f = mod4.*cos(2*pi*ScaleTable(15)*f0*t4);
fa2f = mod4.*cos(2*pi*ScaleTable(16)*f0*t4);
so2f = mod4.*cos(2*pi*ScaleTable(17)*f0*t4);
la2f = mod4.*cos(2*pi*ScaleTable(18)*f0*t4);
ti2f = mod4.*cos(2*pi*ScaleTable(19)*f0*t4);
do3f = mod4.*cos(2*pi*ScaleTable(20)*f0*t4);
blkf = zeros(1,i);
% dotted quarter note
do0ffd = mod4fd.*cos(2*pi*ScaleTable(21)*f0*t4fd);
re0ffd = mod4fd.*cos(2*pi*ScaleTable(22)*f0*t4fd);
mi0ffd = mod4fd.*cos(2*pi*ScaleTable(23)*f0*t4fd);
fa0ffd = mod4fd.*cos(2*pi*ScaleTable(1)*f0*t4fd);
so0ffd = mod4fd.*cos(2*pi*ScaleTable(2)*f0*t4fd);
la0ffd = mod4fd.*cos(2*pi*ScaleTable(3)*f0*t4fd);
ti0ffd = mod4fd.*cos(2*pi*ScaleTable(4)*f0*t4fd);
do1ffd = mod4fd.*cos(2*pi*ScaleTable(5)*f0*t4fd);
re1ffd = mod4fd.*cos(2*pi*ScaleTable(6)*f0*t4fd);
mi1ffd = mod4fd.*cos(2*pi*ScaleTable(7)*f0*t4fd);
fa1ffd = mod4fd.*cos(2*pi*ScaleTable(8)*f0*t4fd);
so1ffd = mod4fd.*cos(2*pi*ScaleTable(9)*f0*t4fd);
la1ffd = mod4fd.*cos(2*pi*ScaleTable(10)*f0*t4fd);
tb1ffd = mod4fd.*cos(2*pi*ScaleTable(11)*f0*t4fd);
ti1ffd = mod4fd.*cos(2*pi*ScaleTable(12)*f0*t4fd);
do2ffd = mod4fd.*cos(2*pi*ScaleTable(13)*f0*t4fd);
re2ffd = mod4fd.*cos(2*pi*ScaleTable(14)*f0*t4fd);
mi2ffd = mod4fd.*cos(2*pi*ScaleTable(15)*f0*t4fd);
fa2fdf = mod4fd.*cos(2*pi*ScaleTable(16)*f0*t4fd);
so2fdf = mod4fd.*cos(2*pi*ScaleTable(17)*f0*t4fd);
la2fdf = mod4fd.*cos(2*pi*ScaleTable(18)*f0*t4fd);
ti2fdf = mod4fd.*cos(2*pi*ScaleTable(19)*f0*t4fd);
do3fdf = mod4fd.*cos(2*pi*ScaleTable(20)*f0*t4fd);
% eighth note
fa0e = mod8.*cos(2*pi*ScaleTable(1)*f0*t8);
so0e = mod8.*cos(2*pi*ScaleTable(2)*f0*t8);
la0e = mod8.*cos(2*pi*ScaleTable(3)*f0*t8);
ti0e = mod8.*cos(2*pi*ScaleTable(4)*f0*t8);
do1e = mod8.*cos(2*pi*ScaleTable(5)*f0*t8);
re1e = mod8.*cos(2*pi*ScaleTable(6)*f0*t8);
mi1e = mod8.*cos(2*pi*ScaleTable(7)*f0*t8);
fa1e = mod8.*cos(2*pi*ScaleTable(8)*f0*t8);
so1e = mod8.*cos(2*pi*ScaleTable(9)*f0*t8);
la1e = mod8.*cos(2*pi*ScaleTable(10)*f0*t8);
tb1e = mod8.*cos(2*pi*ScaleTable(11)*f0*t8);
ti1e = mod8.*cos(2*pi*ScaleTable(12)*f0*t8);
do2e = mod8.*cos(2*pi*ScaleTable(13)*f0*t8);
re2e = mod8.*cos(2*pi*ScaleTable(14)*f0*t8);
mi2e = mod8.*cos(2*pi*ScaleTable(15)*f0*t8);
fa2e = mod8.*cos(2*pi*ScaleTable(16)*f0*t8);
so2e = mod8.*cos(2*pi*ScaleTable(17)*f0*t8);
la2e = mod8.*cos(2*pi*ScaleTable(18)*f0*t8);
ti2e = mod8.*cos(2*pi*ScaleTable(19)*f0*t8);
do3e = mod8.*cos(2*pi*ScaleTable(20)*f0*t8);
blke = zeros(1,j);
% dotted eighth note
do0efd = mod8fd.*cos(2*pi*ScaleTable(21)*f0*t8fd);
re0efd = mod8fd.*cos(2*pi*ScaleTable(22)*f0*t8fd);
mi0efd = mod8fd.*cos(2*pi*ScaleTable(23)*f0*t8fd);
fa0efd = mod8fd.*cos(2*pi*ScaleTable(1)*f0*t8fd);
so0efd = mod8fd.*cos(2*pi*ScaleTable(2)*f0*t8fd);
la0efd = mod8fd.*cos(2*pi*ScaleTable(3)*f0*t8fd);
ti0efd = mod8fd.*cos(2*pi*ScaleTable(4)*f0*t8fd);
do1efd = mod8fd.*cos(2*pi*ScaleTable(5)*f0*t8fd);
re1efd = mod8fd.*cos(2*pi*ScaleTable(6)*f0*t8fd);
mi1efd = mod8fd.*cos(2*pi*ScaleTable(7)*f0*t8fd);
fa1efd = mod8fd.*cos(2*pi*ScaleTable(8)*f0*t8fd);
so1efd = mod8fd.*cos(2*pi*ScaleTable(9)*f0*t8fd);
la1efd = mod8fd.*cos(2*pi*ScaleTable(10)*f0*t8fd);
tb1efd = mod8fd.*cos(2*pi*ScaleTable(11)*f0*t8fd);
ti1efd = mod8fd.*cos(2*pi*ScaleTable(12)*f0*t8fd);
do2efd = mod8fd.*cos(2*pi*ScaleTable(13)*f0*t8fd);
re2efd = mod8fd.*cos(2*pi*ScaleTable(14)*f0*t8fd);
mi2efd = mod8fd.*cos(2*pi*ScaleTable(15)*f0*t8fd);
fa2edf = mod8fd.*cos(2*pi*ScaleTable(16)*f0*t8fd);
so2edf = mod8fd.*cos(2*pi*ScaleTable(17)*f0*t8fd);
la2edf = mod8fd.*cos(2*pi*ScaleTable(18)*f0*t8fd);
ti2edf = mod8fd.*cos(2*pi*ScaleTable(19)*f0*t8fd);
do3edf = mod8fd.*cos(2*pi*ScaleTable(20)*f0*t8fd);
% sixteenth note
fa0s = mod16.*cos(2*pi*ScaleTable(1)*f0*t16);
so0s = mod16.*cos(2*pi*ScaleTable(2)*f0*t16);
la0s = mod16.*cos(2*pi*ScaleTable(3)*f0*t16);
ti0s = mod16.*cos(2*pi*ScaleTable(4)*f0*t16);
do1s = mod16.*cos(2*pi*ScaleTable(5)*f0*t16);
re1s = mod16.*cos(2*pi*ScaleTable(6)*f0*t16);
mi1s = mod16.*cos(2*pi*ScaleTable(7)*f0*t16);
fa1s = mod16.*cos(2*pi*ScaleTable(8)*f0*t16);
so1s = mod16.*cos(2*pi*ScaleTable(9)*f0*t16);
la1s = mod16.*cos(2*pi*ScaleTable(10)*f0*t16);
tb1s = mod16.*cos(2*pi*ScaleTable(11)*f0*t16);
ti1s = mod16.*cos(2*pi*ScaleTable(12)*f0*t16);
do2s = mod16.*cos(2*pi*ScaleTable(13)*f0*t16);
re2s = mod16.*cos(2*pi*ScaleTable(14)*f0*t16);
mi2s = mod16.*cos(2*pi*ScaleTable(15)*f0*t16);
fa2s = mod16.*cos(2*pi*ScaleTable(16)*f0*t16);
so2s = mod16.*cos(2*pi*ScaleTable(17)*f0*t16);
la2s = mod16.*cos(2*pi*ScaleTable(18)*f0*t16);
ti2s = mod16.*cos(2*pi*ScaleTable(19)*f0*t16);
do3s = mod16.*cos(2*pi*ScaleTable(20)*f0*t16);
blks = zeros(1,k);
melody=[re1s
do1e do1s la0s do1e do1s la0s do1s la0s so0efd re1s
do1e do1s la0s do1e do1s mi1s re1s do1s do1efd so0s
mi1e mi1s re1s mi1e mi1s re1s mi1s so1s mi1s mi1s blks mi1s
re1s re1s re1s re1s re1e do1s mi1e re1efd re1s
do1e do1s la0s do1e do1s la0s do1s la0s so0efd so0s
so1e so1s mi1s so1e so1s mi1s re1s do1s do1efd re1s
mi1s re1s re1s do1s re1e do1s la0s re1s do1s do1s la0s do1e
so1s
re1s mi1s la0e re1s mi1s so1s mi1s re1efd so1s
re1s mi1s so0e re1s mi1s so1s re1s do1efd do1s
so1s la1s so1s mi1s so1s mi1s mi1s re1s re1efd do1s
do1s re1s do1s re1e mi1e so1s mi1s mi1efd so1s
re1s mi1s la0e re1s mi1s so1s mi1s re1efd so1s
re1s mi1s so0e re1s mi1s so1s re1s do1efd do1s
so1s la1s so1s mi1s so1s mi1s mi1s re1s re1efd so0s
mi1s
la1ffd so1s mi1s re1ffd
so1ffd so1s re1s do1ffd
mi1e re1e do1e la0e do1e re1e
so1hfd blks re1s
do1e do1s la0s do1e do1s la0s do1s la0s so0efd re1s
do1e do1s la0s do1e do1s mi1s re1s do1s do1efd so0s
mi1e mi1s re1s mi1e mi1s re1s mi1s so1s mi1s mi1s blks mi1s
re1s re1s re1s re1s re1e do1s mi1e re1efd re1s
do1e do1s la0s do1e do1s la0s do1s la0s so0efd so0s
so1e so1s mi1s so1e so1s mi1s re1s do1s do1efd re1s
mi1s re1s re1s do1s re1e do1s la0s re1s do1s do1s la0s do1e
so1s
re1s mi1s la0e re1s mi1s so1s mi1s re1efd so1s
re1s mi1s so0e re1s mi1s so1s re1s do1efd do1s
so1s la1s so1s mi1s so1s mi1s mi1s re1s re1efd do1s
do1s re1s do1s re1e mi1e so1s mi1s mi1efd so1s
re1s mi1s la0e re1s mi1s so1s mi1s re1efd so1s
re1s mi1s so0e re1s mi1s so1s re1s do1efd do1s
so1s la1s so1s mi1s so1s mi1s mi1s re1s re1efd so0s
];
s=melody;
s=s/max(s);
sound(s,fs);
版权声明:本文标题:matlab音乐代码 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1706064447h500356.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论