流行音乐乐曲演奏程序.docx
《流行音乐乐曲演奏程序.docx》由会员分享,可在线阅读,更多相关《流行音乐乐曲演奏程序.docx(19页珍藏版)》请在冰豆网上搜索。
流行音乐乐曲演奏程序
流行音乐乐曲演奏程序
一、需求说明
1、通过一个较大型实用程序的设计与实现,综合运用所学知识,加深理解和掌握。
同时培养学生分析问题和解决问题的能力,以及自学能力。
2、编写用键盘选择计算机演奏歌曲的程序,歌曲清单至少包括3首;
3、程序应该有操作提示、输入和输出,界面追求友好,最好是菜单式的界面;
4、设计若干用例(测试数据),上机测试程序并分析所设计的程序;
二、设计说明
1、简要分析
为了编写一个流行音乐乐曲演奏程序,分析时按照课程设计的要求必须要有操作提示、输入和输出。
在界面设计时应该追求友好,能够使用户便于使用该程序。
而且按照课题要求最好能够实现菜单式的界面,进一步提高该程序界面的友好性。
同时,在设计分析时也必须解决发声问题。
分析设计时按照课本P383(10.4通用发声程序)所示的设计方法解决发声问题。
2、概要分析
2.1用户界面
以下是显示音乐菜单的字符串
msgmenudb'**************************************',0dh,0ah
db'*Thepopmusicmenuisthat:
*',0dh,0ah
db'**',0dh,0ah
db'*1:
dahai*',0dh,0ah;张宇生《大海》
db'*2:
dongfengpo*',0dh,0ah;周杰伦《东风破》
db'*3:
dashetou*',0dh,0ah;吴克群《大舌头》
db'**************************************',0dh,0ah,'$'
2.2模块定义、原理
2.2.2提示选择乐曲
msgchoosedb0dh,0ah,'Inputthenumber(1~3)tochoosethemusicyouwant,input:
','$'
在出现菜单时,同时出现选择乐曲模块,帮助用户认识菜单和操作菜单的方法。
2.2.2提示音乐播放
msgdoingdb0dh,0ah,0dh,0ah
db0dh,0ah,'Now,playingthepopmusicwhichyouchose!
Pleaseenjoying...'
db0dh,0ah,0dh,0ah,'$'
在用户选择所选音乐,程序演奏音乐时,同时显示以上程序段,提示用户系统已经在演奏所选流行歌曲。
2.2.3提示输入字符错误
msgerrordb0dh,0ah,0dh,0ah,0dh,0ah,'!
!
!
sorry,youinputawrongnumber!
!
!
',0dh,0ah
db'pleasetrytochoosefrom1to3again!
input:
','$'
如果出现用户输入字符不符合程序定义的字符串时,程序显示以上模块段,提示用户操作错误,同时程序转回菜单,提示用户重新操作。
2.2.4乐曲频率表和节拍表
以下节选《大舌头》流行乐曲的频率表和节拍表,其余乐曲见源程序段。
freq_dashetoudw524,524,524,524,494,524,588,524;频率表
dw524,524,524,524,494,524,494,392
dw524,524,524,524,494,524,588,524
dw330,330,294,294,262,330,300,262
dw524,524,524,524,494,524,588,524
dw524,524,524,524,494,524,494,392
dw524,524,524,524,494,524,588,524
dw330,330,294,294,262,330,300,262
dw-1
time_dashetoudw500,500,500,500,1000,500,500,500;节拍表
dw500,500,500,500,1000,500,500,500
dw500,500,500,500,1000,500,500,500
dw500,500,500,250,250,500,500,1000
dw500,500,500,500,1000,500,500,500
dw500,500,500,500,1000,500,500,500
dw500,500,500,500,1000,500,500,500
dw500,500,500,250,250,500,500,1000
2.2.5乐曲处理模块
以下节选第一乐曲的处理模块,其余乐曲可见源程序。
music1:
dispmsgmsgdoing;music1处理程序段
movsi,offsetfreq_dahai
movdi,offsettime_dahai
m1:
movcx,[si]
cmpcx,-1;-1用于判断是否结束歌曲
jenext
movbx,[di]
callgensound
addsi,2;取下一频率值
adddi,2;取下一节拍值
jmpm1
2.2.6音乐处理模块
gensoundprocnear
pushdx
moval,0b6h;向计数器写控制数
out43h,al;方式3、双字节写和二进制计数方式写到控制口
movdx,08h;设置被除数
movax,3208h
divcx;其商为预置值
out42h,al;先送LSB
moval,ah
out42h,al;后送MSB
inal,61h;读端口原值
movah,al
oral,3
out61h,al;接通扬声器
l2:
pushdx
pushax
movdx,8h
movax,0f05h
s1:
subax,1
sbbdx,0
jnzs1
popax
popdx
decbx
jnzl2
moval,ah;写回61h端口值,关闭扬声器
out61h,al
popdx
ret
gensoundendp
gensound程序能产生19~65535Hz的声音,这个频率的下限19Hz是使除法不产生溢出的最小的DI值。
其上限实际上是多余的,因为人们最高能够听到的音频约为20000Hz。
2.2.7音符的频率表
1
2
3
4
5
6
7
低音
131
147
165
175
196
220
247
中音
262
294
330
349
392
220
494
高音
524
588
660
698
784
880
984
2.3数据流图
流行乐曲程序演示流程图
Y
N
N
Y
三、详细的算法描述
3.1主程序表述
codesegment
assumecs:
code,ds:
data
begin:
movax,data
movds,ax
next:
dispmsgmsgmenu
dispmsgmsgchoose;提示菜单及输入数字
inputbegin:
movah,01h
int21h
cmpal,'q';输入q则退出
jeexit
cmpal,'1';比较数字<1?
jbdoagain
cmpal,'4';比较数字>4?
jadoagain
andax,000fh;将ASCII码转换成数字,以便后面指向table表里对应的地址
decax;减1,对应地址
shlax,1;相当于ax*2,因为table里的相邻偏移地址是2
movbx,ax
jmptable[bx];间接转移:
IP<--[table+bx]跳到table里面对应的程序段
exit:
movah,4ch
int21h
3.2音乐处理程序详细描述
music1:
dispmsgmsgdoing
movsi,offsetfreq_dahai
movdi,offsettime_dahai
m1:
movcx,[si]
cmpcx,-1
jenext
movbx,[di]
callgensound
addsi,2
adddi,2
jmpm1
music2:
dispmsgmsgdoing
movsi,offsetfreq_dongfengpo
movdi,offsettime_dongfengpo
m2:
movcx,[si]
cmpcx,-1
jenext
movbx,[di]
callgensound
addsi,2
adddi,2
jmpm2
music3:
dispmsgmsgdoing
movsi,offsetfreq_dashetou
movdi,offsettime_dashetou
m3:
movcx,[si]
cmpcx,-1
jexx
jmpxx1
xx:
jmpnext
xx1:
movbx,[di]
callgensound
addsi,2
adddi,2
jmpm3
3.3音乐处理程序详细描述
gensoundprocnear
pushdx
moval,0b6h;向计数器写控制数
out43h,al;方式3、双字节写和二进制计数方式写到控制口
movdx,08h;设置被除数
movax,3208h
divcx;其商为预置值
out42h,al;先送LSB
moval,ah
out42h,al;后送MSB
inal,61h;读端口原值
movah,al
oral,3
out61h,al;接通扬声器
l2:
pushdx
pushax
movdx,8h
movax,0f05h
s1:
subax,1
sbbdx,0
jnzs1
popax
popdx
decbx
jnzl2
moval,ah;写回61h端口值,关闭扬声器
out61h,al
popdx
ret
gensoundendp
四、源程序与执行结果
4.1源程序
dispmsgmacromessage;用来调用显示字符串的宏
movdx,offsetmessage
movah,9
int21h
endm
datasegment
;音乐播放时,提示的字符
msgdoingdb0dh,0ah,0dh,0ah
db0dh,0ah,'Now,playingthepopmusicwhichyouchose!
Pleaseenjoying...'
db0dh,0ah,0dh,0ah,'$'
;提示选择乐曲
msgchoosedb0dh,0ah,'Inputthenumber(1~3)tochoosethemusicyouwant,input:
','$'
;提示输入字符错误
msgerrordb0dh,0ah,0dh,0ah,0dh,0ah,'!
!
!
sorry,youinputawrongnumber!
!
!
',0dh,0ah
db'pleasetrytochoosefrom1to3again!
input:
','$'
;以下是显示音乐菜单的字符串
msgmenudb'**************************************',0dh,0ah
db'*Thepopmusicmenuisthat:
*',0dh,0ah
db'**',0dh,0ah
db'*1:
dahai*',0dh,0ah;张宇生《大海》
db'*2:
dongfengpo*',0dh,0ah;周杰伦《东风破》
db'*3:
dashetou*',0dh,0ah;吴克群《大舌头》
db'**************************************',0dh,0ah,'$'
;以下对应为各乐曲的频率表和节拍时间表
freq_dahaidw196,220
dw262,262,262,262,262,220,196
dw262,262,262,262,294,262,220,262
dw294,294,294,294,294,262,220
dw294,294,294,294,330,294,330,392
dw440,440,392,440,392,330
dw294,294,330,294,262,220,196,220
dw262,262,262,262,262,220
dw262,196,220
dw440,440,392,440,524,440
dw392,330,294,262,220,196,220
dw262,262,262,262,294,262
dw262,330,392
dw440,440,440,440,524,440
dw392,392,392,440,392,330,294
dw262,262,262,262,294
dw330,330,294
dw262,262,262,262,524,440
dw392,392,392,440,392,330,392
dw440,524,524,440,392
dw392,330,392
dw440,440,440,440,524,440
dw392,392,392,440,392,330,294
dw262,262,262,262,392
dw330,330,294
dw262,262,262,262,294,330
dw392,392,330,392,330,392
dw440
dw9,9,196,660,294,294,262
dw262,-1;最后一个以“-1”控制结束
time_dahaidw400,400
dw400,200,400,400,800,400,400
dw400,200,400,200,200,800,400,400
dw400,200,400,400,800,400,400
dw400,200,400,200,200,800,400,400
dw400,800,400,800,400,400
dw400,200,200,400,400,800,400,400
dw400,200,400,400,800,800
dw1600,800,800
dw400,800,400,800,400,400
dw400,400,400,400,800,400,400
dw400,800,400,800,400,200
dw2400,400,400
dw400,800,400,800,400,400
dw400,800,200,200,800,400,400
dw400,800,400,800,800
dw2400,400,400
dw400,800,400,800,400,400
dw400,800,200,200,800,400,400
dw800,400,800,400,200
dw2400,400,400
dw400,800,400,800,400,400
dw400,800,200,200,800,400,400
dw400,800,400,800,800
dw2400,400,400
dw400,800,400,800,400,400
dw400,800,400,800,400,400
dw3200
dw800,400,400,400,400,400,400
dw4000
freq_dongfengpodw294,262,294,330,294,262,294,262,262,220,294
dw294,262,294,330,294,262,294,262,262,220,196
dw392,392,330,330,330,330,349,392,349,349
dw294,294,330,294,262,220,262,440,440,440,392,392
dw294,262,294,330,294,262,294,262,262,220,294
dw294,220,262,294,262,294,330,392,392,330,392
dw392,392,392,440,330,349,392,440,349
dw294,294,262,330,294,262,220,294,262,294,262
dw392,392,392,440,494,440,392,330,330,330,294,294
dw392,392,392,330,294,294,262,294,262,294,330,330
dw247,247,294,330,294,330,392,330,294,262,294,220
dw262,262,294,330,294,330,392,440,392,392,330,330,330,330,294
dw392,392,392,440,494,440,392,330,330,330,294,294
dw392,392,392,330,294,294,262,294,262,294,330,330
dw247,247,294,330,294,330,392,440,392,392,330,392,
440,440,392,330,392,330,292
dw294,294,262,330,294,262,220,294,262
dw-1
time_dongfengpodw800,800,800,1600,800,800,800,800,800,800,1600
dw800,800,800,1600,800,800,800,800,800,800,1600
dw800,800,800,800,800,800,800,1600,800,1600
dw800,800,800,800,1000,800,800,800,800,800,800,800
dw800,800,880,1600,800,800,800,800,800,800,1000
dw800,800,800,1600,800,400,800,800,800,800,1600
dw800,800,800,1600,800,800,1600,800,800,1000
dw800,800,800,800,800,800,800,800,800,800,2400
dw800,800,800,1600,200,800,600,800,800,800,800,1600
dw800,800,800,800,800,800,600,800,800,800,800,1600
dw800,800,800,800,800,800,600,800,800,800,800,1600
dw800,800,800,800,800,800,600,800,800,800,800,800,800,800,800
XX文库-让每个人平等地提升自我dw800,800,800,1600,200,800,600,800,800,800,800,1600
dw800,800,800,800,800,800,600,800,800,800,800,1600
dw800,800,800,800,800,800,600,800,800,800,800,
1600,800,800,800,1600,400,800,600
dw800,800,800,800,800,800,600,800,4000
freq_dashetoudw524,524,524,524,494,524,588,524
dw524,524,524,524,494,524,494,392
dw524,524,524,524,494,524,588,524
dw330,330,294,294,262,330,300,262
dw524,524,524,524,494,524,588,524
dw524,524,524,524,494,524,494,392
dw524,524,524,524,494,524,588,524
dw330,330,294,294,262,330,300,262
dw-1
time_dashetoudw500,500,500,500,1000,500,500,500
dw500,500,500,500,1000,500,500,500
dw500,500,500,500,1000,500,500,500
dw500,500,500,250,250,500,500,1000
dw500,500,500,500,1000,500,500,500
dw500,500,500,500,1000,500,500,500
dw500,500,500,500,1000,500,500,500
dw500,500,500,250,250,500,500,1000
tabledwmusic1,music2,music3;取得各个标号的偏移地址
dataends
;主程序
codesegment
assumecs:
code,ds:
data
begin:
movax,data
movds,ax
next:
dispmsgmsgmenu
dispmsgmsgchoose;提示菜单及输入数字
inputbegin:
movah,01h
int21h
cmpal,'q';输入q则退出
jeexit
cmpal,'1';比较数字<1?
jbdoagain
cmpal,'4';比较数字>4?
jadoagain
andax,000fh;将ASCII码转换成数字,以便后面指向table