6#include "AudioToolsConfig.h"
7#include "AudioLogger.h"
8#include "AudioTools/Disk/AudioSource.h"
11#include "AudioTools/Disk/SDIndex.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 bool setupIndex =
true) {
35 LOGI(
"SD chipSelect: %d", chipSelect);
36 LOGI(
"SD speedMHz: %d", speedMHz);
38 p_cfg =
new SdSpiConfig(chipSelect, DEDICATED_SPI, 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 AudioSourceIdxSDFAT(AudioFs fs,
const char *startFilePath=
"/",
const char *ext=
"",
bool setupIndex =
true){
62 start_path = startFilePath;
64 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);
88 if (is_close_sd) sd.end();
90 if (owns_cfg)
delete (p_cfg);
96 LOGI(
"nextStream: %d", offset);
101 LOGI(
"selectStream: %d",
index);
108 if (path ==
nullptr) {
109 LOGE(
"Filename is null")
114 if (!file.open(path, O_RDONLY)) {
115 LOGE(
"Open error: '%s'", path);
118 LOGI(
"-> selectStream: %s", path);
131 const char *
toStr() {
return file_name; }
137 virtual void setPath(
const char *p) { start_path = p; }
140 long size() {
return idx.size(); }
144 return idx.indexOf(filename);
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 =
"*";
162 bool setup_index =
true;
163 bool is_close_sd =
true;
164 bool is_sd_setup =
false;
166 bool owns_cfg =
false;
168 const char *getFileName(AudioFile &file) {
169 static char name[MAX_FILE_LEN];
170 file.getName(
name, MAX_FILE_LEN);