Skip to content

Commit 8ac6628

Browse files
committed
Issue no error message when sd.begin failed
1 parent 41542f9 commit 8ac6628

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/AudioConfig.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,15 @@
135135

136136
#ifdef ESP32
137137
#include "esp32-hal-log.h"
138-
#define USE_A2DP
138+
// optional libraries
139+
//#define USE_A2DP
140+
//#define USE_ESP8266_AUDIO
141+
139142
#define USE_PWM
140143
#define USE_URL_ARDUINO
141144
#define USE_I2S
142145
#define USE_AUDIO_SERVER
143146
#define USE_URLSTREAM_TASK
144-
//#define USE_ESP8266_AUDIO
145147

146148
#define PWM_FREQENCY 30000
147149
#define PWM_START_PIN 12
@@ -159,7 +161,6 @@
159161

160162
#define I2S_AUTO_CLEAR true
161163

162-
163164
// URLStream
164165
#define URL_STREAM_CORE 0
165166
#define URL_STREAM_PRIORITY 2

src/AudioTools/AudioPlayer.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,24 +181,32 @@ namespace audio_tools {
181181
LOGD(LOG_METHOD);
182182
LOGI("SD chipSelect: %d", chipSelect);
183183
LOGI("SD speedMHz: %d", speedMHz);
184-
if (!sd.begin(SdSpiConfig(chipSelect, DEDICATED_SPI, SD_SCK_MHZ(speedMHz)))) {
185-
LOGE("SD.begin failed");
186-
}
184+
p_cfg = new SdSpiConfig(chipSelect, DEDICATED_SPI, SD_SCK_MHZ(speedMHz));
185+
owns_cfg = true;
187186
start_path = startFilePath;
188187
exension = ext;
189188
}
190189

191190
/// Costructor with SdSpiConfig
192191
AudioSourceSdFat(const char* startFilePath, const char* ext, SdSpiConfig &config) {
193192
LOGD(LOG_METHOD);
194-
if (!sd.begin(config)) {
195-
LOGE("SD.begin failed");
196-
}
193+
p_cfg = &config;
194+
owns_cfg = false;
197195
start_path = startFilePath;
198196
exension = ext;
199197
}
198+
199+
virtual ~AudioSourceSdFat(){
200+
if (p_cfg!=nullptr && owns_cfg){
201+
delete p_cfg;
202+
}
203+
}
204+
200205
virtual void begin() override {
201206
LOGD(LOG_METHOD);
207+
if (!sd.begin(*p_cfg)) {
208+
LOGE("SD.begin failed!");
209+
}
202210
idx_pos = 0;
203211
}
204212

@@ -245,6 +253,8 @@ namespace audio_tools {
245253

246254
protected:
247255
AudioFile file;
256+
SdSpiConfig *p_cfg = nullptr;
257+
bool owns_cfg=false;
248258
AudioFs sd;
249259
size_t idx_pos = 0;
250260
char file_name[MAX_FILE_LEN];

0 commit comments

Comments
 (0)