In the last blogs I presented a Versatile MP3 Player and then a Basic Streaming MP3 Player using my Arduino Audio Tools Library.
If you expect a Versatile Streaming MP3 Player, you will not be disappointed. All the functionality related to the AudioPlayer class which was described in the Versatile MP3 Player Blog is still valid. In our sketch, we just need to replace the AudioSourceSdFat with an AudioSourceURL. In order to support navigation we can define multiple URLs!
The Arduino Sketch
Here is the complete Arduino Sketch which has been tested on a ESP32:
#define USE_HELIX
#include "AudioTools.h"
#include "AudioCodecs/CodecMP3Helix.h"
using namespace audio_tools;
const char *urls[] = {
"http://centralcharts.ice.infomaniak.ch/centralcharts-128.mp3",
"http://centraljazz.ice.infomaniak.ch/centraljazz-128.mp3",
"http://centralrock.ice.infomaniak.ch/centralrock-128.mp3",
"http://centralcountry.ice.infomaniak.ch/centralcountry-128.mp3",
"http://centralfunk.ice.infomaniak.ch/centralfunk-128.mp3"
};
const char *wifi = "wifi";
const char *password = "password";
URLStream urlStream(wifi, password);
AudioSourceURL source(urlStream, urls, "audio/mp3");
I2SStream i2s;
MP3DecoderHelix decoder;
AudioPlayer player(source, i2s, decoder);
void setup() {
Serial.begin(115200);
AudioLogger::instance().begin(Serial, AudioLogger::Info);
// setup output
i2s.begin(i2s.defaultConfig(TX_MODE));
// setup player
player.begin();
}
void loop() {
player.copy();
}
In this example we provide the output via I2S to an external DAC with the help of the I2SStream class.
External DAC:
For my tests I am using the 24-bit PCM5102 PCM5102A Stereo DAC Digital-to-analog Converter PLL Voice Module pHAT
I am just using the default pins defined by the framework. However I could change them with the help of the config object. The mute pin can be defined in the constructor of the I2SStream – by not defining anything we use the default which is GPIO23
DAC | ESP32 |
---|---|
VDD | 5V |
GND | GND |
SD | OUT (GPIO22) |
L/R | GND |
WS | WS (GPIO15) |
SCK | BCK (GPIO14) |
FMT | GND |
XSMT | +3V |
- DEMP – De-emphasis control for 44.1kHz sampling rate(1): Off (Low) / On (High)
- FLT – Filter select : Normal latency (Low) / Low latency (High)
- SCK – System clock input (probably SCL on your board).
- FMT – Audio format selection : I2S (Low) / Left justified (High)
- XSMT – Soft mute control(1): Soft mute (Low) / soft un-mute (High)
Dependencies
The sketch is using the following dependencies:
Source code
You can find the source code for this and other audio player examples on Github.
5 Comments
Jan R. Ziebart · 15. September 2022 at 20:46
Hi Peter,
I have a working bluetooth radio working with the schreibfaul library and an 5105a (?) DAC. I use an old Grundig Tube Radio as Amp with a simple Adapter from headphone jack to TA/TB. Do you think it is possible to stream the Webradiodata directly to a Bluetooth Speaker via A2DP?
pschatzmann · 16. September 2022 at 16:08
No, you can’t use Bluetooth and Wifi at the same time!
moco83 · 26. December 2021 at 19:43
Hello,
Many thanks for your quick reply!
I tried the test player example and the compilation is ok .
Some informations about my goal:
I’ve my own webserver which is able to stream mp3, what I would like to do to is to get this streaming with an ESP32 arduino sketch and broadcast it to a blue tooth speaker (in fact an Alexa Echo Dot).
May I have some help from you to solve the issues I probably get when building this gateway?
Many thanks again
I wish you a very nice and happy newyear !!!!!
moco83 · 23. December 2021 at 17:46
Hello, I tried to compile the code above but I got a compilation error message on this statement
AudioSourceURL source1(urlStream, urls,”audio/mp3″, 5, 0);
Compilation errormessage is:
no matching function for call to ‘audio_tools::AudioSourceURL::AudioSourceURL(audio_tools::URLStream&, const char* [5], const char [10], int, int)’
Any help is welcome
Regards
pschatzmann · 23. December 2021 at 18:01
I updated the example – anyhow I recommend to use the code from the examples directory – which I try to keep updated.