matlab 音乐合集

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

一 最炫名族风
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Most shining national wind//最炫民族风 on Matlab
% The Modification is from "canon", not by me

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);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
二 义勇军进行曲
%%%%%%%%%%%%%%%%%%%%%%%%%% 中华人民共和国国歌 (Matlab版) %%%%%%%%%%%%%%%%%%%%%%
% 注:参考 前人“卡农”代码 的 基础之上 完成 此曲
% by 延边大学 信息管理 张 波% matlab 爱好者 欢迎 加我 QQ:1296445042
% 百度贴吧 ID :zhangbo0037
% 内有注释,纯属娱乐( date 2013.03.11 )

clc,clear all
fs = 44100; dt = 1/fs; f0 = 320; T16 = 0.125;
t16 = [0:dt:T16]; [temp m] = size(t16);
t2 = linspace(0,8*T16,8*m); [temp i] = size(t2);
t4 = linspace(0,4*T16,4*m); [temp j] = size(t4);
t8 = linspace(0,2*T16,2*m); [temp k] = size(t8);
t12 = linspace(0,4/3*T16,4/3*m); [temp l] = size(t12);
% Modification functions
mod2 = sin(pi*t2/t2(end));
mod4 = sin(pi*t4/t4(end));
mod8 = sin(pi*t8/t8(end));
mod12 = sin(pi*t12/t12(end));
mod16 = sin(pi*t16/t16(end));

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];

do0g = mod2.*cos(2*pi*ScaleTable(21)*f0*t2);re0g = mod2.*cos(2*pi*ScaleTable(22)*f0*t2);mi0g = mod2.*cos(2*pi*ScaleTable(23)*f0*t2);fa0g = mod2.*cos(2*pi*ScaleTable(1)*f0*t2);so0g = mod2.*cos(2*pi*ScaleTable(2)*f0*t2);la0g = mod2.*cos(2*pi*ScaleTable(3)*f0*t2);ti0g = mod2.*cos(2*pi*ScaleTable(4)*f0*t2);
do1g = mod2.*cos(2*pi*ScaleTable(5)*f0*t2);re1g = mod2.*cos(2*pi*ScaleTable(6)*f0*t2);mi1g = mod2.*cos(2*pi*ScaleTable(7)*f0*t2);fa1g = mod2.*cos(2*pi*ScaleTable(8)*f0*t2);so1g = mod2.*cos(2*pi*ScaleTable(9)*f0*t2);la1g = mod2.*cos(2*pi*ScaleTable(10)*f0*t2);% tb1g = mod2.*cos(2*pi*ScaleTable(11)*f0*t2);ti1g = mod2.*cos(2*pi*ScaleTable(12)*f0*t2);
do2g = mod2.*cos(2*pi*ScaleTable(13)*f0*t2);re2g = mod2.*cos(2*pi*ScaleTable(14)*f0*t2);mi2g = mod2.*cos(2*pi*ScaleTable(15)*f0*t2);fa2g = mod2.*cos(2*pi*ScaleTable(16)*f0*t2);so2g = mod2.*cos(2*pi*ScaleTable(17)*f0*t2);la2g = mod2.*cos(2*pi*ScaleTable(18)*f0*t2);ti2g = mod2.*cos(2*pi*ScaleTable(19)

*f0*t2);
do3g = mod2.*cos(2*pi*ScaleTable(20)*f0*t2);
I = zeros(1,i);

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);
J = zeros(1,j);

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);
K = zeros(1,k);
do0d = mod12.*cos(2*pi*ScaleTable(21)*f0*t12);re0d = mod12.*cos(2*pi*ScaleTable(22)*f0*t12);mi0d = mod12.*cos(2*pi*ScaleTable(23)*f0*t12);fa0d = mod12.*cos(2*pi*ScaleTable(1)*f0*t12);so0d = mod12.*cos(2*pi*ScaleTable(2)*f0*t12);la0d = mod12.*cos(2*pi*ScaleTable(3)*f0*t12);ti0d = mod12.*cos(2*pi*ScaleTable(4)*f0*t12);
do1d = mod12.*cos(2*pi*ScaleTable(5)*f0*t12);re1d = mod12.*cos(2*pi*ScaleTable(6)*f0*t12);mi1d = mod12.*cos(2*pi*ScaleTable(7)*f0*t12);fa1d = mod12.*cos(2*pi*ScaleTable(8)*f0*t12);so1d = mod12.*cos(2*pi*ScaleTable(9)*f0*t12);la1d = mod12.*cos(2*pi*ScaleTable(10)*f0*t12);% tb1d = mod12.*cos(2*pi*ScaleTable(11)*f0*t12);ti1d = mod12.*cos(2*pi*ScaleTable(12)*f0*t12);
do2d = mod12.*cos(2*pi*ScaleTable(13)*f0*t12);re2d = mod12.*cos(2*pi*ScaleTable(14)*f0*t12);mi2d = mod12.*cos(2*pi*ScaleTable(15)*f0*t12);fa2d = mod12.*cos(2*pi*ScaleTable(16)*

f0*t12);so2d = mod12.*cos(2*pi*ScaleTable(17)*f0*t12);la2d = mod12.*cos(2*pi*ScaleTable(18)*f0*t12);ti2d = mod12.*cos(2*pi*ScaleTable(19)*f0*t12);
do3d = mod12.*cos(2*pi*ScaleTable(20)*f0*t12);
L = zeros(1,l);
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);
M = zeros(1,m);

