4 #include "AudioLogger.h"
5 #include "AudioTools/CoreAudio/AudioSource.h"
6 #include "AudioTools/AudioLibs/SDDirect.h"
35 AudioSourceSD(
const char *startFilePath =
"/",
const char *ext =
".mp3",
int chipSelect = PIN_CS,
bool setupIndex=
true) {
36 start_path = startFilePath;
38 setup_index = setupIndex;
43 #ifdef USE_SD_SUPPORTS_SPI
46 AudioSourceSD(
const char *startFilePath,
const char *ext,
int chipSelect, SPIClass &spiInstance,
bool setupIndex=
true) {
47 start_path = startFilePath;
49 setup_index = setupIndex;
60 LOGE(
"SD.begin cs=%d failed", cs);
65 idx.begin(start_path, extension, file_name_pattern);
75 LOGI(
"nextStream: %d", offset);
80 LOGI(
"selectStream: %d",
index);
82 file_name = idx[
index];
83 if (file_name==
nullptr)
return nullptr;
84 LOGI(
"Using file %s", file_name);
85 file = SD.open(file_name);
86 return file ? &file :
nullptr;
92 file_name = file.name();
93 LOGI(
"-> selectStream: %s", path);
94 return file ? &file :
nullptr;
105 const char *
toStr() {
return file_name; }
111 virtual void setPath(
const char *p) { start_path = p; }
117 #if defined(USE_SD_NO_NS)
120 SDDirect<fs::SDFS,fs::File> idx{SD};
124 const char *file_name;
125 const char *extension =
nullptr;
126 const char *start_path =
nullptr;
127 const char *file_name_pattern =
"*";
128 bool setup_index =
true;
129 bool is_sd_setup =
false;
131 SPIClass *p_spi =
nullptr;
134 #ifdef USE_SD_SUPPORTS_SPI
135 return SD.begin(cs, *p_spi);