本文主要是介绍Matlab演奏《我和我的祖国》,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
没有假期,但是节日快乐
每年都会听到这首歌,但总听不腻,最近看到matlab演奏歌曲的代码,就想自己试一试,其实还挺简单的,就是有点难(bushi),主要是不会识谱(丢人),代码是按照我微薄的乐理知识来写的,可能细节上有点问题,我会找时间修正的。
%前奏
y1 = gen_wave(1,0.25);
y2 = gen_wave(2,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(2,0.25);
y5 = gen_wave(1,0.25);
y6 = gen_wave(6,0.25);
y = [y1,y2,y3,y4,y5,y6];y1 = gen_wave(7,0.25);
y2 = gen_wave(6,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(5,1);
y = [y,y1,y2,y3,y4];y1 = gen_wave(1,0.25);
y2 = gen_wave(2,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(2,0.25);
y5 = gen_wave(1,0.25);
y6 = gen_wave(6,0.25);
y = [y,y1,y2,y3,y4,y5,y6];y1 = gen_wave(7,0.25);
y2 = gen_wave(5,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(6,1);
y = [y,y1,y2,y3,y4];y1 = gen_wave(5,0.25);
y2 = gen_wave(4,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(2,1);
y5 = gen_wave1(7,0.25);
y6 = gen_wave1(6,0.25);
y7 = gen_wave1(5,0.25);
y8 = gen_wave(3,1);
y = [y,y1,y2,y3,y4,y5,y6,y7,y8];y1 = gen_wave1(4,1);
y2 = gen_wave(2,1);
y3 = gen_wave(1,1);
y4 = gen_wave(1,1);
y = [y,y1,y2,y3,y4];%我和我的祖国
y1 = gen_wave(5,0.25);
y2 = gen_wave(6,0.25);
y3 = gen_wave(5,0.25);
y4 = gen_wave(4,0.25);
y5 = gen_wave(3,0.25);
y6 = gen_wave(2,0.25);
y7 = gen_wave(1,1);
y8 = gen_wave1(5,1);
y = [y,y1,y2,y3,y4,y5,y6,y7,y8];%一刻也不能分割
y1 = gen_wave1(1,0.25);
y2 = gen_wave(3,0.25);
y3 = gen_wave(1,0.25);
y4 = gen_wave1(7,0.25);
y5 = gen_wave1(6,0.25);
y6 = gen_wave1(3,0.25);
y7 = gen_wave1(5,1);
y = [y,y1,y2,y3,y4,y5,y6,y7];%无论我走到哪里
y1 = gen_wave(6,0.25);
y2 = gen_wave(7,0.25);
y3 = gen_wave(6,0.25);
y4 = gen_wave(5,0.25);
y5 = gen_wave(4,0.25);
y6 = gen_wave(3,0.25);
y7 = gen_wave(2,1);
y8 = gen_wave1(6,1);
y = [y,y1,y2,y3,y4,y5,y6,y7,y8];%都流出一首赞歌
y1 = gen_wave1(7,0.25);
y2 = gen_wave1(6,0.25);
y3 = gen_wave1(5,0.25);
y4 = gen_wave(5,0.25);
y5 = gen_wave(1,0.25);
y6 = gen_wave(2,0.25);
y7 = gen_wave(3,1);
y = [y,y1,y2,y3,y4,y5,y6,y7];%我歌唱每一座高山
y1 = gen_wave(5,0.25);
y2 = gen_wave(6,0.25);
y3 = gen_wave(5,0.25);
y4 = gen_wave(4,0.25);
y5 = gen_wave(3,0.25);
y6 = gen_wave(2,0.25);
y7 = gen_wave(1,1);
y8 = gen_wave1(5,1);
y = [y,y1,y2,y3,y4,y5,y6,y7,y8];%我歌唱每一条河
y1 = gen_wave(1,0.25);
y2 = gen_wave(3,0.25);
y3 = gen_wave(1,0.25);
y4 = gen_wave(7,0.25);
y5 = gen_wave(2,0.25);
y6 = gen_wave(1,0.25);
y7 = gen_wave(6,1);
y = [y,y1,y2,y3,y4,y5,y6,y7];%袅袅炊烟
y1 = gen_wave(1,0.25);
y2 = gen_wave(7,0.25);
y3 = gen_wave(6,0.25);
y4 = gen_wave(5,1);
y = [y,y1,y2,y3,y4];%小小村落
y1 = gen_wave(6,0.25);
y2 = gen_wave(5,0.25);
y3 = gen_wave(4,0.25);
y4 = gen_wave(3,1);
y = [y,y1,y2,y3,y4];%路上一道辙
y1 = gen_wave1(7,1);
y2 = gen_wave1(6,1);
y3 = gen_wave1(5,0.5);
y4 = gen_wave(2,1);
y5 = gen_wave(1,1);
y = [y,y1,y2,y3,y4,y5];% 我最亲爱的祖国
y1 = gen_wave(1,0.25);
y2 = gen_wave(2,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(2,0.25);
y5 = gen_wave(1,0.25);
y6 = gen_wave(6,0.25);
y7 = gen_wave(7,0.25);
y8 = gen_wave(6,0.25);
y9 = gen_wave(3,0.25);
y10 = gen_wave(5,1);
y = [y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10];%我永远紧依着你的心窝
y1 = gen_wave(1,0.25);
y2 = gen_wave(2,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(2,0.25);
y5 = gen_wave(1,0.25);
y6 = gen_wave(6,0.25);
y7 = gen_wave(7,0.25);
y8 = gen_wave(5,0.25);
y9 = gen_wave(3,0.25);
y10 = gen_wave(6,1);
y = [y,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10];%你用你那 母亲的脉搏和我诉说
y1 = gen_wave1(5,0.25);
y2 = gen_wave(4,0.25);
y3 = gen_wave(3,0.25);
y4 = gen_wave(2,1);
y=[y,y1,y2,y3,y4];y1 = gen_wave1(7,0.25);
y2 = gen_wave1(6,0.5);
y3 = gen_wave1(6,0.5);
y4 = gen_wave1(5,0.25);
y5 = gen_wave(3,1);
y6 = gen_wave(3,1);
y7 = gen_wave(2,1);
y8 = gen_wave(1,1);
% y13 = gen_wave(1,1);
% y14 = gen_wave(8,1);
y = [y,y1,y2,y3,y4,y5,y6,y7,y8 ];sound(y);
%plot(y);
gen_wave1函数:
function y = gen_wave1( tone, rhythm )
%UNTITLED3 此处显示有关此函数的摘要
% 此处显示详细说明Fs = 8192;freqs = [261,293,329,349,392,440,493];x = linspace(0,2*pi*rhythm,floor(Fs*rhythm));y = sin(freqs(tone)*x).*(1-x/(rhythm*2*pi));
end
gen_wave函数:
function y = gen_wave( tone, rhythm )
%UNTITLED2 此处显示有关此函数的摘要
% 此处显示详细说明Fs = 8192;freqs = [523,587,659,698,783,880,988,0];x = linspace(0,2*pi*rhythm,floor(Fs*rhythm));y = sin(freqs(tone)*x).*(1-x/(rhythm*2*pi));
end
这篇关于Matlab演奏《我和我的祖国》的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!