Skip to content

Commit 3450f26

Browse files
committed
A2DP optimizations
1 parent 21b6926 commit 3450f26

File tree

7 files changed

+290
-99
lines changed

7 files changed

+290
-99
lines changed

examples/examples-player/player-callback-i2s/player-callback-i2s.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Stream* callbackStream();
2424

2525

2626
// data
27-
const int chipSelect=5;
27+
const int chipSelect=PIN_CS;
2828
AudioSourceCallback source(callbackStream,callbackInit);
2929
I2SStream i2s;
3030
MP3DecoderHelix decoder;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# A Simple SdFat Audio Player
2+
3+
The example demonstrates how to implement an __MP3 Player__: which provides the data from a SD drive and provides the audio via A2DP (e.g. to a Bluetooth Speaker): The __AudioSourceSdFat class__ builds on the [SdFat Library](https://github.com/greiman/SdFat) from Bill Greiman which provides FAT16/FAT32 and exFAT support.
4+
5+
## SD Card
6+
7+
Here is the information how to wire the SD card to the ESP32
8+
9+
| SD | ESP32
10+
|-------|-----------------------
11+
| CS | VSPI-CS0 (GPIO 05)
12+
| SCK | VSPI-CLK (GPIO 18)
13+
| MOSI | VSPI-MOSI (GPIO 23)
14+
| MISO | VSPI-MISO (GPIO 19)
15+
| VCC | VIN (5V)
16+
| GND | GND
17+
18+
![SD](https://www.pschatzmann.ch/wp-content/uploads/2021/04/sd-module.jpeg)
19+
20+
21+
22+
23+
## Dependencies
24+
25+
- https://github.com/pschatzmann/arduino-audio-tools
26+
- https://github.com/pschatzmann/arduino-libhelix
27+
- https://github.com/greiman/SdFat
28+
- https://github.com/pschatzmann/ESP32-A2DP

examples/sandbox/player-sd-a2dp.ino renamed to examples/examples-player/player-sd-a2dp/player-sd-a2dp.ino

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,24 @@ using namespace audio_tools;
1212
const char *startFilePath="/";
1313
const char* ext="mp3";
1414
AudioSourceSdFat source(startFilePath, ext);
15-
A2DPStream out = A2DPStream::instance() ; // A2DP input - A2DPStream is a singleton!
15+
A2DPStream out = A2DPStream::instance(); // A2DP input - A2DPStream is a singleton!
1616
MP3DecoderHelix decoder;
1717
AudioPlayer player(source, out, decoder);
1818

1919

2020
void setup() {
2121
Serial.begin(115200);
22-
AudioLogger::instance().begin(Serial, AudioLogger::Info);
22+
AudioLogger::instance().begin(Serial, AudioLogger::Warning);
2323

24-
// setup output - We send the test signal via A2DP - so we conect to the MyMusic Bluetooth Speaker
25-
out.begin(TX_MODE, "MyMusic");
24+
// setup output - We send the test signal via A2DP - so we conect to the "LEXON MINO L" Bluetooth Speaker
25+
auto cfg = out.defaultConfig(TX_MODE);
26+
cfg.name = "LEXON MINO L";
27+
out.begin(cfg);
2628

2729
// setup player
28-
player.setVolume(0.5);
30+
player.setVolume(0.1);
2931
player.begin();
32+
3033
}
3134

3235
void loop() {

examples/streams-sd_mp3-i2s/streams-sd_mp3-i2s.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ const int chipSelect=10;
2222
I2SStream i2s; // final output of decoded stream
2323
EncodedAudioStream decoder(&i2s, new MP3DecoderHelix()); // Decoding stream
2424
StreamCopy copier;
25-
25+
File audioFile;
2626

2727
void setup(){
2828
Serial.begin(115200);
2929
AudioLogger::instance().begin(Serial, AudioLogger::Info);
3030

3131
// setup file
3232
SD.begin(chipSelect);
33-
File audioFile = SD.open("/music.mp3");
33+
audioFile = SD.open("/Music/Conquistadores.mp3");
3434

3535
// setup i2s
3636
auto config = i2s.defaultConfig(TX_MODE);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#define USE_SDFAT
2+
3+
#include <SPI.h>
4+
#include <SD.h>
5+
#include "AudioTools.h"
6+
7+
using namespace audio_tools;
8+
9+
const char *urls[] = {
10+
"http://centralcharts.ice.infomaniak.ch/centralcharts-128.mp3",
11+
"http://centraljazz.ice.infomaniak.ch/centraljazz-128.mp3",
12+
"http://centralrock.ice.infomaniak.ch/centralrock-128.mp3",
13+
"http://centralcountry.ice.infomaniak.ch/centralcountry-128.mp3",
14+
"http://centralfunk.ice.infomaniak.ch/centralfunk-128.mp3"
15+
};
16+
17+
URLStream urlStream("SSID","password");
18+
AudioSourceURL source(urlStream, urls, "audio/mp3");
19+
20+
21+
void testUrl(){
22+
for (int j=-10;j<10;j++){
23+
Stream *out = source.setIndex(j);
24+
Serial.printf("%d -> %d / %s \n", j, source.index(), source.toStr());
25+
if (out!=nullptr){
26+
delay(500);
27+
assert(out->available()>0);
28+
}
29+
}
30+
Serial.println("--------------------------");
31+
}
32+
33+
const char *startFilePath="/";
34+
const char* ext="mp3";
35+
AudioSourceSdFat sdsource(startFilePath, ext);
36+
37+
void testSD() {
38+
for (int j=-5;j<20;j++){
39+
Stream *out = sdsource.setIndex(j);
40+
Serial.printf("%d -> %d / %s \n", j, sdsource.index(), sdsource.toStr());
41+
if (out!=nullptr){
42+
assert(out->available()>0);
43+
}
44+
}
45+
Serial.println("--------------------------");
46+
47+
}
48+
49+
void setup() {
50+
Serial.begin(115200);
51+
AudioLogger::instance().begin(Serial, AudioLogger::Error);
52+
testUrl();
53+
testSD();
54+
}
55+
56+
void loop(){
57+
58+
}

0 commit comments

Comments
 (0)