snapshot
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
# A Simple SdFat Audio Player
|
||||
|
||||
It was pretty simple to build a simple audio player with the help of the Stream API. A SD file is a sublass of an Arduino Stream, so all you need to do is to copy from the file to the desired output strem. Finally you need to add some logic which handles the end of file to automatically process the next file and maybe a status flag to halt and contine the processing. In addition it adds only a little bit of additional complexity to add volume control and meta data support.
|
||||
|
||||
In order to simplify things, I decided to provide this functionality as well and to prove the point: The AudioPlayer class took only 120 lines of code to implement!
|
||||
|
||||
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 from a SD drive and provides the audio via I2S as __anlog output__: The __AudioSourceSdFat class__ builds on the [SdFat Library](https://github.com/greiman/SdFat) from Bill Greiman which provides FAT16/FAT32 and exFAT support.
|
||||
|
||||
## SD Card
|
||||
|
||||
Here is the information how to wire the SD card to the ESP32
|
||||
|
||||
| SD | ESP32
|
||||
|-------|-----------------------
|
||||
| CS | VSPI-CS0 (GPIO 05)
|
||||
| SCK | VSPI-CLK (GPIO 18)
|
||||
| MOSI | VSPI-MOSI (GPIO 23)
|
||||
| MISO | VSPI-MISO (GPIO 19)
|
||||
| VCC | VIN (5V)
|
||||
| GND | GND
|
||||
|
||||

|
||||
|
||||
|
||||
### Output Device: Piezo Electric Element
|
||||
|
||||
To test the output I am using piezo electric elements
|
||||
|
||||

|
||||
|
||||
It should also be possible to connect a headphone to the output pins.
|
||||
|
||||
|
||||
| PIEZO Left | ESP32
|
||||
| ------------| --------------
|
||||
| + | GPIO25
|
||||
| - | GND
|
||||
|
||||
| PIEZO2 Rigt | ESP32
|
||||
| ------------| --------------
|
||||
| + | GPIO26
|
||||
| - | GND
|
||||
|
||||
|
||||
## Dependencies
|
||||
|
||||
- https://github.com/pschatzmann/arduino-audio-tools
|
||||
- https://github.com/pschatzmann/arduino-libhelix
|
||||
- https://github.com/greiman/SdFat
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* @file player-sdfat-analog.ino
|
||||
* @brief see https://github.com/pschatzmann/arduino-audio-tools/blob/main/examples/examples-player/player-sdfat-analog/README.md
|
||||
*
|
||||
* @author Phil Schatzmann
|
||||
* @copyright GPLv3
|
||||
*/
|
||||
|
||||
|
||||
#include "AudioTools.h"
|
||||
#include "AudioTools/Disk/AudioSourceSDFAT.h"
|
||||
#include "AudioTools/AudioCodecs/CodecMP3Helix.h"
|
||||
|
||||
|
||||
const char *startFilePath="/";
|
||||
const char* ext="mp3";
|
||||
AudioSourceSDFAT source(startFilePath, ext);
|
||||
AnalogAudioStream out;
|
||||
MP3DecoderHelix decoder;
|
||||
AudioPlayer player(source, out, decoder);
|
||||
|
||||
|
||||
void printMetaData(MetaDataType type, const char* str, int len){
|
||||
Serial.print("==> ");
|
||||
Serial.print(toStr(type));
|
||||
Serial.print(": ");
|
||||
Serial.println(str);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);
|
||||
|
||||
// setup output
|
||||
auto cfg = out.defaultConfig();
|
||||
out.begin(cfg);
|
||||
|
||||
// setup player
|
||||
//source.setFileFilter("*Bob Dylan*");
|
||||
player.setMetadataCallback(printMetaData);
|
||||
player.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
player.copy();
|
||||
}
|
||||
Reference in New Issue
Block a user