使用程序集构建音乐播放器

发布于 2024-09-02 09:13:56 字数 60 浏览 12 评论 0原文

是否有可能在汇编中构建一个音乐播放器(我正在沿着 NASM 的思路思考)?在构建过程中可能会遇到哪些障碍?

Is it possible to build a music player in assembly (I'm thinking along the lines of NASM)? What are the obstacles one might face in the process of building one?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

绝影如岚 2024-09-09 09:13:56

这是可能的——在装配中一切皆有可能。

主要问题是动机 - 汇编并不是最高效的环境,因此在开始之前您确实必须想要在汇编中构建一些东西。

It is possible - anything is possible in assembly.

The main problem is motivation - assembly is not the most productive of environments, so you really have to want to build something in assembly before you start.

梦里南柯 2024-09-09 09:13:56

很有可能。主要障碍在于链接到所选的 api,尽管我不明白为什么它会过于困难。

Quite possible. The main obstacles would be in linking to the chosen api, though I can't see why it would be overly hard.

蓦然回首 2024-09-09 09:13:56

是的。您可以只使用操作系统 API 和/或声音库,这有点毫无意义,所以我假设您想了解计算机硬件如何编码和实现声音。

基本上,声卡需要一个值流(大约每秒 48000 个,它随音质而变化),代表扬声器振膜当时的目标位置。

WAV 文件只是将这些数字存储在文件中。这占用了很多空间。

MP3、OGG等对数据进行数学变换,以减少所需的空间量,方法是:

  • 降低人类听觉不太敏感的频率精度,
  • 压缩重复的音频

真正“实现”整个音乐播放的效果,您需要解码音频文件,配置声音硬件并将数据流写入其中。可以做:)

Yes, it is. You could just use an OS API and/or sound library, which would be kind of pointless, so I'll assume you want to learn about how sound is encoded and realised by computer hardware.

Basically a sound card requires a stream of values (something like 48000 per second, it varies with sound quality) which represent the target position of the speaker diaphragm at that time.

WAV files simply store these numbers in a file. This takes up lots of space.

MP3, OGG, etc. apply mathematical transforms to the data in order to reduce the amount of space required, by:

  • decreasing the precision of frequencies which human hearing is less sensitive to
  • compress repetitive audio

To really "achieve" the whole music playing thing, you'd need to decode the audio file, and configure the sound hardware and write the stream of data to it. Can be done :)

把昨日还给我 2024-09-09 09:13:56

这是可能的,但代码会根据您想要支持的操作系统而有所不同(例如,Windows 的代码将与 Linux 的代码完全不同)。

最简单的情况可能是一个在 Windows 下播放 MIDI 和/或 WAV 文件的程序(它已经非常直接地支持它,所以你大多只是告诉它要播放什么文件,它会从那里处理事情)。

用汇编语言编写类似您自己的 MP3 解码器的东西会更具挑战性 - 坦率地说,您必须对汇编语言真正狂热才能认真考虑它。

It's possible, but the code will vary with the OS you want to support (e.g., code for Windows will be completely different from code for Linux).

The simplest case would probably be a program to play MIDI and/or WAV files under Windows (which it already supports pretty directly, so you mostly just tell it what file to play and it handles things from there).

Writing something like your own MP3 decoder in assembly would be considerably more challenging -- quite frankly, well into the range that you'd have to be truly fanatical about assembly language to give it serious consideration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文