在 TASM 组件中通过扬声器播放音符
我正在尝试在 TASM 中编写一个播放音符的程序。我在网上找不到任何文档,我发现的最接近的是这个 stackoverflow 问题,能够发出“嘟嘟”的声音。
我不知道的是:
这段代码是如何工作的
声音映射是什么
我如何演奏特定音符(do re mi...)
I'm trying to write a program in TASM that plays music notes. I couldn't find any documentation online and the closest thing I found was this stackoverflow question, which is able to produce a "beep" sound.
What I don't know is:
How this code works
What the sound mapping is
How I can play specific notes (do re mi...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用PC扬声器播放单音可以使用引用的问题中提到的方法。它使用系统定时器的方波发生器,通过将操作模式 0xB6 设置为 I/O 端口 0x43 来激活。请参阅定时器端口。
写入端口 0x43 的值 182=0xB6=0y10110110 指定
然后您需要指定所需的频率
与
OUT 0x42,LowByte
和OUT 0x42,HighByte
。这个 16 位二进制整数实际上指定了方波的周期,即将方波从 0 翻转到 1 所必须经过的刻度数,反之亦然。当您对频率进行编程后,要求可编程外设接口将扬声器连接到方波发生器。如果 PPI 端口为 0x61,则可以通过设置两个最低有效位来完成,请参阅 PPI 端口 。
现在您应该等待一段时间让音调播放,然后将 PPI 端口 B 上的两位重置回 0。
您可以找到音乐音调到频率的映射 此处。
您将需要一个表格来将do、re、mi等音调的频率转换为16位整数,您将其作为LowByte和HighByte放入系统计时器。
请参阅示例代码如何获取LowByte和HighByte。 PC 计时器的滴答频率为 1193180 Hz。当您想要播放音调do(注意C4=261.63 Hz)时,计算1193180/261.63=4560=0x11D0。低字节 = 0xD0,高字节 = 0x11。
Playing a single tone with PC speaker may use method mentioned in the quoted question. It uses square-wave generator from system timer, activated by setting mode of operation 0xB6 to I/O port 0x43. See Timer Ports.
The value 182=0xB6=0y10110110 written to port 0x43 specifies
Then you are expected to specify the required frequency
with
OUT 0x42,LowByte
andOUT 0x42,HighByte
. This 16bit binary integer number actually specifies period of the square wave, i.e. the number of ticks that must elapse to flip the wave from 0 to 1 and vice versa.When you have programmed the frequency, ask the Programmable Peripheral Interface to connect speaker to the square-wave generator. This is done by setting the two least significat bits if PPI port 0x61, see PPI Ports.
Now you should wait some time to let the tone play and then reset the two bits back to 0 at PPI port B.
Mapping of musical tones to frequencies you can find here.
You will need a table to convert the frequency of do, re, mi etc tones to 16bit integer numbers which you will put to the system timer as LowByte and HighByte.
See sample code how to get LowByte and HighByte. PC timer ticks at 1193180 Hz. When you want to play the tone do (note C4=261.63 Hz), calculate 1193180/261.63=4560=0x11D0. LowByte=0xD0 and HighByte=0x11.