6#include "AudioLogger.h"
7#include "AudioTools/Disk/AudioSource.h"
8#include "AudioToolsConfig.h"
11#include "AudioTools/Disk/SDDirect.h"
19#define SPI_CLOCK SD_SCK_MHZ(50)
23typedef File AudioFile;
25typedef SdFat32 AudioFs;
26typedef File32 AudioFile;
28typedef SdExFat AudioFs;
29typedef ExFile AudioFile;
32typedef 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;
74 AudioSourceSDFAT(AudioFs fs,
const char *startFilePath=
"/",
const char *ext=
"",
bool setupIndex =
true){
79 start_path = startFilePath;
81 setup_index = setupIndex;
74 AudioSourceSDFAT(AudioFs fs,
const char *startFilePath=
"/",
const char *ext=
"",
bool setupIndex =
true) {
…}
89 if (owns_cfg)
delete (p_cfg);
95 if (!sd.begin(*p_cfg)) {
96 LOGE(
"sd.begin failed");
101 idx.begin(start_path, exension, file_name_pattern);
109 if (is_close_sd) sd.end();
116 LOGI(
"nextStream: %d", offset);
121 LOGI(
"selectStream SDFAT: %d",
index);
130 if (path ==
nullptr) {
131 LOGE(
"Filename is null")
136 if (!file.open(path, O_RDONLY)) {
137 LOGE(
"Open error: '%s'", path);
140 LOGI(
"-> selectStream: %s", path);
141 strncpy(file_name, path, MAX_FILE_LEN);
154 const char *
toStr() {
return file_name; }
160 virtual void setPath(
const char *p) { start_path = p; }
170 SdSpiConfig *p_cfg =
nullptr;
175 char file_name[MAX_FILE_LEN];
176 const char *exension =
nullptr;
177 const char *start_path =
nullptr;
178 const char *file_name_pattern =
"*";
180 bool setup_index =
true;
181 bool owns_cfg =
false;
182 bool is_sd_setup =
false;
183 bool is_close_sd =
true;
185 const char *getFileName(AudioFile &file) {
186 static char name[MAX_FILE_LEN];
187 file.getName(name, MAX_FILE_LEN);