MP3 decoding code, NOT realtime

Does anyone have code for decoding MP3 files into PCM? I don't need to have the conversion go on in realtime as the audio is playing, just something that can read an MP3 (in small chunks of course)into memory from an SD card and convert it to PCM so that I could store it in another file for later playback. If not, can someone direct me to an article about decoding huffman code? (which is what most of the MP3 is made up of as far as I can tell)

maybe libmad could be your starting point, i've seen it being used on a mbed, so it's not impossible to use

Lots of sources at MP3' Tech - MPEG source codes

Thanks for the responses! It's certainly going to take a while to combine and port all this code to an xmega but I'm sure the results will be worth it.

but I'm sure the results will be worth it.

Are you sure? I would have thought you would be better off doing this on your PC there are lots of applications that will do this. Why does it have to be on an arduino?

Why does it have to be on an arduino?

It's for a handheld device (think iPod touch) that I'm working on. All of the data for this device (images, songs, text files, etc.) will be stored on an SD card. Every time I want to listen to a song, I'll decode it, play it, and then erase the decoded version. If all my songs were stored as wav files then I wouldn't be able to store nearly as many.

Why not just use a shield/chip that can decode mp3s directly?

I wanted to keep costs down and board layout simple. Seeing as it doesn't have to be realtime, software seemed like a fine solution

How are you planning to output audio?

dxw00d:
How are you planning to output audio?

http://www.analog.com/static/imported-files/data_sheets/AD5663.pdf
I have another topic in the audio section talking about it, as I'm not sure which SPI mode to use to talk to it.

This document says 12344 bytes for MP3 decoder. http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATA_BRIEF/DM00024441.pdf
Looks like memory size is the main problem.

bobthebanana:
I wanted to keep costs down and board layout simple. Seeing as it doesn't have to be realtime, software seemed like a fine solution

bobthebanana:

dxw00d:
How are you planning to output audio?

http://www.analog.com/static/imported-files/data_sheets/AD5663.pdf
I have another topic in the audio section talking about it, as I'm not sure which SPI mode to use to talk to it.

You know, the MP3 decoder chips output audio directly, so you don't need the AD5663 anymore. The board layout is still very simple.

Every time I want to listen to a song, I'll decode it, play it, and then erase the decoded version.

So you want to listen to a 3 minute track. You select it and hit play. Then there is a 10 minute delay before any sound is produced. Is this a system you want to use? Remember you said it did not have to be real time so you do know it will take longer than the playing time of the track to decode.

@Magician So I'll read a smaller chunk. If I remember, one "page" of mp3 data is about 1K. Even if it's bigger, I still have 15K of RAM to spare.

@frank26080115 A separate DAC gives me the ability to create and send waveforms directly from the MCU as well. If I decide to implement something like a low frequency arb. wave generator then it will be easier to send the data directly to the DAC rather than packing it up into a format that the decoder will understand just for it to be decoded again.

@Grumpy_Mike It's certainly not the best solution to the problem, but for this low cost, low speed application I'm not going to complain. Worst comes to worst, I'll use a bigger SD card with wav files and try to make a fat32 compatible library.

So it is not arduino, than what is xmega?

ATxmega256D3, the big brother of ATmega. http://www.atmel.com/devices/atxmega256d3.aspx?tab=documents

bobthebanana:
@frank26080115 A separate DAC gives me the ability to create and send waveforms directly from the MCU as well. If I decide to implement something like a low frequency arb. wave generator then it will be easier to send the data directly to the DAC rather than packing it up into a format that the decoder will understand just for it to be decoded again.

VLSI Solution brand MP3 decoders can also play WAV files, and WAV files are just a series of amplitudes. It'll work kind of like a normal DAC when you tell it to play a WAV file.

edit: but it won't work quite like an arbitrary function generator though, so your point is still valid