tags:

views:

186

answers:

6

I want to read MP3 files in C++ and I prefer to write my own code for this. Basically to learn how the filetype works. I want to read all the bits of hex data of a MP3 file and have my speakers play it. :) I have no idea where to start since I don't yet know how data is actually stored into a MP3 file.

Thanks for your help

+2  A: 

Start by reading up on the structure on an mp3 file. Then, if you're still interested, find a good tutorial on how to decode the audio data in each frame. It's pretty complex, so you'll need to have a fair bit of time to do it from scratch.

jball
+10  A: 

You can buy the specification for the MP3 format from here. It's about 160EUR.

Oh, and by the way, it's not "hex data". If you're still at the point where you refer to any non-human readable data as "hexadecimal" (which is a number system), delving head-first into a binary data format that involves complex decoding/encoding algorithms might be a bit too much for you for the time being.

How about starting by writing a player that can play .wav files? (Any reasonable .wav file, mind you, taking into account the file format and the different audio formats)

Matti Virkkunen
+1 for interpreting 'hex data' as a clue.
Amardeep
What is the difference between the purchasable specification and the links provided by other answers?
Pindatjuh
+1 for the suggestion of starting with .wav files
Andy Mortimer
@Pindatjuh: I'd say completeness (and possibly in some parts of the world, legality). Plus a lot of the links seem to talk about the file format (which is reasonably simple), and not about the actual decompression algorithm.
Matti Virkkunen
The legality problems of MP3 seem to be with _encoding_ MP3. That's the hard problem: deciding what to omit. This requires a mathemathical model of human hearing. Decoding doesn't need such complex decistions.
MSalters
@MSalters: Hence, "possibly". I rarely bother to familiarize myself with boring legal stuff.
Matti Virkkunen
A: 

If you insist on doing it yourself, you pretty much have to start with the spec:

http://mpgedit.org/mpgedit/mpeg_format/MP3Format.html

Neil N
+2  A: 

Well, it would be tough :)

Anyway, your application should consist of two parts - decompression library / routines and your main backend, which would take some decompressed data block and actually play it.

I would recommend "Data Compression" book by David Salomon to understand how your decoder should actually do it. The variants for your second parts are, unfortunately, too broad to cover them in one sentence.

You could also try investigating some open-source mp3 decoders / decoding libs like this one.

Kotti
+1 for recommending reading existing code.
quixoto
A: 

I worked on the JavaLayer project - an mp3 player in java. That has code to read the MP3 file format - If you can read Java, that might be a helpful starting point.

(Ironicaly, the javalayer code started off as a port of some C++ code...)

mdma
A: 

You'll want to use some decoder library for your task, something like http://sourceforge.net/projects/mpg123net/

There is also MAD decoder... http://www.underbit.com/products/mad/

To properly read mp3 file there is lots of math involved, and I guess that you really don't want to go into that one...

Daniel Mošmondor