• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Non-blocking (async) ESP32 library for the vs1053 MP3 SD player

Q&A Forum › Category: ESP32 › Non-blocking (async) ESP32 library for the vs1053 MP3 SD player
0 Vote Up Vote Down
Bernie asked 4 years ago

Update – this has been resolved.  Please see about 7 posts down.

There appears to be at least two kinds of MP3 players.  Tracked players such as DFplayer are given the track name and play that from an onboard FAT16 or FAT32 SD card.  The other kind is a streaming player where the MCU must read the SD card and spoon feed the data byte by byte via SPI to the player — such as the older Adafruit VS1053 player.  There may be players with other kind of architectures.

Problem I have is that my tracks are at least one hour long and consist of a mix of songs (EDM, Progressive, etc).  A track can easily be three hours long and 400 MB.  Usually I want to play one or few of the songs in such a track, and not the whole three hour track.  So I need a method to play the track random access anywhere in the middle, by providing the byte address of the start of the song in a track to the player.  It is not practical for me to break down each track into its songs and make a track for each song using an audio editor.  There are about 10,000 songs.

1- Are there tracked players that can start playing from the middle of a track, such as by fast forwarding (instantly)?  Or do I have to use a streamed player.  I am pretty sure the popular tracked players such as the DFplayer cannot play from the middle.

2- If a song is extracted from the middle of a track and sent to a streaming player, would that stream be all messed up because it does not start from the beginning of the track, and the decoder may not have the correct initial conditions to play from the middle of a track?

Thanks!

Question Tags: MP3 ESP32
9 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi Bernie.
 
I’m sorry, but I’m not familiar with audio with the ESP32 at all.
Nonetheless, I’ve done some research. But I couldn’t find any information about what you want to achieve.
I’m sorry that I can’t help much.
 
Maybe you can try to post your issue in our Facebook group and see if it reaches more people: https://www.facebook.com/groups/RandomNerdTutorials
 
Regards,
Sara

0 Vote Up Vote Down
Bernie answered 3 years ago

I have been looking in all places and leaving messages.  There seems to be no such library for a VS1053 music player for ESP32.  I found a bunch of Web Radio (i.e. WiFi streaming) software for the ESP32 on GitHub, and some seem to have SD capability, but no pure SD-only player for the VS1053.  Which is odd, because this is a very popular sound chip, which has been around for a while.  I am currently using a Mega with the VS1053, coupled to an ESP32 via HardSerial and having a lot of problems, and I want to switch to ESP32, and am stuck.
Thanks.

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi Bernie.
 
Have you tried the Arduino library on the ESP32 board? Many times the libraries are compatible (even if it is not mentioned on the library page). Or sometimes with a few modifications you can make it compatible with the ESP32.
 
Regards,
Sara

0 Vote Up Vote Down
Bernie answered 3 years ago

Yes, I believe I have tried that.  But I will look again in ESP32 libraries.
I found a small project on GitHub that uses the Adafruit library with the ESP32.  It looks promising.  It also has circuit schematics.

If this is successful, then it will be a nice project.  The VS1053 sound chip is a very advanced chip used by professionals in the music industry.  If we can get it to work with the ESP32 that would be a great project to have.  I am working on the track database, which can take more than 2,000 tracks, and can manage mixes that are several hours long.  As the database will not fit on a Mega, I have to port it to the ESP32.  I will also implement WiFi streaming (Web Radio or network files).  Then plan to get the bluetooth working so that it can be controlled and streamed from a smart phone.  Finally will be adding rechargable batteries to make it portable.  The output is as high as 10 W, so even big speakers can be driven in battery mode.  Finally will be adding a 480×320 TFT display.  The package will be just a litter larger than a can of coke.
Thank

0 Vote Up Vote Down
Bernie answered 3 years ago

Hi Sara,
There is an Adafruit library for the VS1053 chip on Arduino IDE ESP32.  But it refuses to install.  
Then there is the Bill Porter (SFEMP3shield) library that I have installed and works for Arduino Uno and Mega (but nt Due), but its examples refuse to compile for the ESP32 and complains about missing include files.

0 Vote Up Vote Down
Bernie answered 3 years ago

Finally Resolved!!! After days of struggling and hacking, and going through about 50 GitHub repositories, finally found one that with a bit of modification works on the ESP32 in non-blocking (async) mode.  It is by JohnJJG.  Totally obscure with no stars or forks.

This is a variant of the Adafruit_VS1053.  The original library by Adafruit will compile but will crash when running.  Multiple other users fixed the crash problem by making the play function blocking, and removing interrupt driven non-blocking, which made the library useless.

More on this later.  This can now be marked as “Resolved”.

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Hi Bernie.
Thanks for sharing your progress.
Can you please share a link to the library you’re using? That can be useful for other readers.
Regards,
Sara

0 Vote Up Vote Down
Bernie answered 3 years ago

Hi Sara – The only library that I could find that works non-blocking in pin interrupt mode is by AdaFruit as modified by JohnJJG

vs1053 for ESP32

Furthermore, the X_RESET pin must be specified and cannot remain -1.  The definitions are not pin numbers but GPIO numbers.  I am using a Sparkfun vs1053 clone shield and the ESPduino by DOIT.  So for this combination that needs no jumpers, we get SHIELD_RESET 12, SHIELD_CS 27, SHIELD_XDCS 14, SHIELD_DREQ 26, SHIELD_SDCS 13.  Note the SD drive is on the vs1053 shield and shares the SPI bus GPIO18, GPIO19, GPIO23.

The modification I had to do was to declare a uint32_t currentPosition.  This is needed if you want to know where in the track you are currently playing so you can fast forward or rewind.  The seek() function is in the FS library and not the SD library.  Then in function

Adafruit_VS1053_FilePlayer::feedBuffer_noLock(void)   you need to add the line

currentPosition += VS1053_DATABUFFERLEN;   before the line that says

playData().

Hope this helps future users. Bernie

0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Great!
Thank you so much for sharing.
This will definitely be useful for other readers.
I’ll close this issue now.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.