
乐谱是:1231 1231 345 345 565431 565431 25(低)1 25(低)1
--------------------------------------------------------------------------------------------------
extrndelay:far
data segment
ftable dw 2 dup(262,294,330,262)
dw 2 dup(330,349,392,19)
dw 2 dup(392,440,392,349,330,262)
dw 2 dup(294,196,262,19),-1
ttable dw 8 dup(8)
dw 8 dup(8)
dw 2 dup(4,4,4,4,8,8)
dw 8 dup(8)
data ends
code segment
assume cs:code,ds:data
begin: mov ax,data
mov ds,ax
lea si,ftable
lea bp,ds:ttable
freq: mov di,[si]
cmp di,-1
je exit
mov bx,DS:[BP]
call sound
add si,2
add bp,2
jmp freq
exit: mov ah,4ch
int 21h
sound proc near
push ax
push bx
push cx
push dx
push di
mov al,0b6h
out 43h,al
mov dx,12h
mov ax,348ch
div di
out 42h,al
mov al,ah
out 42h,al
in al,61h
mov ah,al
or al,3
out 61h,al
call delay
mov al,ah
out 61h,al
pop di
pop dx
pop cx
pop bx
pop ax
ret
sound endp
code ends
end begin
--------------------------------------------------------------------------------------------------
这中间还用到了一个延迟用的通用子程序: delay
在delay.asm里实现:
--------------------------------------------------------------------------------------------------
publicdelay
code segment
assume cs:code
delay proc far
push ax
ms250: mov cx,16666
us015: in al,61h
and al,10h
cmp al,ah
je us015
mov ah,al
loop us015
dec bl
jnz ms250
pop ax
ret
delayendp
code ends
end
我对音乐基本一窍不通,但是我知道,在用C编写的程序中如果不考虑使用D/A转换的话,能改变的只有发声的频率和发声的时间,给你个蜂鸣器的例子看看while(unsigned int L){ a = ~a delay(P)}void delay(unsigned int P){ while(P--);}这个是控制蜂鸣器发声的一般原理 参数L决定声音时间的长短 P决定声音的频率 这样一来通过控制L和P酒可以发出不同声调,不同长度的声音了 拉长L就能实现长音 其他的关于音乐的我不清楚你可以自己摸索欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)