matlab卡农代码微盘,MATLAB演奏国歌,除乐理知识基本抛弃卡农代码,未参照前国歌.......

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

最近很无聊,想起卡农代码,很是佩服,原卡农代码为小提琴三重奏,本人音乐修养不行,做不出来,在此感谢卡农大神代码的启发指点,并无多少相同

本帖第一部分为思路,第二部分为代码,第三部分为失败了的自动筛选代码,为省内存基本都是single数据

思路:先建立三个库矩阵,分别为标准音符、连音符、附点音符的89*8矩阵,sound1,、sound0_6,sound1.5,行表示钢琴的88键+空音键,列为全音符,2分符,4分符,8分符,16分符,32,64,128分符,理论上可扩展。按此思路可以囊括所有曲目。本希望抛弃单个取值赋变量的方法,奈何识别程序有问题,我也没找出来哪里出错了,所以后面又是手动赋值。切记可以实现自动筛选匹配音符的功能

%沈阳化工大学

%马红越

%不留联系方式了,太乱

%matlab版本2012b

fs=single(44100);%采样频率

dt=single(1/fs);

%速度

temp=90;%拍速

%四分符为基准,一拍时值

t4=60/temp;

t1=4*t4;

t2=2*t4;

t8=0.5*t4;

t16=0.25*t4;

t32=0.125*t4;

t64=t32/2;

t128=t64/2;

t=single([t1,t2,t4,t8,t16,t32,t64,t128]);

clear t1 t2 t4 t8 t16 t32 t64 t128;

%调幅函数

t1_5=t*1.5;

t0_6=t*2/3;

for j=1:length(t)

%标准音

temp=single(0:dt:t(j));

mod1{j}=single(sin(pi*temp/temp(end)));%标准音调幅函数

T1{j}=temp;%T1为标准音时值矩阵,

%1个点的附点长音

temp=single(0:dt:t1_5(j));

mod1_5{j}=single(sin(pi*temp/temp(end)));%附点音调幅函数

T1_5{j}=temp;%附点音时值

%三连音

temp=single(0:dt:t0_6(j));

mod0_6{j}=single(sin(pi*temp/temp(end)));%标准音调幅函数

T0_6{j}=temp;%T1为标准音时值矩阵,

%两个点

%t=t*1.5*1.5;

%for j=1:length(t);

% tem1=0:dt:t(j);

% k=length(tem1);

% mod1_25{j}=[mod256(temp),ones(1,k-i),mod256(tem)];%附点音调幅函数

% T1_25{j}=tem1;%附点音时值

end

clear dt t0_6 t1_5 t

%以A为基准,f=440hz

%中央区

c=261.63;

cp=277.18;ds=cp;

d=293.66;

dp=311.13;es=dp;

e=329.63;

f=349.23;

fp=369.99;gs=fp;

g=392.00;

gp=415.30;as=gp;

a=440.00;

ap=466.16;bs=ap;

b=493.88;

center4=single([c,cp,d,dp,e,f,fp,g,gp,a,ap,b]);

clear c cp ds d dp es e f fp gs g gp as a ap bs b

%全部音区,%88键

keys=center4;

for i=1:4

temp=center4/2^i;

tem=center4*2^i;

if i==4

temp(1:9)=[];

tem(2:end)=[];

end

keys=[temp,keys,tem];

end

clear center4

%国歌 1=G 2/4拍

%标准音长

for j=1:length(T1)