v1 = [do0e L mi0e so0e so0e M,la0f M so0f M,mi0e M do0e so0d so0d so0d M,mi0f do0f L,so0d so0d so0d so0d so0d so0d,do0f K M so0e,do1f J do1e,do1e M do1e so0d M la0d ti0d M,do1f do1f,J mi1e M do1d re1d mi1d M,so1f L so1f M,mi1e M mi1e do1e M mi1e,so1e M mi1e re1f M,re1f J M la1f M so1f M,re1f M mi1f M,so1e M mi1e K so1e,M mi1e re1d mi1d do1e K,mi1f J M so1e M la1e do1e do1e M,mi1e M mi1e so1e so1e M,re1e re1e re1e la1f ,re1f J so1e,do1f J do1e,mi1f J mi1e,so1f J do1e M mi1e so1e M so1e M,la1f M so1f,L mi1e M do1e so1e so1e so1e,mi1e K do1e J,so1f do1f K mi1e L do1e so1e so1e so1e,mi1e J do1e J,so1f do1f,K so1f do1f,K so1f do1f,do1f];

s = v1;s = s/max(s);sound(s,fs);clc
三 新贵妃醉酒
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;
soun

dpos = [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*p

i*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 blkf blkf];
% Base Melody
cello = [do1f do1f so0f so0f la0f la0f mi0f mi0f...
fa0f fa0f do0f do0f fa0f fa0f so0f so0f];
% So-FUCKING-Long Melody
violin = [mi2f mi2f re2f re2f do2f do2f ti1f ti1f...
la1f la1f so1f so1f la1f la1f ti1f ti1f ...%
do2f do2f ti1f ti1f la1f la1f so1f so1f...
fa1f fa1f mi1f mi1f fa1f fa1f re1f re1f ...%
do1f mi1f so1f fa1f mi1f do1f mi1f re1f...
do1f la0f do1f so1f fa1f la1f so1f fa1f...%
mi1f do1f re1f ti1f do2f mi2f so2f so1f...
la1f fa1f so1f mi1f do1f do2f blkf blke ti1e ...%
do2e ti1e do2e do1e ti0e so1e re1e mi1e...
do1e do2e ti1e la1e ti1e mi2e so2e la2e...
fa2e mi2e re2e fa2e mi2e re2e do2e ti1e...
la1e so1e fa1e mi1e re1e fa1e mi1e re1e... %%
do1e re1e mi1e fa1e so1e re1e so1e fa1e...
mi1e la1e so1e fa1e so1e fa1e mi1e re1e...
do1e la0e la1e ti1e do2e ti1e la1e so1e...
fa1e mi1e re1e la1e so1e la1e so1e fa1e...%
mi1f mi2e blke re2f re2f blkf do1f

mi2f mi2f...
la2f la2f so2f so2f la2f la2f ti2f ti2f...%
do3e blke do2e blke ti1f ti1f blkf la1f do2f do2f...
do2f do2f do2f do2f do2f fa2f re2f so2f...%
so2e mi2s fa2s so2e mi2s fa2s so2s so1s la1s ti1s ...
do2s re2s mi2s fa2s mi2e do2s re2s...
mi2e mi1s fa1s so1s la1s so1s fa1s so1s mi1s fa1s so1s...
fa1e la1s so1s fa1e mi1s re1s mi1s re1s do1s re1s mi1s fa1s so1s la1s...
fa2e la1s so1s la1e ti1s do2s so1s la1s ti1s do2s re2s mi2s fa2s so2s...%
mi2e do2s re2s mi2e re2s do2s re2s ti1s do2s re2s mi2s re2s do2s ti1s...
do2e la1s ti1s do2e do1s re1s mi1s fa1s mi1s re1s mi1s do2s ti1s do2s...
la1e do2s ti1s la1e so1s fa1s so1s fa1s mi1s fa1s so1s la1s ti1s do2s...
la2e do2s ti1s do2e ti1s la1s ti1s do2s re2s do2s ti1s do1s la1s ti1s...%%
do2e blke blkf ti1e blke blkf la1e blke blkf do2e blke blkf...
do1e blke blkf do1e blke blkf do1e blke blkf do1e blke blkf...%
blkf so1e blke blkf so1e blke blkf mi1e blke blkf so1e blke...
blkf fa1e blke blkf mi1e blke blkf fa1e blke blkf re2e blke...%
mi2e mi1e fa1e mi1e re1e re2e mi2e re2e do2e mi1e do1e do2e ti1e so0e fa0e so0e...
la0e la1e so1e la1e so1e so0e fa0e so0e do1e la1e so1e la1e ti1e ti0e la0e ti0e...%
do1e do2e re2e do2e ti1e ti0e do1e ti0e la0e la1e so1e la1e ti1e ti0e mi1e re1e...
do1e do2e re2e fa2e mi2e mi1e so1e mi2e do2e fa2e mi2e fa2e re2e so1e fa1e so1e...%
mi1e so1e so1e so1e so1e so1e so1e so1e mi1e mi1e mi1e mi1e mi1e mi1e so1e so1e...
fa1e fa1e fa1e do2e do2e do2e do2e do2e do2e do2e la1e la1e so1e so1e re2e ti1e...%%
so1e mi2e mi2e mi2e re2e re2e re2e re2e do2e do2e do2e do2e so2e so2e so2e so2e...
la2e la2e la2e la2e so2e so2e so2e so2e la2e la2e la2e la2e ti2e ti1e ti1e ti1e...%
do2e do1s re1s mi1e do1e ti0e ti1s do2s re2e ti1e la1e la0s ti0s do1e la0e ti0e so1s fa1s mi1e re1e...
do1e mi1s re1s do1e fa1e mi1e do1s re1s mi1e so1e fa1e la1s so1s fa1e mi1e re1e so1s fa1s mi1e re1e...%
mi1e do2s ti1s do2e mi1e so1e so1s la1s ti1e so1e mi1e do2s re2s mi2e do2e mi2e mi2s re2s do2e ti1e...
la1e la1s so1s la1e ti1e do2e mi2s re2s do2e mi2e fa2e do2s ti1s la1e la1e so1e re1e so1e so1e...%
so1f so1f so1f so1f do1f do1f do1f so1f...
fa1f fa1f so1f so1f fa1f do1f do1f do1e ti0e...%
do1f do2f ti1f ti1f la1f la1f so1f so1f...
do1f do1e re1e mi1f mi1f do2f do2f ti1f ti1f...%%
do2f];
% cello
c1 = [cello cello cello cello cello...
cello cello cello 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];
% viol

