基于MATLAB的音乐合成和处理( 三 )


    baoluo=zeros(1,time(num));  %P为存储包络数据的标的目的量
for j=1:time(num)
if(j<0.2*time(num))
   y=7.5*j/time(num);
else
       if(j<0.333*time(num))
             y=-15/4*j/time(num)+9/4;
       else
if(j<0.666*time(num))
      y=1;
else
       y=-3*j/time(num)+3;

        

baoluo(j)=y;

east(n:n+time(num)-1)=sin(2*pi*f(num)*t).*baoluo(1:time(num));
%给第num个乐音加上包络
    n=n+time(num);

sound(east,8000)       %播放音乐
plot(east)
此处操纵函数fre
function f = fre(p)
f=440*2^((p-69)/12);
运行获得的图像为:
下图是两个乐音交代处的局部放年夜图 , 可以看到知道前一个乐音衰减到零时 , 后一个乐音才起头从零增添 , 所以可以说消弭了噪音 。
1.3  改编法式 , 实现1.2中乐曲的升八度
升高一个八度就是将每个乐音的频率都提高一倍 , 变为本来的2倍;降低一个八度即每个乐音的频率都减小一倍 , 变为本来的1/2 。 是以将存储乐音频率的标的目的量每个元素改变为2或1/2倍即可 。
 查表获得下列MATLAB法式
clc
clear
fs=44100;
t=0:1/fs:0.5;
c4_2=key(60, 2, fs);
d4_2=key(62, 2, fs);
e4_2=key(64, 2, fs);
f4_2=key(65, 2, fs);
g4_2=key(67, 2, fs);
a4_2=key(69, 2, fs);
b4_2=key(71, 2, fs);
c4_4=key(60, 4, fs);
d4_4=key(62, 4, fs);
e4_4=key(64, 4, fs);
f4_4=key(65, 4, fs);
g4_4=key(67, 4, fs);
a4_4=key(69, 4, fs);
b4_4=key(71, 4, fs);
c4_8=key(60, 8, fs);
d4_8=key(62, 8, fs);
e4_8=key(64, 8, fs);
f4_8=key(65, 8, fs);
g4_8=key(67, 8, fs);
a4_8=key(69, 8, fs);
b4_8=key(71, 8, fs);
c4_16=key(60, 16, fs);
d4_16=key(62,16, fs);
e4_16=key(64, 16, fs);
f4_16=key(65, 16, fs);
g4_16=key(67, 16, fs);
a4_16=key(69, 16, fs);
b4_16=key(71, 16, fs);
c5_2=key(72, 2, fs);
d5_2=key(74, 2, fs);
e5_2=key(76, 2, fs);
f5_2=key(77, 2, fs);
g5_2=key(79, 2, fs);
a5_2=key(81, 2, fs);
b5_2=key(83, 2, fs);
c5_4=key(72, 4, fs);
d5_4=key(74, 4, fs);
e5_4=key(76, 4, fs);
f5_4=key(77, 4, fs);
g5_4=key(79, 4, fs);
a5_4=key(81, 4, fs);
b5_4=key(83, 4, fs);
c5_8=key(72, 8, fs);
d5_8=key(74, 8, fs);
e5_8=key(76, 8, fs);
f5_8=key(77, 8, fs);
g5_8=key(79, 8, fs);
a5_8=key(81, 8, fs);
b5_8=key(83, 8, fs);
c5_16=key(72, 16, fs);
d5_16=key(74,16, fs);
e5_16=key(76, 16, fs);
f5_16=key(77, 16, fs);
g5_16=key(79, 16, fs);
a5_16=key(81, 16, fs);
b5_16=key(83, 16, fs);
part1=[g4_4 c5_8 c5_8 d5_8 e5_8 c5_8 e5_8 d5_8 b4_8];
part2=[c5_8 c5_8 d5_8 e5_8 c5_4 b4_8 g4_8 ];
part3=[c5_8 c5_8 d5_8 e5_8 f5_8 e5_8 d5_8 c5_8 b4_8 g4_8 a4_8 b4_8 c5_4 c5_4];
part4=[a4_8 b4_16 a4_8 g4_8 a4_8  b4_8 c5_4];
part5=[g4_8 a4_16 g4_8 f4_8 e4_8 f4_8 g4_4];
part6=[a4_8 b4_16 a4_8 g4_8 a4_8  b4_8 c5_4];
part7=[g4_8 c5_8 b4_8 d5_8 c5_4 c5_4];
para1=[part1 part2 part3 ];
para2=[part4 part5 ];
para3=[part6 part7 ];
leg=[para1 para2 para3];
sound(leg,fs)
1.4   在1.2的音乐中插手谐波
我们在1.2的音乐平分别加上二、三、四次谐波 , 其基波幅度为1 , 高次谐波幅度别离为0.2、0.3、0.1 。 应该将法式改为:

推荐阅读