3 #include "AudioConfig.h"
7 #include "AudioLogger.h"
8 #include "AudioBasic/StrExt.h"
9 #include "AudioTools/AudioSource.h"
12 #include "AudioLibs/SDIndex.h"
21 #define SPI_CLOCK SD_SCK_MHZ(50)
23 typedef SdFat AudioFs;
24 typedef File AudioFile;
25 #elif SD_FAT_TYPE == 1
26 typedef SdFat32 AudioFs;
27 typedef File32 AudioFile;
28 #elif SD_FAT_TYPE == 2
29 typedef SdExFat AudioFs;
30 typedef ExFile AudioFile;
31 #elif SD_FAT_TYPE == 3
33 typedef FsFile AudioFile;
49 AudioSourceIdxSDFAT(
const char* startFilePath =
"/",
const char* ext =
".mp3",
int chipSelect = PIN_CS,
int speedMHz = 10,
bool setupIndex=
true) {
51 LOGI(
"SD chipSelect: %d", chipSelect);
52 LOGI(
"SD speedMHz: %d", speedMHz);
54 p_cfg =
new SdSpiConfig(chipSelect, DEDICATED_SPI, SD_SCK_MHZ(speedMHz));
56 start_path = startFilePath;
58 setup_index = setupIndex;
62 AudioSourceSDFAT(
const char* startFilePath,
const char* ext, SdSpiConfig &config,
bool setupIndex=
true) {
66 start_path = startFilePath;
68 setup_index = setupIndex;
75 if (!sd.begin(*p_cfg)) {
76 LOGE(
"sd.begin failed");
81 idx.begin(start_path, exension, file_name_pattern, setup_index);
93 LOGI(
"nextStream: %d", offset);
98 LOGI(
"selectStream: %d",
index);
106 LOGE(
"Filename is null")
111 if (!new_file.open(path, O_RDONLY)){
112 LOGE(
"Open error: '%s'", path);
115 LOGI(
"-> selectStream: %s", path);
128 const char *
toStr() {
return file_name; }
134 virtual void setPath(
const char *p) { start_path = p; }
137 long size() {
return idx.size();}
140 SdSpiConfig *p_cfg =
nullptr;
145 char file_name[MAX_FILE_LEN];
146 const char *exension =
nullptr;
147 const char *start_path =
nullptr;
148 const char *file_name_pattern =
"*";
149 bool setup_index =
true;
150 bool is_sd_setup =
false;
154 const char* getFileName(AudioFile&file){
155 static char name[MAX_FILE_LEN];
156 file.getName(name,MAX_FILE_LEN);