Matlab演奏天空之城

Matlab演奏天空之城

今天尝试了一下用Matlab演奏天空之城,无奈以前没学过乐理,花了几个小时磕磕绊绊的算是看懂了简谱,演奏的时候感觉音色有点奇怪,不知道哪里出了问题,希望感兴趣的大佬不吝赐教。
下面是代码:

Fs=8192;
%天空之城,C调
y1=f(-1,6,0.25);
y2=f(-1,7,0.25);
%-------------
y3=f(0,1,0.75);
y4=f(-1,7,0.25);
y5=f(0,1,0.5);
y6=f(0,3,0.5);
%-------------
y7=f(-1,7,1.5);
y8=f(-1,3,0.5);
%-------------
y9=f(-1,6,0.75);
y10=f(-1,5,0.25);
y11=f(-1,6,0.5);
y12=f(0,1,0.5);
%--------------
y13=f(-1,5,1.5);
y14=f(-1,3,0.5);
%--------------
y15=f(-1,4,0.75);
y16=f(-1,3,0.25);
y17=f(-1,4,0.25);
y18=f(0,1,0.75);
%--------------
y19=f(-1,3,1.5);
y20=f(0,1,0.5);
%--------------
y21=f(-1,7,0.75);
x22=linspace(0,2*pi*0.25,Fs*0.25);
y22=sin(x22*349).*(1-x22/(2*pi*0.25));
x23=linspace(0,2*pi,Fs*0.5);
y23=sin(x23*349).*(1-x23/(2*pi*0.5));
y24=f(-1,7,0.5);
%---------------
y25=f(-1,7,1.5);
y26=f(-1,6,0.25);
y27=f(-1,7,0.25);
%---------------
y28=f(0,1,0.75);
y29=f(-1,7,0.25);
y30=f(0,1,0.5);
y31=f(0,3,0.5);
%---------------second end
y32=f(-1,7,1.5);
y33=f(-1,3,0.25);
y34=f(-1,3,02.5);
%---------------
y35=f(-1,6,0.75);
y36=f(-1,5,0.25);
y37=f(-1,6,0.5);
y38=f(0,1,0.5);
%---------------
y39=f(-1,5,1.5);
y40=f(-1,3,0.5);
%---------------
y41=f(-1,4,0.5);
y42=f(0,1,0.25);
y43=f(-1,7,0.75);
y44=f(0,1,0.5);
%---------------
y45=f(0,2,0.5);
y46=f(0,3,0.25);
y47=f(0,1,0.25);
y48=f(0,1,0.5);%y41,y48之间有连音符emmm.....
%---------------
y49=f(0,1,0.25);
y50=f(-1,7,0.25);
y51=f(-1,6,0.5);
y52=f(-1,7,0.5);
x53=linspace(0,2*pi,Fs*0.5);
y53=sin(x53*392).*(1-x53/(2*pi*0.5));
%-----------------
y54=f(-1,6,1.5);
y55=f(0,1,0.25);
y56=f(0,2,0.25);
%-----------------
y57=f(0,3,0.75);
y58=f(0,2,0.25);
y59=f(0,3,0.5);
y60=f(0,5,0.5);
%------------------fouth end
y61=f(0,2,1.5);
y62=f(-1,5,0.5);
%------------------
y63=f(0,1,0.75);
y64=f(-1,7,0.25);
y65=f(0,1,0.5);
y66=f(0,2,0.25);
y67=f(0,3,0.25);
%-------------------
y68=f(0,3,2);
%-------------------
y69=f(-1,6,0.25);
y70=f(-1,7,0.25);
y71=f(0,1,0.5);
y72=f(-1,7,0.25);
y73=f(0,1,0.25);
y74=f(0,2,0.5);
%-------------------
y75=f(0,1,0.75);
y76=f(-1,5,0.25);
y77=f(-1,5,1);
%-------------------
y78=f(0,4,0.5);
y79=f(0,3,0.5);
y80=f(0,2,0.5);
y81=f(0,1,0.5);
%-------------------
y82=f(0,3,1.5);
y83=f(0,3,0.5);
%-------------------
y84=f(0,6,0.75);
y85=f(0,6,0.25);
y86=f(0,5,0.75);
y87=f(0,5,0.25);
%-------------------sixth end
y88=f(0,3,0.25);
y89=f(0,2,0.25);
y90=f(0,1,0.5);
y91=f(0,1,1);
%-------------------
y92=f(0,2,0.75);
y93=f(0,1,0.25);
y94=f(0,2,0.5);
y95=f(0,5,0.5);
%-------------------
y96=f(0,3,1.5);
y97=f(0,3,0.5);
%-------------------
y98=f(0,6,0.75);
y99=f(0,6,0.25);
y100=f(0,5,0.75);
y101=f(0,5,0.25);
%-------------------
y102=f(0,3,0.25);
y103=f(0,2,0.25);
y104=f(0,1,0.5);
y105=f(0,1,1);
%--------------------
y106=f(0,2,0.75);
y107=f(0,1,0.25);
y108=f(0,2,0.5);
y109=f(-1,7,0.5);
%--------------------
y110=f(-1,6,1.5);
%---------------------End


y=[y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13,y14,y15,y16,y17,y18,y19,y20...
    y21,y22,y23,y24,y25,y26,y27,y28,y29,y30,y31,y32,y33,y34,y35,y36,y37...
    y38,y39,y40,y41,y42,y43,y44,y45,y46,y47,y48,y49,y50,y51,y52,y53,y54...
    y55,y56,y57,y58,y59,y60,y61,y62,y63,y64,y65,y66,y67,y68,y69,y70,y71...
    y72,y73,y74,y75,y76,y77,y78,y79,y80,y81,y82,y83,y84,y85,y86,y87,y88...
    y99,y100,y101,y102,y103,y104,y105,y106,y107,y108,y109,y110];

sound(y,Fs);





function y=f(a,tone,rythm)
Fs=8192;
%低音
if a==-1
    freqs=[262,294,330,349,392,440,449];
    x=linspace(0,2*pi*rythm,Fs*rythm);
    y=sin(x*freqs(tone)).*(1-x/(2*rythm*pi));
    
end
%中音
if a==0
    freqs=[523,587,659,698,784,880,988];
    x=linspace(0,2*pi*rythm,Fs*rythm);
    y=sin(x*freqs(tone)).*(1-x/(2*rythm*pi));
end
%高音
if a==1
    freqs=[1046,1175,1318,1397,1568,1760,1967];
    x=linspace(0,2*pi*rythm,Fs*rythm);
    y=sin(x*freqs(tone)).*(1-x/(2*rythm*pi));
end
        
   
end

这是我用的简谱,emmm看不太懂。
Matlab演奏天空之城_第1张图片

你可能感兴趣的:(Matlab演奏天空之城)