Close

Software

A project log for DIY Retro Audio Player

Portable MP3 Player for Music and Audiobooks

maxkMax.K 06/20/2022 at 19:240 Comments

Decoding mp3 files is not easy, but luckily it is a task that has been solved before. I found the library ESP32-audioI2S to be an ideal starting point for this project. It includes all the necessary functions to play audio files from an SD card, including ways to fast-forward and read id3 tags. The creator of the library, Schreibfaul1, even added support for very long audiobooks after I had trouble with those.

While the audio library is feeding data to the amplifier, the user interface is displayed on the screen. This is done via a second library, TFT_eSPI. This makes it easy to draw the tape animation with decent efficiency. It might be even better to „pre-render“ the animation and just load individual frames from the flash memory, but I have not tried that yet.

For audiobooks it is important to remember the position in a file. This means that the position has to be saves even when the power is switched off. There are multiple ways to solves this. Having a battery-backed SRAM is a good solution because unlike EEPROM or flash memory, RAM has unlimited write cycles. But eventually this extra battery is going to die and will need to be replaced. Instead of this I decided to use the available SD card and just limit the amount of wear. Saving the playback position only once per minute is enough for normal use. The data is written to a text file on the card, with every position being a new line in the file. Because all lines contain the same number of characters, restoring the position means simply jumping to the end of the file and reading the last line. This makes the code for saving and restoring short and simple while also saving the card from too many write cycles. The same method is used for saving the volume setting for the internal and external speaker. Now an audiobook can easily be stopped and resumed by simply turning off the device.

Discussions