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.
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
}
How do you know if there is enough place in the mouth to take another bite ?
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 ?
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.