Arduino Forum

Using Arduino => Audio => Topic started by: Baguda on Jul 06, 2014, 10:30 pm

Title: Saving small Mp3's to EEPROM
Post by: Baguda on Jul 06, 2014, 10:30 pm
Hello everyone,

    I am attempting to make an automatic bird caller that will play bird call mp3s (or other audio file). The device will only have one file to play that never changes so I am trying to avoid adding in an entire SD card reader, and want to save the mp3 files on an EEPROM or other in-circuit memory device. I am planning on using a DAC to play the audio files from the arduino memory to a small speaker. However, I have read that the EEPROM may be too slow to read for audio playing. Does anyone have any advice on this matter or have a link to a good article about it?

Thank you, and have a great day!
Title: Re: Saving small Mp3's to EEPROM
Post by: Grumpy_Mike on Jul 06, 2014, 10:33 pm
Quote
I have read that the EEPROM may be too slow to read for audio playing.

Yes and it is only 1K and there is not enough memory to decode and play an MP3 file.
Sorry without extra support like an MP3 player or a wave shield SD card this is a non starter.
Title: Re: Saving small Mp3's to EEPROM
Post by: CrossRoads on Jul 06, 2014, 10:41 pm
EEPROM will be fast enough - the onchip memory is just too small, mere fractions of a second can be stored. Consider that .wav files (basically CD files) use 44100 16-bit samples/second.
The '328P doesn't do MP3 decoding, you need an external device for that.

Use an MP3 module like this, then you don't have to worry how long the song is.
http://www.mdfly.com/search.php?search_query=mp3
Title: Re: Saving small Mp3's to EEPROM
Post by: Baguda on Jul 07, 2014, 01:02 am
Quote
EEPROM will be fast enough - the onchip memory is just too small, mere fractions of a second can be stored.


This is fine because I was planning on expanding the Arduino's memory with an added EEPROM (like an 24LC512). The Mp3s are ~50KB which should fit on a 512Kb EEPROM.

Quote
The '328P doesn't do MP3 decoding, you need an external device for that.


Are you referring to the DAC that is needed to pass the mp3 to the speaker? Or is there a different decoding device specifically for Mp3 handling? If so, can you provide me a model number or link in the right direction? I was planning on adding my own 16bit DAC (MAX5541) for the signal processing out of the Arduino.

Thank y'all for the help!!
Title: Re: Saving small Mp3's to EEPROM
Post by: Baguda on Jul 07, 2014, 02:37 am
After searching around I found the vs1053 mp3 decoder and interfacing instructions to the arduino. The vs1053 seems like a bit overkill for the project in mind so I also looked up some Wave Shields and their schematics. The wave shield from adafruit  ( http://www.adafruit.com/product/94 ) seems to simply connect the SD card's SPI and the DAC's SPI to the arduino's SPI via some tri-state buffers. The data is taken from the SD to the Arduino and then sent to the DAC which converts it and sends it to the amplifier (see attached image [I'm not sure how to use this insert image code thing yet]). Would this work the same with data stored to an external EEPROM connected to the SPI instead of the SD card?
Title: Re: Saving small Mp3's to EEPROM
Post by: Baguda on Jul 07, 2014, 03:40 am
***UPDATE***

After braving the wilds of the internet, I've come to a solution! You are correct in that a codec is needed to play Mp3s. This is avoided by the adafuit wave shield because it is designed to only play .wav files. The arduino can play an audio file, just not a compressed audio file. The .wav files are not compressed which is why they are so big.

So playing Mp3's off of the EEPROM is a "NO-GO" for the Arduino without a Mp3 codec to decompress it.
However, this can be done with a .wav file, and luckily the audio file I want to play (3 secs of a bird call) is only 200KB as a .wav file. So if I use a 2Mb EEPROM, like the M95M02 ( http://www.digikey.com/product-detail/en/M95M02-DRMN6TP/497-11405-1-ND/2679405 ), and a DAC, like the MAX5541, I should be able to store and play the audio file without a SD card!

This method would only be useful for very small .wav files; however, it would be perfect for a project like a holloween decoration that screams or moans when it detects motion, or maybe cool doorbell ringtone. Or perhaps a for a bird feeder that calls the birds to it for optimal bird watching action!

Here is an article I found on how to interface the M95M01 (the smaller version of the M95M02) to the arduino that is useful:
http://strayspark.wordpress.com/arduino-bit-banged-spi-eeprom/

Thanks to Crossroads and Mike for helping me through this! I will post the results of the circuit later.
Title: Re: Saving small Mp3's to EEPROM
Post by: CrossRoads on Jul 07, 2014, 05:20 am
Ok, good luck.
Don't bit bang tho - use the onboard SPI port.
Title: Re: Saving small Mp3's to EEPROM
Post by: Grumpy_Mike on Jul 07, 2014, 06:43 am

Ok, good luck.
Don't bit bang tho - use the onboard SPI port.

Yes good luck, although both EEPROM and D/A use the SPI so that reduces the modes you can use the EEPROM in. The Lady Ada wave shield bit bangs athe A/D to get round this.
Basically it means every access you have to write the EEPROM address again and that slows things down because there are more device accesses to get the two bytes you want.
Title: Re: Saving small Mp3's to EEPROM
Post by: Mr_arduino on Jul 08, 2014, 04:22 am
I am surprised no one mentioned this. Store the sound in the microcontrollers flash memory. I am not sure what the length of the file is but it sounds short. Lets say you are using an arduino uno and lets say with the bootloader and the audio playing code you are left with 30kb of flash memory. The audio is stored at 8000 samples per second. That means you can store (30*1024)/8000=3.84 seconds of audio. However note that the length can be increased by using simple audio compression. If you adpcm with a 3:1 compression ratio you can fit 11.52 seconds of audio in 30kb of flash memory. Which arduino board are you using? It might have even more memory which allows for a higher quality sample or longer data. Regardless you said the sample was only three seconds so it will fit just fine even without compression.
Title: Re: Saving small Mp3's to EEPROM
Post by: CrossRoads on Jul 08, 2014, 05:23 am
The bandwidth at 8000 samples/second would be very low. If going thru all this effort, might as well make it sound good.
Title: Re: Saving small Mp3's to EEPROM
Post by: Mr_arduino on Jul 08, 2014, 05:43 am
8000hz may not sound as bad as you think. If you use a good re-sampling algorithm that is. Also he could use compression to improve quality. Storing the audio in internal memory does reduce complexity which appears to be desired in this case.