6 #include "AudioConfig.h"
7 #include "AudioLogger.h"
8 #include "AudioTools/CoreAudio/AudioSource.h"
11 #include "AudioTools/AudioLibs/SDIndex.h"
19 #define SPI_CLOCK SD_SCK_MHZ(50)
21 typedef SdFat AudioFs;
22 typedef File AudioFile;
23 #elif SD_FAT_TYPE == 1
24 typedef SdFat32 AudioFs;
25 typedef File32 AudioFile;
26 #elif SD_FAT_TYPE == 2
27 typedef SdExFat AudioFs;
28 typedef ExFile AudioFile;
29 #elif SD_FAT_TYPE == 3
31 typedef FsFile AudioFile;
47 int chipSelect = PIN_CS,
int speedMHz = 10,
48 bool setupIndex =
true) {
50 LOGI(
"SD chipSelect: %d", chipSelect);
51 LOGI(
"SD speedMHz: %d", speedMHz);
53 p_cfg =
new SdSpiConfig(chipSelect, DEDICATED_SPI, SD_SCK_MHZ(speedMHz));
55 start_path = startFilePath;
57 setup_index = setupIndex;
62 SdSpiConfig &config,
bool setupIndex =
true) {
66 start_path = startFilePath;
68 setup_index = setupIndex;
74 if (!sd.begin(*p_cfg)) {
75 LOGE(
"sd.begin failed");
80 idx.begin(start_path, exension, file_name_pattern, setup_index);
92 LOGI(
"nextStream: %d", offset);
97 LOGI(
"selectStream: %d",
index);
104 if (path ==
nullptr) {
105 LOGE(
"Filename is null")
110 if (!file.open(path, O_RDONLY)) {
111 LOGE(
"Open error: '%s'", path);
114 LOGI(
"-> selectStream: %s", path);
127 const char *
toStr() {
return file_name; }
133 virtual void setPath(
const char *p) { start_path = p; }
136 long size() {
return idx.size(); }
139 SdSpiConfig *p_cfg =
nullptr;
144 char file_name[MAX_FILE_LEN];
145 const char *exension =
nullptr;
146 const char *start_path =
nullptr;
147 const char *file_name_pattern =
"*";
148 bool setup_index =
true;
149 bool is_sd_setup =
false;
151 bool owns_cfg =
false;
153 const char *getFileName(AudioFile &file) {
154 static char name[MAX_FILE_LEN];
155 file.getName(name, MAX_FILE_LEN);