6 #include "AudioConfig.h"
7 #include "AudioLogger.h"
8 #include "AudioTools/CoreAudio/AudioSource.h"
11 #include "AudioTools/AudioLibs/SDDirect.h"
19 #define SPI_CLOCK SD_SCK_MHZ(50)
22 typedef SdFat AudioFs;
23 typedef File AudioFile;
24 #elif SD_FAT_TYPE == 1
25 typedef SdFat32 AudioFs;
26 typedef File32 AudioFile;
27 #elif SD_FAT_TYPE == 2
28 typedef SdExFat AudioFs;
29 typedef ExFile AudioFile;
30 #elif SD_FAT_TYPE == 3
32 typedef FsFile AudioFile;
49 int chipSelect = PIN_CS,
int speedMHz = 10,
50 int spi_mode = DEDICATED_SPI,
bool setupIndex =
true) {
52 LOGI(
"SD chipSelect: %d", chipSelect);
53 LOGI(
"SD speedMHz: %d", speedMHz);
55 p_cfg =
new SdSpiConfig(chipSelect, spi_mode, SD_SCK_MHZ(speedMHz));
57 start_path = startFilePath;
59 setup_index = setupIndex;
64 SdSpiConfig &config,
bool setupIndex =
true) {
68 start_path = startFilePath;
70 setup_index = setupIndex;
76 if (!sd.begin(*p_cfg)) {
77 LOGE(
"sd.begin failed");
82 idx.begin(start_path, exension, file_name_pattern);
94 LOGI(
"nextStream: %d", offset);
99 LOGI(
"selectStream SDFAT: %d",
index);
108 if (path ==
nullptr) {
109 LOGE(
"Filename is null")
114 if (!file.open(path, O_RDONLY)) {
115 LOGE(
"Open error: '%s'", path);
118 LOGI(
"-> selectStream: %s", path);
119 strncpy(file_name, path, MAX_FILE_LEN);
132 const char *
toStr() {
return file_name; }
138 virtual void setPath(
const char *p) { start_path = p; }
145 SdSpiConfig *p_cfg =
nullptr;
150 char file_name[MAX_FILE_LEN];
151 const char *exension =
nullptr;
152 const char *start_path =
nullptr;
153 const char *file_name_pattern =
"*";
155 bool setup_index =
true;
156 bool owns_cfg =
false;
157 bool is_sd_setup =
false;
159 const char *getFileName(AudioFile &file) {
160 static char name[MAX_FILE_LEN];
161 file.getName(name, MAX_FILE_LEN);