clear;clc;
A4=440;%标准音A4
pt=44100;p0=pt/2;%频率
scale12=A4/2^(9/12)*2.^((0:11)/12);%十二平均律
map=[1 3 5 6 8 10 12];%七音符
%乐谱
score=[1 1 5 5 6 6 5,...do do sol sol la la sol-
4 4 3 3 2 2 1,...fa fa mi mi re re do-
5 5 4 4 3 3 2,...sol sol fa fa mi mi re-
5 5 4 4 3 3 2,...sol sol fa fa mi mi re-
1 1 5 5 6 6 5,...do do sol sol la la sol-
4 4 3 3 2 2 1];%fa fa mi mi re re do-
%节拍
rhythm=repmat([1 1 1 1 1 1 2],1,6);
%歌词
lyric=['一闪一闪亮晶晶' ...Twinkle twinkle little star
'满天都是小星星' ...How I wonder what you are
'挂在天上放光明' ...Up above the world so high
'好像许多小眼睛' ...like a diamond in the sky
'一闪一闪亮晶晶' ...Twinkle twinkle little star
'满天都是小星星'];%How I wonder what you are
%下面开始播放
for i=1:length(score)
fprintf(1,'%c',lyric(i))
wavplay(sin((1:rhythm(i)*p0)/pt*2*pi*scale12(map(score(i)))),pt);
if mod(i,7)==0
fprintf(1,'\n');
end
end