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);
93 if (is_close_sd) sd.end();
100 LOGI(
"nextStream: %d", offset);
105 LOGI(
"selectStream SDFAT: %d",
index);
114 if (path ==
nullptr) {
115 LOGE(
"Filename is null")
120 if (!file.open(path, O_RDONLY)) {
121 LOGE(
"Open error: '%s'", path);
124 LOGI(
"-> selectStream: %s", path);
125 strncpy(file_name, path, MAX_FILE_LEN);
138 const char *
toStr() {
return file_name; }
144 virtual void setPath(
const char *p) { start_path = p; }
148 long size() {
return idx.size(); }
154 SdSpiConfig *p_cfg =
nullptr;
159 char file_name[MAX_FILE_LEN];
160 const char *exension =
nullptr;
161 const char *start_path =
nullptr;
162 const char *file_name_pattern =
"*";
164 bool setup_index =
true;
165 bool owns_cfg =
false;
166 bool is_sd_setup =
false;
167 bool is_close_sd =
true;
169 const char *getFileName(AudioFile &file) {
170 static char name[MAX_FILE_LEN];
171 file.getName(name, MAX_FILE_LEN);