in3
v3 = [blkblock blkblock blkblock violin];
% Get dirty
s = c1+v1+v2+v3;
s = s/max(s);
sound(s,fs);
五 董小姐
% 董小姐 词曲:宋冬野% 演奏者:Matlab
sp=actxserver('SAPI.SpVoice');
sp.Speak('董小姐');
sp.Speak('作曲者');
sp.Speak('宋冬野');
sp.Speak('演奏者');
sp.Speak('Matlab');
fs = 44100; % 采样率
dt= 1/fs;
T16=0.25;%十六分音符时长0.25秒
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);
f=440*sqrt(0.5);% E大调
d=2^(1/12);
blk4=zeros(1,i);%四分休止符
blk8=zeros(1,j);%八分休止符
blk16=zeros(1,k);%十六分休止符
% Modification functions
mod4 = sin(pi*t4/t4(end));
mod8 = sin(pi*t8/t8(end));
mod16 = sin(pi*t16/t16(end));
%四分音符
one4=mod4.*sin(2*pi*f*d^1*t4);
two4=mod4.*sin(2*pi*f*d^3*t4);
three4=mod4.*sin(2*pi*f*d^5*t4);
four4=mod4.*sin(2*pi*f*d^6*t4);
five4=mod4.*sin(2*pi*f*d^8*t4);
six4=mod4.*sin(2*pi*f*d^10*t4);
seven4=mod4.*sin(2*pi*f*d^12*t4);
upone4=mod4.*sin(2*pi*f*d^13*t4);
uptwo4=mod4.*sin(2*pi*f*d^15*t4);
upthree4=mod4.*sin(2*pi*f*d^17*t4);
%八分音符
one8=mod8.*sin(2*pi*f*d^1*t8);
two8=mod8.*sin(2*pi*f*d^3*t8);
three8=mod8.*sin(2*pi*f*d^5*t8);
four8=mod8.*sin(2*pi*f*d^6*t8);
five8=mod8.*sin(2*pi*f*d^8*t8);
six8=mod8.*sin(2*pi*f*d^10*t8);
seven8=mod8.*sin(2*pi*f*d^12*t8);
upone8=mod8.*sin(2*pi*f*d^13*t8);
uptwo8=mod8.*sin(2*pi*f*d^15*t8);
upthree8=mod8.*sin(2*pi*f*d^17*t8);
%十六分音符
one16=mod16.*sin(2*pi*f*d^1*t16);
two16=mod16.*sin(2*pi*f*d^3*t16);
three16=mod16.*sin(2*pi*f*d^5*t16);
four16=mod16.*sin(2*pi*f*d^6*t16);
five16=mod16.*sin(2*pi*f*d^8*t16);
six16=mod16.*sin(2*pi*f*d^10*t16);
seven16=mod16.*sin(2*pi*f*d^12*t16);
upone16=mod16.*sin(2*pi*f*d^13*t16);
uptwo16=mod16.*sin(2*pi*f*d^15*t16);
upthree16=mod16.*sin(2*pi*f*d^17*t16);
upfive16=mod16.*sin(2*pi*f*d^20*t16);
%特殊音符