temp=cos(2*pi*keys'*T1{j});

temp(89,:)=single(0);%休止符

for i=1:89

sound1{i,j}=single(mod1{j}.*temp(i,:));

end

%cell sound1中j=1-8为 全音符,2分符,4分符,8分符,16分符,32分符,64分符,128分符

%i=1-88个音符

temp=cos(2*pi*keys'*T1_5{j});

temp(89,:)=single(0);%休止符

for i=1:89

sound1_5{i,j}=single(mod1_5{j}.*temp(i,:));

end

%cell sound1_5中j为 1附点的 全音符,2分符,4分符,8分符,16分符,32分符,64分符,128分符

%i=1-88个音符

temp=cos(2*pi*keys'*T0_6{j});

temp(89,:)=single(0);%休止符

for i=1:89

sound0_6{i,j}=single(mod0_6{j}.*temp(i,:));

end

%cell sound0_6中为三连音的 全音符,2分符,4分符,8分符,16分符,32分符,64分符,128分符

%i=1-88个音符

end

clear i j k temp tem T1_5 T1 T0_6 keys

do1_5f8=sound1_5{47,4};

mi1f16=sound1{51,5};

so1f8=sound1{54,4};

section1=[do1_5f8,mi1f16,so1f8,so1f8];

la1f4=sound1{56,3};

so1f4=sound1{54,3};

section2=[la1f4,so1f4];

mi1_5f8=sound1_5{51,4};

do1f16=sound1{47,5};

so0_6f8=sound0_6{54,4};

section3=[mi1_5f8,do1f16,so0_6f8,so0_6f8,so0_6f8];

mi1f4=sound1{51,3};

do1f4=sound1{47,3};

section4=[mi1f4,do1f4];

so0_6f8d=sound0_6{42,4};

section5=[so0_6f8d,so0_6f8d,so0_6f8d,so0_6f8d,so0_6f8d,so0_6f8d];

section=[section1,section2,section3,section4,section5];

clear section1 section2 section3 section4 section5

emf8=sound1{89,4};

so1f8d=sound1{42,4};

section6=[do1f4,emf8,so1f8d];

do1_5f4=sound1_5{47,3};

do1f8=sound1{47,4};

section7=[do1_5f4,do1f8];

la1f16d=sound1{44,5};

ti1f16d=sound1{46,5};

section8=[do1_5f8,do1f16,so1f8d,la1f16d,ti1f16d];

section9=[do1f4,do1f4];

mi1f8=sound1{51,4};

re1f16=sound1{49,5};

section10=[emf8,mi1f8,do1f8,re1f16,mi1f16];

section=[section,section6,section7,section8,section9,section10];

clear section6 section7 section8 section9 section10

section11=[so1f4,so1f4];

section12=[mi1_5f8,mi1f16,do1_5f8,mi1f16];

so1_5f8=sound1_5{54,4};

re1f4=sound1{49,3};

section13=[so1_5f8,mi1f16,re1f4];

re1f2=sound1{49,2};

section14=re1f2;

section15=[la1f4,so1f4];

section=[section,section11,section12,section13,section14,section15];

clear section11 section12 section13 section14 section15

section16=[re1f4,mi1f4];

section17=[so1f8,mi1f8,emf8,so1f8];

section18=[mi1f8,re1f16,mi1f16,do1f4];

emf4=sound1{89,3};

section19=[mi1f4,emf4];

so1_5f8d=sound1_5{42,4};

section20=[so1_5f8d,la1f16d,do1f8,do1f8];

section=[section,section16,section17,section18,section19,section20];

clear section16 section17 section18 section19 section20

section21=[mi1_5f8,mi1f16,so1f8,so1f8];

re1f8=sound1{49,4};

la1f4d=sound1{44,3};

section22=[re1f8,re1f16,re1f16,la1f4d];

re1_5f4=sound1_5{49,3};

section23=[re1_5f4,so1f8d];

section24=[do1_5f4,do1f8];

mi1_5f4=sound1_5{51,3};

section25=[mi1_5f4,mi1f8];

section=[section,section21,section22,section23,section24,section25];

clear section21 section22 section23 section24 section25

so1f2=sound1{54,2};

section26=so1f2;

section27=[do1_5f8,mi1f16,so1f8,so1f8];

section28=[la1f4,so1f4];

section29=[mi1_5f8,do1f16,so0_6f8,so0_6f8,so0_6f8];

section30=[mi1f8,emf8,do1f8,emf8];

section=[section,section26,section27,section28,section29,section30];

clear section26 section27 section28 section29 section30

sof4d=sound1{42,3};

section31=[sof4d,do1f4];

section32=[mi1_5f8,do1f16,so0_6f8,so0_6f8,so0_6f8];

section33=[mi1f8,emf8,do1f8,emf8];

section34=[sof4d,do1f4];

section35=[sof4d,do1f4];

section36=[sof4d,do1f4];

section37=[do1f4,emf4];

section=[section,section31,section32,section33,...

section34,section35,section36,section37];

clear section31 section32 section33 section34 section35 section36 section37

sound(section,fs);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值