用matlab演奏一曲《董小姐》【源代码】
本帖最后由 青年梦想家 于 2015-11-19 21:27 编辑%《董小姐》
%原词曲:宋东野
%现曲:MATLAB 制作人:LG
%曲谱见:
%%
clc;
clear all;
close all;
fs = 44100;%采样率
dt = 1/fs;
T16=0.25;% E4/4时长0.25s
t16 = 0:dt:T16;
= size(t16);
t4 = linspace(0,4*T16,4*k);
t8 = linspace(0,2*T16,2*k);
t3_16 = linspace(0,3*T16,3*k);
= size(t4);
= size(t8);
f = 440*(1/2)^(5/12);% E大调
d = 2^(1/12);
% Modification functions
mod4 = sin(pi*t4/t4(end));
mod8 = sin(pi*t8/t8(end));
mod16 = sin(pi*t16/t16(end));
%休止符
blk4 = zeros(1,i);%4分休止符
blk8 = zeros(1,j);%8分休止符
blk16 = zeros(1,k);%16分休止符
%4分音符
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);
%8分音符
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);
%16分音符
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);
% 连音符
mod3_16 = sin(pi*t3_16/t3_16(end));
one3_16 = mod3_16.*sin(2*pi*f*d^1*t3_16);
two3_16 = mod3_16.*sin(2*pi*f*d^3*t3_16);
three3_16 = mod3_16.*sin(2*pi*f*d^5*t3_16);
four3_16 = mod3_16.*sin(2*pi*f*d^6*t3_16);
five3_16 = mod3_16.*sin(2*pi*f*d^8*t3_16);
six3_16 = mod3_16.*sin(2*pi*f*d^10*t3_16);
seven3_16 = mod3_16.*sin(2*pi*f*d^12*t3_16);
upone3_16 = mod3_16.*sin(2*pi*f*d^13*t3_16);
uptwo3_16 = mod3_16.*sin(2*pi*f*d^15*t3_16);
upthree3_16 = mod3_16.*sin(2*pi*f*d^17*t3_16);
%曲谱
melody = [blk4 five8 upone16 six3_16 blk8 blk8 six16 six16 six16 six16...
seven8 five8 five16 six16 five3_16 three8 blk16 two16 three16 two16...
three8 two16 five16 five4 blk8 two8 five8 two8...
five8 three8 blk4 blk4 blk4...
blk4 five8 upone16 six3_16 blk8 blk16 six16 seven16 five16...
seven16 seven8 five16 seven8 five16 seven3_16 six8 blk8 five16 five16...
six8 six16 six3_16 five8 blk4 three16 two8 three16...
one4 blk4 blk4 blk4...
blk4 five8 upone16 six3_16 blk8 blk8 six16 six16...
seven16 seven3_16 seven8 five16 seven16 seven16 six16 six8 blk8 three16 five16...
six8 five16 six16 five8 five3_16 six16 five8 two16 two8 five16 five16...
five8 three3_16 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 six16 five3_16 seven3_16 seven16 upone16...
upone4 upone4 blk4 blk4...
blk8 upthree16 upthree16 upthree8 uptwo16 upthree8 uptwo8 uptwo16 uptwo8 upone16 upthree16...
upthree16 upthree3_16 five8 upone16 six3_16 blk8 blk8 blk16 five16...
upthree8 upthree16 uptwo16 upthree8 uptwo16 upthree8 uptwo8 uptwo16 upone16 upone8 five16...
five16 upthree8 upthree16 upthree4 blk4 blk4...
upthree8 six8 upthree8 upfive16 upthree16 upthree16 uptwo3_16 blk16 upone16 upone16 uptwo16...
upthree8 five8 upthree8 uptwo16 five8 six3_16 blk16 six16 six16 five16...
five8 five16 upone8 upone3_16 blk4 five8 upone16 upone16...
one4 blk4 blk4 blk16 six16 six16 five16...
five8 five16 upone8 upone3_16 blk4 five8 upone16 upone16...
one4 blk4 blk4 blk4...
blk4 blk4 blk4 blk4...
blk4 blk4 blk4 blk4...
five8 five16 upone8 upone3_16 blk4 five8 upone16 upone16...
one4 blk4 blk4 blk4...
blk4 blk4 blk4 blk4...
];
sound(melody, fs);
%%
不错
听起来有那种感觉。
我去我超级喜欢这首歌~~
666666666
百年孤独 发表于 2015-11-20 09:14 static/image/common/back.gif
666666666
:loveliness::loveliness::loveliness:
数学中国YY主管 发表于 2015-11-19 23:48 static/image/common/back.gif
我去我超级喜欢这首歌~~
哈哈哈..听着感觉有点怪
yuanyuanxiang 发表于 2015-11-19 23:26 static/image/common/back.gif
听起来有那种感觉。
:P:P:P
果珍冰 发表于 2015-11-19 21:32 static/image/common/back.gif
不错
哈哈~
6666666666666666666
页:
[1]
2