3 #include "AudioConfig.h"
7 #include "AudioBasic/StrExt.h"
8 #include "AudioLogger.h"
9 #include "AudioTools/AudioSource.h"
12 #include "AudioLibs/SDDirect.h"
21 #define SPI_CLOCK SD_SCK_MHZ(50)
24 typedef SdFat AudioFs;
25 typedef File AudioFile;
26 #elif SD_FAT_TYPE == 1
27 typedef SdFat32 AudioFs;
28 typedef File32 AudioFile;
29 #elif SD_FAT_TYPE == 2
30 typedef SdExFat AudioFs;
31 typedef ExFile AudioFile;
32 #elif SD_FAT_TYPE == 3
34 typedef FsFile AudioFile;
51 AudioSourceSDFAT(
const char* startFilePath =
"/",
const char* ext =
".mp3",
int chipSelect = PIN_CS,
int speedMHz = 10,
int spi_mode=DEDICATED_SPI,
bool setupIndex=
true) {
53 LOGI(
"SD chipSelect: %d", chipSelect);
54 LOGI(
"SD speedMHz: %d", speedMHz);
56 p_cfg =
new SdSpiConfig(chipSelect, spi_mode, SD_SCK_MHZ(speedMHz));
58 start_path = startFilePath;
60 setup_index = setupIndex;
64 AudioSourceSDFAT(
const char* startFilePath,
const char* ext, SdSpiConfig &config,
bool setupIndex=
true) {
68 start_path = startFilePath;
70 setup_index = setupIndex;
77 if (!sd.begin(*p_cfg)) {
78 LOGE(
"sd.begin failed");
83 idx.begin(start_path, exension, file_name_pattern);
96 LOGI(
"nextStream: %d", offset);
101 LOGI(
"selectStream SDFAT: %d",
index);
111 LOGE(
"Filename is null")
116 if (!new_file.open(path, O_RDONLY)){
117 LOGE(
"Open error: '%s'", path);
120 LOGI(
"-> selectStream: %s", path);
121 strncpy(file_name, path, MAX_FILE_LEN);
134 const char *
toStr() {
return file_name; }
140 virtual void setPath(
const char *p) { start_path = p; }
146 SdSpiConfig *p_cfg =
nullptr;
151 char file_name[MAX_FILE_LEN];
152 const char *exension =
nullptr;
153 const char *start_path =
nullptr;
154 const char *file_name_pattern =
"*";
156 bool setup_index =
true;
158 bool is_sd_setup =
false;
160 const char* getFileName(AudioFile&file){
161 static char name[MAX_FILE_LEN];
162 file.getName(name,MAX_FILE_LEN);