10
10
#define USE_SDFAT
11
11
#include " AudioTools/Disk/SDIndex.h"
12
12
13
- // SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
14
- // 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
15
- #ifndef SD_FAT_TYPE
16
- #define SD_FAT_TYPE 1
17
- #endif
18
13
// Try max SPI clock for an SD. Reduce SPI_CLOCK if errors occur. (40?)
19
14
#define SPI_CLOCK SD_SCK_MHZ (50 )
20
- #if SD_FAT_TYPE == 0
21
- typedef SdFat AudioFs;
22
- typedef File AudioFile;
23
- #elif SD_FAT_TYPE == 1
24
- typedef SdFat32 AudioFs;
25
- typedef File32 AudioFile;
26
- #elif SD_FAT_TYPE == 2
27
- typedef SdExFat AudioFs;
28
- typedef ExFile AudioFile;
29
- #elif SD_FAT_TYPE == 3
30
- typedef SdFs AudioFs;
31
- typedef FsFile AudioFile;
32
- #endif
33
15
34
16
namespace audio_tools {
35
17
/* *
36
18
* @brief ESP32 AudioSource for AudioPlayer using an SD card as data source.
37
19
* An index file is used to speed up the access to the audio files by index.
38
20
* This class is based on the Arduino SD implementation
39
21
* For UTF8 Support change SdFatConfig.h #define USE_UTF8_LONG_NAMES 1
22
+ * @param <SdFat32, File32>, <SdFs, FsFile>, <SdExFat, ExFile>, <SdFat, File>
40
23
* @ingroup player
41
24
* @author Phil Schatzmann
42
25
* @copyright GPLv3
43
26
*/
27
+ template <typename AudioFs = SdFat32, typename AudioFile = File32>
44
28
class AudioSourceIdxSDFAT : public AudioSource {
45
29
public:
46
30
// / Default constructor
@@ -69,6 +53,20 @@ class AudioSourceIdxSDFAT : public AudioSource {
69
53
setup_index = setupIndex;
70
54
}
71
55
56
+ // / Constructor for providing an open FS
57
+ AudioSourceIdxSDFAT (AudioFs fs, const char *startFilePath=" /" , const char *ext=" " , bool setupIndex = true ){
58
+ TRACED ();
59
+ sd = fs;
60
+ p_cfg = nullptr ;
61
+ owns_cfg = false ;
62
+ start_path = startFilePath;
63
+ exension = ext;
64
+ setup_index = setupIndex;
65
+ is_sd_setup = true ;
66
+ // since we expect an open fs we do not close it
67
+ is_close_sd = false ;
68
+ }
69
+
72
70
virtual ~AudioSourceIdxSDFAT () { end (); }
73
71
74
72
virtual void begin () override {
@@ -87,7 +85,7 @@ class AudioSourceIdxSDFAT : public AudioSource {
87
85
void end () {
88
86
if (is_sd_setup) {
89
87
#ifdef ESP32
90
- sd.end ();
88
+ if (is_close_sd) sd.end ();
91
89
#endif
92
90
if (owns_cfg) delete (p_cfg);
93
91
is_sd_setup = false ;
@@ -162,6 +160,7 @@ class AudioSourceIdxSDFAT : public AudioSource {
162
160
const char *start_path = nullptr ;
163
161
const char *file_name_pattern = " *" ;
164
162
bool setup_index = true ;
163
+ bool is_close_sd = true ;
165
164
bool is_sd_setup = false ;
166
165
int cs;
167
166
bool owns_cfg = false ;
0 commit comments