MP3 player

Hi everyone,

I’m trying to play a mp3 file (the FEZ_Monkey.mp3 for example) from a USB thumb drive but with no success;
everytime I try to read with FEZ_Extensions.MP3.SendData(System.IO.File.ReadAllBytes(usbRoot + “\FEZ_Monkey.mp3” the CLR hang up with a System.OutOfMemoryException in System.IO.dll. I think this is because the program try to copy the file from usb to ram and no enough space is on it. Is correct? How can I read and play a mp3 file from thumb drive with a decent size (not only few kbytes)?
Thanks in advance,
Scippy.

Why do you read the whole file? You should read chunks, send to decoder then read more. If you are playing a real song then it is about 5MB!! Do not expect that to fit all in ram.

Let us know how it goes

please can you explain what you mean by read the file in chuncks? a code representation will be good. i’m very new to this that’s why. thanks

pseudo code only:

while there’s enough bytes in the file (eg if end of file is more than 5,000 bytes away)
{
read some more bytes (eg read 5,000 bytes)
send bytes to decoder
}
If there’s any remaining bytes (ie the less than 5000 case)
{
read remaining bytes
send remaining bytes
}

He means that you cannot load a full mp3 file (3-5mb) into the ram of your board. That’s impossible.

You will need to load smaller parts.

See it as a cake: you cannot eat the whole cake at once, you will require smaller pieces. Same for a embedded board. :stuck_out_tongue:

How do you know if there is enough place in the mouth to take another bite ? :smiley:

I suppose the memory on the MP3 chip is limited too so you can’t send data continually, you’ll have to wait until there is enough free memory to send another chunk but how do you know that ?

Does the chip have multiple buffers internally allowing to play long files without interruptions ?

He’s talking about on the FEZ, not the MP3 board. The FEZ doesn’t have enough RAM to buffer the file to send it.

@ Chris Yeah, but what about the MP3 board ? Does it have 5Mb of memory ? I doubt it

The mp3 board decodes the data in an incoming stream. You can send it unlimited data!

If you look at the sample MP3 shield driver code, you’ll see this in several places:


while (_DREQ.Read() == false)
   Thread.Sleep(1);  // wait till done

On those VS10XX decoder chips, if the DREQ pin is low, it means the chip is busy. So after you send each chunk, you just wait until DREQ is high before sending more data.