开发者

Building a music player with assembly

开发者 https://www.devze.com 2022-12-30 19:31 出处:网络
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?It is possible - anythin

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?


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.


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


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 :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号