Skip to content

Commit 84cb7f8

Browse files
committed
VS1053Stream logging
1 parent e30ca22 commit 84cb7f8

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

src/AudioLibs/VS1053Stream.h

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ namespace audio_tools {
1313
class VS1053BaseStream : public AudioStreamX {
1414
public:
1515
VS1053BaseStream(uint8_t _cs_pin, uint8_t _dcs_pin, uint8_t _dreq_pin,int16_t _reset_pin=-1){
16+
LOGD(LOG_METHOD);
1617
this->_cs_pin = _cs_pin;
1718
this->_dcs_pin = _dcs_pin;
1819
this->_dreq_pin = _dreq_pin;
1920
this->_reset_pin = _reset_pin;
2021
}
2122

2223
bool begin() {
24+
LOGD(LOG_METHOD);
2325
p_vs1053 = new VS1053(_cs_pin,_dcs_pin,_dreq_pin, _reset_pin);
2426
// initialize SPI
2527
SPI.begin();
@@ -35,6 +37,7 @@ class VS1053BaseStream : public AudioStreamX {
3537

3638
void end(){
3739
if (p_vs1053!=nullptr){
40+
LOGD(LOG_METHOD);
3841
p_vs1053->stopSong();
3942
delete p_vs1053;
4043
p_vs1053 = nullptr;
@@ -43,6 +46,7 @@ class VS1053BaseStream : public AudioStreamX {
4346

4447
/// value from 0 to 1.0
4548
void setVolume(float vol){
49+
LOGD(LOG_METHOD);
4650
// make sure that value is between 0 and 1
4751
float volume = vol;
4852
if (volume>1.0) volume = 1.0;
@@ -55,12 +59,14 @@ class VS1053BaseStream : public AudioStreamX {
5559

5660
/// provides the volume
5761
float volume() {
62+
LOGD(LOG_METHOD);
5863
if (p_vs1053==nullptr) return -1.0;
5964
return p_vs1053->getVolume()/100.0;;
6065
}
6166

6267
/// Adjusting the left and right volume balance, higher to enhance the right side, lower to enhance the left side.
6368
void setBalance(float bal){
69+
LOGD(LOG_METHOD);
6470
float balance = bal;
6571
if (balance<-1.0) balance = -1;
6672
if (balance>1.0) balance = 1;
@@ -70,18 +76,21 @@ class VS1053BaseStream : public AudioStreamX {
7076
}
7177
/// Get the currenet balance setting (-1.0..1.0)
7278
float balance(){
79+
LOGD(LOG_METHOD);
7380
if (p_vs1053==nullptr) return -1.0;
7481
return static_cast<float>(p_vs1053->getBalance())/100.0;
7582
}
7683

7784
/// Provides the treble amplitude value
7885
float treble() {
86+
LOGD(LOG_METHOD);
7987
if (p_vs1053==nullptr) return -1.0;
8088
return static_cast<float>(p_vs1053->treble())/100.0;
8189
}
8290

8391
/// Sets the treble amplitude value (range 0 to 1.0)
8492
void setTreble(float val){
93+
LOGD(LOG_METHOD);
8594
float value = val;
8695
if (value<0.0) value = 0.0;
8796
if (value>1.0) value = 1.0;
@@ -92,25 +101,29 @@ class VS1053BaseStream : public AudioStreamX {
92101

93102
/// Provides the Bass amplitude value
94103
float bass() {
104+
LOGD(LOG_METHOD);
95105
if (p_vs1053==nullptr) return -1;
96106
return static_cast<float>(p_vs1053->bass())/100.0;
97107
}
98108

99109
/// Sets the bass amplitude value (range 0 to 1.0)
100110
void setBass(float value){
111+
LOGD(LOG_METHOD);
101112
if (p_vs1053!=nullptr){
102113
p_vs1053->setBass(value*100.0);
103114
}
104115
}
105116

106117
/// Sets the treble frequency limit in hz (range 0 to 15000)
107118
void setTrebleFrequencyLimit(uint16_t value){
119+
LOGD(LOG_METHOD);
108120
if (p_vs1053!=nullptr){
109121
p_vs1053->setTrebleFrequencyLimit(value);
110122
}
111123
}
112124
/// Sets the bass frequency limit in hz (range 0 to 15000)
113125
void setBassFrequencyLimit(uint16_t value){
126+
LOGD(LOG_METHOD);
114127
if (p_vs1053!=nullptr){
115128
p_vs1053->setBassFrequencyLimit(value);
116129
}
@@ -124,6 +137,7 @@ class VS1053BaseStream : public AudioStreamX {
124137
}
125138

126139
VS1053 &getVS1053() {
140+
LOGD(LOG_METHOD);
127141
if (p_vs1053==nullptr) begin();
128142
return *p_vs1053;
129143
}
@@ -167,6 +181,7 @@ class VS1053Stream : public AudioStreamX {
167181
}
168182

169183
VS1053Config defaultConfig() {
184+
LOGD(LOG_METHOD);
170185
VS1053Config c;
171186
return c;
172187
}
@@ -178,6 +193,15 @@ class VS1053Stream : public AudioStreamX {
178193

179194
/// Starts with the indicated configuration
180195
bool begin(VS1053Config cfg) {
196+
LOGI(LOG_METHOD);
197+
cfg.logInfo();
198+
LOGI("is_encoded_data: %s", cfg.is_encoded_data?"true":"false");
199+
LOGI("cs_pin: %d", cfg.cs_pin);
200+
LOGI("dcs_pin: %d", cfg.dcs_pin);
201+
LOGI("dreq_pin: %d", cfg.dreq_pin);
202+
LOGI("reset_pin: %d", cfg.reset_pin);
203+
LOGI("cs_sd_pin: %d", cfg.cs_sd_pin);
204+
181205
this->cfg = cfg;
182206
setAudioInfo(cfg);
183207
if (p_driver==nullptr){
@@ -193,6 +217,7 @@ class VS1053Stream : public AudioStreamX {
193217

194218
/// Stops the processing and releases the memory
195219
void end(){
220+
LOGI(LOG_METHOD);
196221
if (p_out!=nullptr){
197222
delete p_out;
198223
p_out = nullptr;
@@ -206,6 +231,7 @@ class VS1053Stream : public AudioStreamX {
206231

207232
/// Sets the volume: value from 0 to 1.0
208233
void setVolume(float volume){
234+
LOGI(LOG_METHOD);
209235
if (p_driver==nullptr) {
210236
logError(__FUNCTION__);
211237
return;
@@ -214,6 +240,7 @@ class VS1053Stream : public AudioStreamX {
214240
}
215241
/// provides the volume
216242
float volume() {
243+
LOGI(LOG_METHOD);
217244
if (p_driver==nullptr) {
218245
logError(__FUNCTION__);
219246
return -1;
@@ -223,6 +250,7 @@ class VS1053Stream : public AudioStreamX {
223250

224251
/// Adjusting the left and right volume balance, higher to enhance the right side, lower to enhance the left side.
225252
void setBalance(float balance){
253+
LOGI(LOG_METHOD);
226254
if (p_driver==nullptr) {
227255
logError(__FUNCTION__);
228256
return;
@@ -231,6 +259,7 @@ class VS1053Stream : public AudioStreamX {
231259
}
232260
/// Get the currenet balance setting (-1.0..1.0)
233261
float balance(){
262+
LOGD(LOG_METHOD);
234263
if (p_driver==nullptr) {
235264
logError(__FUNCTION__);
236265
return -1;
@@ -240,6 +269,7 @@ class VS1053Stream : public AudioStreamX {
240269

241270
/// Provides the treble amplitude value
242271
float treble() {
272+
LOGD(LOG_METHOD);
243273
if (p_driver==nullptr) {
244274
logError(__FUNCTION__);
245275
return -1;
@@ -249,6 +279,7 @@ class VS1053Stream : public AudioStreamX {
249279

250280
/// Sets the treble amplitude value (range 0 to 1.0)
251281
void setTreble(float value){
282+
LOGI(LOG_METHOD);
252283
if (p_driver==nullptr) {
253284
logError(__FUNCTION__);
254285
return;
@@ -258,6 +289,7 @@ class VS1053Stream : public AudioStreamX {
258289

259290
/// Provides the Bass amplitude value
260291
float bass() {
292+
LOGD(LOG_METHOD);
261293
if (p_driver==nullptr) {
262294
logError(__FUNCTION__);
263295
return -1;
@@ -267,6 +299,7 @@ class VS1053Stream : public AudioStreamX {
267299

268300
/// Sets the bass amplitude value (range 0 to 1.0)
269301
void setBass(float value){
302+
LOGI(LOG_METHOD);
270303
if (p_driver==nullptr) {
271304
logError(__FUNCTION__);
272305
return;
@@ -276,6 +309,7 @@ class VS1053Stream : public AudioStreamX {
276309

277310
/// Sets the treble frequency limit in hz (range 0 to 15000)
278311
void setTrebleFrequencyLimit(uint16_t value){
312+
LOGI(LOG_METHOD);
279313
if (p_driver==nullptr) {
280314
logError(__FUNCTION__);
281315
return;
@@ -284,6 +318,7 @@ class VS1053Stream : public AudioStreamX {
284318
}
285319
/// Sets the bass frequency limit in hz (range 0 to 15000)
286320
void setBassFrequencyLimit(uint16_t value){
321+
LOGI(LOG_METHOD);
287322
if (p_driver==nullptr) {
288323
logError(__FUNCTION__);
289324
return;
@@ -299,23 +334,27 @@ class VS1053Stream : public AudioStreamX {
299334

300335
/// returns the VS1053 object
301336
VS1053 &getVS1053() {
337+
LOGD(LOG_METHOD);
302338
return p_driver->getVS1053();
303339
}
304340

305341
/// Defines an alternative encoder that will be used (e.g. MP3Encoder). It must be allocated on the heap!
306342
bool setEncoder(AudioEncoder *enc){
343+
LOGI(LOG_METHOD);
307344
if (p_out!=nullptr){
308345
logError("setEncoder");
309346
return false;
310347
}
311-
delete p_encoder;
312-
p_encoder = enc;
348+
if (p_encoder!=nullptr){
349+
delete p_encoder;
350+
p_encoder = enc;
351+
}
313352
return true;
314353
}
315354

316355
protected:
317356
VS1053Config cfg;
318-
VS1053BaseStream *p_driver=nullptr;
357+
VS1053BaseStream *p_driver = nullptr;
319358
EncodedAudioStream *p_out = nullptr;
320359
AudioEncoder *p_encoder = new WAVEncoder(); // by default we send wav data
321360
CopyEncoder copy; // used when is_encoded_data == true

0 commit comments

Comments
 (0)