1+ /* *
2+ * @file player-sdfat-audiokit.ino
3+ * @brief SDFAT Audio Player example for ESP32-S3-AI-Smart-Speaker.
4+ * Unfortunatly the cd pins is mapped to EXIO4 and not an regualr GPIO pin.
5+ * This requires custom functions for SdCsInit and SdCsWrite. Make sure that
6+ * SD_CHIP_SELECT_MODE is set to 1 in SdFatConfig.h.
7+ * @author Phil Schatzmann
8+ * @copyright GPLv3
9+ */
10+
11+ #include " AudioTools.h"
12+ #include " AudioTools/AudioLibs/AudioBoardStream.h"
13+ #include " AudioTools/Disk/AudioSourceSDFAT.h" // or AudioSourceIdxSDMMC.h
14+ #include " AudioTools/AudioCodecs/CodecMP3Helix.h"
15+ #include " ESP32S3AISmartSpeaker.h"
16+
17+ const char * startFilePath = " /" ;
18+ const char * ext = " mp3" ;
19+ AudioSourceSDFAT source (startFilePath, ext);
20+ AudioBoardStream kit (ESP32S3AISmartSpeaker);
21+ MP3DecoderHelix decoder; // or change to MP3DecoderMAD
22+ AudioPlayer player (source, kit, decoder);
23+
24+ // do nothing: pins are setup by the baord driver
25+ void sdCsInit (SdCsPin_t pin) {}
26+
27+ // activate/deactivate the CS pin
28+ void sdCsWrite (SdCsPin_t pin, bool level) {
29+ kit.digitalWrite (EXIO4, level);
30+ }
31+
32+ void setup () {
33+ Serial.begin (115200 );
34+ delay (2000 );
35+ AudioToolsLogger.begin (Serial, AudioToolsLogLevel::Info);
36+
37+ // setup output
38+ auto cfg = kit.defaultConfig (TX_MODE);
39+ // cfg.sdmmc_active = false;
40+ cfg.sd_active = true ;
41+ kit.begin (cfg);
42+ kit.setVolume (0.4 );
43+
44+
45+ // setup player: must be after
46+ player.begin ();
47+
48+ // select file with setPath() or setIndex()
49+ // player.setPath("/ZZ Top/Unknown Album/Lowrider.mp3");
50+ // player.setIndex(1); // 2nd file
51+ }
52+
53+ void loop () {
54+ player.copy ();
55+ }
0 commit comments