snapshot
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
# A Simple Streaming Audio Player
|
||||
|
||||
It was pretty simple to build a simple audio player with the help of the Stream API.
|
||||
|
||||
The AudioPlayer supports
|
||||
|
||||
- __multiple processor architectures__
|
||||
- __multiple audio data sources__ (SD, URL, callbacks)
|
||||
- __different Output__ Scenarios (I2S, PWM, A2DP etc). Just pass the desired output stream object to the constructor.
|
||||
- __different Decoders__ for MP3, AAC, WAV. Just pass the desired decoder object to the constructor.
|
||||
- __Volume Control__ (by calling player.setVolume())
|
||||
- __Stopping and Resuming__ the processing (by calling player.stop() and player.play())
|
||||
- You can __move to the next file__ by calling player.next();
|
||||
- support for __Metadata__
|
||||
|
||||
|
||||
The example demonstrates how to implement an __MP3 Player__ which provides the data via the Internet (with the help of the AudioSourceURL class) and sends the audio via I2S to an external DAC using an ESP32.
|
||||
|
||||
### The 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
|
||||
-----|----------------
|
||||
VCC | 5V
|
||||
GND | GND
|
||||
BCK | BCK (GPIO14)
|
||||
DIN | OUT (GPIO22)
|
||||
LCK | BCK (GPIO15)
|
||||
FMT | GND
|
||||
XMT | 3V (or another GPIO PIN which is set to high)
|
||||
|
||||
- DMP - De-emphasis control for 44.1kHz sampling rate(1): Off (Low) / On (High)
|
||||
- FLT - Filter select : Normal latency (Low) / Low latency (High)
|
||||
- SCL - System clock input (probably SCL on your board).
|
||||
- FMT - Audio format selection : I2S (Low) / Left justified (High)
|
||||
- XMT - Soft mute control(1): Soft mute (Low) / soft un-mute (High)
|
||||
|
||||
|
||||
### Wiring the Volume Potentiometer
|
||||
|
||||

|
||||
|
||||
| Pot | ESP32 | ESP8266
|
||||
| --------| ---------|---------
|
||||
| POW | 3V | 3V
|
||||
| GND | GND | GND
|
||||
| VOUT | A0 | A0
|
||||
|
||||
### Moving to the next song
|
||||
|
||||
We use a button to move to the next url.
|
||||
|
||||
| Button | ESP32 | ESP8266
|
||||
|------------|----------|---------
|
||||
| Button | GPIO13 | GPIO13
|
||||
| Out 3V
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
- https://github.com/pschatzmann/arduino-audio-tools
|
||||
- https://github.com/pschatzmann/arduino-libhelix
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* @file player-url-i2s.ino
|
||||
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-player/player-url-i2s/README.md
|
||||
*
|
||||
* @author Phil Schatzmann
|
||||
* @copyright GPLv3
|
||||
*/
|
||||
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
|
||||
#include "AudioTools/Disk/AudioSourceURL.h"
|
||||
#include "AudioTools/Communication/AudioHttp.h"
|
||||
|
||||
|
||||
const char *urls[] = {
|
||||
"http://stream.srg-ssr.ch/m/rsj/mp3_128",
|
||||
"http://stream.srg-ssr.ch/m/drs3/mp3_128",
|
||||
"http://stream.srg-ssr.ch/m/rr/mp3_128",
|
||||
"http://sunshineradio.ice.infomaniak.ch/sunshineradio-128.mp3",
|
||||
"http://streaming.swisstxt.ch/m/drsvirus/mp3_128"
|
||||
};
|
||||
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);
|
||||
|
||||
// additional controls
|
||||
const int volumePin = A0;
|
||||
Debouncer nextButtonDebouncer(2000);
|
||||
const int nextButtonPin = 13;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup output
|
||||
auto cfg = i2s.defaultConfig(TX_MODE);
|
||||
i2s.begin(cfg);
|
||||
|
||||
// setup player
|
||||
player.begin();
|
||||
}
|
||||
|
||||
// Sets the volume control from a linear potentiometer input
|
||||
void updateVolume() {
|
||||
// Reading potentiometer value (range is 0 - 4095)
|
||||
float vol = static_cast<float>(analogRead(volumePin));
|
||||
// min in 0 - max is 1.0
|
||||
player.setVolume(vol/4095.0);
|
||||
}
|
||||
|
||||
|
||||
// Moves to the next url when we touch the pin
|
||||
void updatePosition() {
|
||||
if (digitalRead(nextButtonPin)) {
|
||||
Serial.println("Moving to next url");
|
||||
if (nextButtonDebouncer.debounce()){
|
||||
player.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
//updateVolume(); // remove comments to activate volume control
|
||||
//updatePosition(); // remove comments to activate position control
|
||||
player.copy();
|
||||
}
|
||||
Reference in New Issue
Block a user