6#include "AudioToolsConfig.h"
7#include "AudioLogger.h"
8#include "AudioTools/Disk/AudioSource.h"
11#include "AudioTools/Disk/SDIndex.h"
19#define SPI_CLOCK SD_SCK_MHZ(50)
22typedef File AudioFile;
24typedef SdFat32 AudioFs;
25typedef File32 AudioFile;
27typedef SdExFat AudioFs;
28typedef ExFile AudioFile;
31typedef FsFile AudioFile;
47 int chipSelect = PIN_CS,
int speedMHz = 10,
48 bool setupIndex =
true) {
50 LOGI(
"SD chipSelect: %d", chipSelect);
51 LOGI(
"SD speedMHz: %d", speedMHz);
53 p_cfg =
new SdSpiConfig(chipSelect, DEDICATED_SPI, SD_SCK_MHZ(speedMHz));
55 start_path = startFilePath;
57 setup_index = setupIndex;
62 SdSpiConfig &config,
bool setupIndex =
true) {
66 start_path = startFilePath;
68 setup_index = setupIndex;
76 if (!sd.begin(*p_cfg)) {
77 LOGE(
"sd.begin failed");
82 idx.begin(start_path, exension, file_name_pattern, setup_index);
91 if (owns_cfg)
delete (p_cfg);
97 LOGI(
"nextStream: %d", offset);
102 LOGI(
"selectStream: %d",
index);
109 if (path ==
nullptr) {
110 LOGE(
"Filename is null")
115 if (!file.open(path, O_RDONLY)) {
116 LOGE(
"Open error: '%s'", path);
119 LOGI(
"-> selectStream: %s", path);
132 const char *
toStr() {
return file_name; }
138 virtual void setPath(
const char *p) { start_path = p; }
141 long size() {
return idx.size(); }
144 SdSpiConfig *p_cfg =
nullptr;
149 char file_name[MAX_FILE_LEN];
150 const char *exension =
nullptr;
151 const char *start_path =
nullptr;
152 const char *file_name_pattern =
"*";
153 bool setup_index =
true;
154 bool is_sd_setup =
false;
156 bool owns_cfg =
false;
158 const char *getFileName(AudioFile &file) {
159 static char name[MAX_FILE_LEN];
160 file.getName(name, MAX_FILE_LEN);