t8p=linspace(0,3*T16,3*k);
t5_16=linspace(0,5*T16,5*k);
t2=linspace(0,8*T16,8*k);
mod8p=sin(pi*t8p/t8p(end));
mod5_16=sin(pi*t5_16/t5_16(end));
mod2=sin(pi*t2/t2(end));
three8p=mod8p.*sin(2*pi*f*d^5*t8p);
five8p=mod8p.*sin(2*pi*f*d^8*t8p);
blk8p=zeros(1,3*k);
six3_16=mod8p.*sin(2*pi*f*d^10*t8p);
upone2=mod2.*sin(2*pi*f*d^13*t2);
upthree8p=mod8p.*sin(2*pi*f*d^17*t8p);
uptwo8p=mod8p.*sin(2*pi*f*d^15*t8p);
upone8p=mod8p.*sin(2*pi*f*d^13*t8p);
upone5_16=mod5_16.*sin(2*pi*f*d^13*t5_16);
upthree5_16=mod5_16.*sin(2*pi*f*d^17*t5_16);
%谱子
melody=[blk4 five8 upone16 six3_16 blk8 blk16 six16 six16 six16...
seven8 five8 five8 six16 five8 three8p blk16 two16 three16 two16 three8 two16 five8 five4 blk8p two16 five8p two16 five16 three8p...
blk4 blk4 blk4 blk4 five8 upone16 six3_16 blk8 blk16 six16 seven16 five16...
seven16 seven8 five16 seven8 five16 seven16 six4 blk8 five16 five16 six8 six16 six8 five8p blk4 three16 two8 three16 one4...
blk4 blk4

blk4 blk4 five8 upone16 six3_16 blk4 six16 six16...
seven8 seven16 seven8 five8 seven16 six16 six3_16 blk8 three16 five16 six8 five16 six16 five16 five8p six16 five8 two16 two8 five16 five8 three8p...
blk4 blk4 blk4 blk4 five8 upone16 six3_16 blk8 six16 seven8 seven16 seven16 five16 five8 upone8 uptwo16 upone8 six3_16 blk16...
five16 six16 five16 six4 blk16 five16 six16 five16 five8 seven4 seven16 upone16 upone2 blk4 blk4...
blk16 upthree16 upthree16 upthree8 uptwo16 upthree8 uptwo8 uptwo16 upone16 uptwo8 upone16 upthree8 upthree8p five8 upone16 six3_16 blk8 blk8p...
five16 uptwo16 upthree8 upthree16 uptwo16 uptwo16 upthree8 uptwo16 uptwo16 upthree8 uptwo8 uptwo16 upone16 upone8 five16 five16 upthree8 uptwo16 upthree5_16 blk4 blk4...
upthree8 six8 upthree8 upfive16 upthree8 uptwo8p blk16...
five16 upone16 uptwo16 upthree8 five8 upthree8 uptwo16 five8 six3_16 blk16...
two16 six16 five16 five8 five16 upone8 upone8p blk4 five8 upone16 upone5_16];
sound(melody,fs)

相关文档
最新文档