views:

93

answers:

4

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?

+1  A: 

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.

Kramii
+1  A: 

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

David Sykes
+1  A: 

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

Artelius
A: 

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.

Jerry Coffin
I disagree. With a decent macro assembler that supports data structures, writing an MP3 decoder in assembly language wouldn't be that much harder than writing one in C (of course assuming that you're reasonably skilled at assembly language). It would certainly take considerably longer, but much of the difficulty of writing an MP3 decoder is in understanding what's needed, and once you get past that hurdle, implementation language isn't a huge issue.
Artelius
@Artelius: My experience has indicated otherwise, but who knows, experience may be a handicap.
Jerry Coffin
Well maybe I am a *little* fanatical about assembly language :)
Artelius