2024年4月7日发(作者:速灵卉)
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;
soundpos = [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);
2024年4月7日发(作者:速灵卉)
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;
soundpos = [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);