6#include "AudioLogger.h"
7#include "AudioTools/Disk/AudioSource.h"
8#include "AudioToolsConfig.h"
11#include "AudioTools/Disk/SDDirect.h"
14#define SPI_CLOCK SD_SCK_MHZ(50)
27template <
typename AudioFs = SdFat32,
typename AudioFile = File32>
32 int chipSelect = PIN_CS,
int speedMHz = 10,
33 int spi_mode = DEDICATED_SPI,
bool setupIndex =
true) {
35 LOGI(
"SD chipSelect: %d", chipSelect);
36 LOGI(
"SD speedMHz: %d", speedMHz);
38 p_cfg =
new SdSpiConfig(chipSelect, spi_mode, SD_SCK_MHZ(speedMHz));
40 start_path = startFilePath;
42 setup_index = setupIndex;
47 SdSpiConfig &config,
bool setupIndex =
true) {
51 start_path = startFilePath;
53 setup_index = setupIndex;
57 AudioSourceSDFAT(AudioFs fs,
const char *startFilePath=
"/",
const char *ext=
"",
bool setupIndex =
true){
62 start_path = startFilePath;
64 setup_index = setupIndex;
72 if (owns_cfg)
delete (p_cfg);
78 if (!sd.begin(*p_cfg)) {
79 LOGE(
"sd.begin failed");
84 idx.begin(start_path, exension, file_name_pattern);
92 if (is_close_sd) sd.end();
99 LOGI(
"nextStream: %d", offset);
104 LOGI(
"selectStream SDFAT: %d",
index);
113 if (path ==
nullptr) {
114 LOGE(
"Filename is null")
119 if (!file.open(path, O_RDONLY)) {
120 LOGE(
"Open error: '%s'", path);
123 LOGI(
"-> selectStream: %s", path);
124 strncpy(file_name, path, MAX_FILE_LEN);
137 const char *
toStr() {
return file_name; }
143 virtual void setPath(
const char *p) { start_path = p; }
147 long size() {
return idx.size(); }
153 SdSpiConfig *p_cfg =
nullptr;
158 char file_name[MAX_FILE_LEN];
159 const char *exension =
nullptr;
160 const char *start_path =
nullptr;
161 const char *file_name_pattern =
"*";
163 bool setup_index =
true;
164 bool owns_cfg =
false;
165 bool is_sd_setup =
false;
166 bool is_close_sd =
true;
168 const char *getFileName(AudioFile &file) {
169 static char name[MAX_FILE_LEN];
170 file.getName(name, MAX_FILE_LEN);