@@ -13,13 +13,15 @@ namespace audio_tools {
13
13
class VS1053BaseStream : public AudioStreamX {
14
14
public:
15
15
VS1053BaseStream (uint8_t _cs_pin, uint8_t _dcs_pin, uint8_t _dreq_pin,int16_t _reset_pin=-1 ){
16
+ LOGD (LOG_METHOD);
16
17
this ->_cs_pin = _cs_pin;
17
18
this ->_dcs_pin = _dcs_pin;
18
19
this ->_dreq_pin = _dreq_pin;
19
20
this ->_reset_pin = _reset_pin;
20
21
}
21
22
22
23
bool begin () {
24
+ LOGD (LOG_METHOD);
23
25
p_vs1053 = new VS1053 (_cs_pin,_dcs_pin,_dreq_pin, _reset_pin);
24
26
// initialize SPI
25
27
SPI.begin ();
@@ -35,6 +37,7 @@ class VS1053BaseStream : public AudioStreamX {
35
37
36
38
void end (){
37
39
if (p_vs1053!=nullptr ){
40
+ LOGD (LOG_METHOD);
38
41
p_vs1053->stopSong ();
39
42
delete p_vs1053;
40
43
p_vs1053 = nullptr ;
@@ -43,6 +46,7 @@ class VS1053BaseStream : public AudioStreamX {
43
46
44
47
// / value from 0 to 1.0
45
48
void setVolume (float vol){
49
+ LOGD (LOG_METHOD);
46
50
// make sure that value is between 0 and 1
47
51
float volume = vol;
48
52
if (volume>1.0 ) volume = 1.0 ;
@@ -55,12 +59,14 @@ class VS1053BaseStream : public AudioStreamX {
55
59
56
60
// / provides the volume
57
61
float volume () {
62
+ LOGD (LOG_METHOD);
58
63
if (p_vs1053==nullptr ) return -1.0 ;
59
64
return p_vs1053->getVolume ()/100.0 ;;
60
65
}
61
66
62
67
// / Adjusting the left and right volume balance, higher to enhance the right side, lower to enhance the left side.
63
68
void setBalance (float bal){
69
+ LOGD (LOG_METHOD);
64
70
float balance = bal;
65
71
if (balance<-1.0 ) balance = -1 ;
66
72
if (balance>1.0 ) balance = 1 ;
@@ -70,18 +76,21 @@ class VS1053BaseStream : public AudioStreamX {
70
76
}
71
77
// / Get the currenet balance setting (-1.0..1.0)
72
78
float balance (){
79
+ LOGD (LOG_METHOD);
73
80
if (p_vs1053==nullptr ) return -1.0 ;
74
81
return static_cast <float >(p_vs1053->getBalance ())/100.0 ;
75
82
}
76
83
77
84
// / Provides the treble amplitude value
78
85
float treble () {
86
+ LOGD (LOG_METHOD);
79
87
if (p_vs1053==nullptr ) return -1.0 ;
80
88
return static_cast <float >(p_vs1053->treble ())/100.0 ;
81
89
}
82
90
83
91
// / Sets the treble amplitude value (range 0 to 1.0)
84
92
void setTreble (float val){
93
+ LOGD (LOG_METHOD);
85
94
float value = val;
86
95
if (value<0.0 ) value = 0.0 ;
87
96
if (value>1.0 ) value = 1.0 ;
@@ -92,25 +101,29 @@ class VS1053BaseStream : public AudioStreamX {
92
101
93
102
// / Provides the Bass amplitude value
94
103
float bass () {
104
+ LOGD (LOG_METHOD);
95
105
if (p_vs1053==nullptr ) return -1 ;
96
106
return static_cast <float >(p_vs1053->bass ())/100.0 ;
97
107
}
98
108
99
109
// / Sets the bass amplitude value (range 0 to 1.0)
100
110
void setBass (float value){
111
+ LOGD (LOG_METHOD);
101
112
if (p_vs1053!=nullptr ){
102
113
p_vs1053->setBass (value*100.0 );
103
114
}
104
115
}
105
116
106
117
// / Sets the treble frequency limit in hz (range 0 to 15000)
107
118
void setTrebleFrequencyLimit (uint16_t value){
119
+ LOGD (LOG_METHOD);
108
120
if (p_vs1053!=nullptr ){
109
121
p_vs1053->setTrebleFrequencyLimit (value);
110
122
}
111
123
}
112
124
// / Sets the bass frequency limit in hz (range 0 to 15000)
113
125
void setBassFrequencyLimit (uint16_t value){
126
+ LOGD (LOG_METHOD);
114
127
if (p_vs1053!=nullptr ){
115
128
p_vs1053->setBassFrequencyLimit (value);
116
129
}
@@ -124,6 +137,7 @@ class VS1053BaseStream : public AudioStreamX {
124
137
}
125
138
126
139
VS1053 &getVS1053 () {
140
+ LOGD (LOG_METHOD);
127
141
if (p_vs1053==nullptr ) begin ();
128
142
return *p_vs1053;
129
143
}
@@ -167,6 +181,7 @@ class VS1053Stream : public AudioStreamX {
167
181
}
168
182
169
183
VS1053Config defaultConfig () {
184
+ LOGD (LOG_METHOD);
170
185
VS1053Config c;
171
186
return c;
172
187
}
@@ -178,6 +193,15 @@ class VS1053Stream : public AudioStreamX {
178
193
179
194
// / Starts with the indicated configuration
180
195
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
+
181
205
this ->cfg = cfg;
182
206
setAudioInfo (cfg);
183
207
if (p_driver==nullptr ){
@@ -193,6 +217,7 @@ class VS1053Stream : public AudioStreamX {
193
217
194
218
// / Stops the processing and releases the memory
195
219
void end (){
220
+ LOGI (LOG_METHOD);
196
221
if (p_out!=nullptr ){
197
222
delete p_out;
198
223
p_out = nullptr ;
@@ -206,6 +231,7 @@ class VS1053Stream : public AudioStreamX {
206
231
207
232
// / Sets the volume: value from 0 to 1.0
208
233
void setVolume (float volume){
234
+ LOGI (LOG_METHOD);
209
235
if (p_driver==nullptr ) {
210
236
logError (__FUNCTION__);
211
237
return ;
@@ -214,6 +240,7 @@ class VS1053Stream : public AudioStreamX {
214
240
}
215
241
// / provides the volume
216
242
float volume () {
243
+ LOGI (LOG_METHOD);
217
244
if (p_driver==nullptr ) {
218
245
logError (__FUNCTION__);
219
246
return -1 ;
@@ -223,6 +250,7 @@ class VS1053Stream : public AudioStreamX {
223
250
224
251
// / Adjusting the left and right volume balance, higher to enhance the right side, lower to enhance the left side.
225
252
void setBalance (float balance){
253
+ LOGI (LOG_METHOD);
226
254
if (p_driver==nullptr ) {
227
255
logError (__FUNCTION__);
228
256
return ;
@@ -231,6 +259,7 @@ class VS1053Stream : public AudioStreamX {
231
259
}
232
260
// / Get the currenet balance setting (-1.0..1.0)
233
261
float balance (){
262
+ LOGD (LOG_METHOD);
234
263
if (p_driver==nullptr ) {
235
264
logError (__FUNCTION__);
236
265
return -1 ;
@@ -240,6 +269,7 @@ class VS1053Stream : public AudioStreamX {
240
269
241
270
// / Provides the treble amplitude value
242
271
float treble () {
272
+ LOGD (LOG_METHOD);
243
273
if (p_driver==nullptr ) {
244
274
logError (__FUNCTION__);
245
275
return -1 ;
@@ -249,6 +279,7 @@ class VS1053Stream : public AudioStreamX {
249
279
250
280
// / Sets the treble amplitude value (range 0 to 1.0)
251
281
void setTreble (float value){
282
+ LOGI (LOG_METHOD);
252
283
if (p_driver==nullptr ) {
253
284
logError (__FUNCTION__);
254
285
return ;
@@ -258,6 +289,7 @@ class VS1053Stream : public AudioStreamX {
258
289
259
290
// / Provides the Bass amplitude value
260
291
float bass () {
292
+ LOGD (LOG_METHOD);
261
293
if (p_driver==nullptr ) {
262
294
logError (__FUNCTION__);
263
295
return -1 ;
@@ -267,6 +299,7 @@ class VS1053Stream : public AudioStreamX {
267
299
268
300
// / Sets the bass amplitude value (range 0 to 1.0)
269
301
void setBass (float value){
302
+ LOGI (LOG_METHOD);
270
303
if (p_driver==nullptr ) {
271
304
logError (__FUNCTION__);
272
305
return ;
@@ -276,6 +309,7 @@ class VS1053Stream : public AudioStreamX {
276
309
277
310
// / Sets the treble frequency limit in hz (range 0 to 15000)
278
311
void setTrebleFrequencyLimit (uint16_t value){
312
+ LOGI (LOG_METHOD);
279
313
if (p_driver==nullptr ) {
280
314
logError (__FUNCTION__);
281
315
return ;
@@ -284,6 +318,7 @@ class VS1053Stream : public AudioStreamX {
284
318
}
285
319
// / Sets the bass frequency limit in hz (range 0 to 15000)
286
320
void setBassFrequencyLimit (uint16_t value){
321
+ LOGI (LOG_METHOD);
287
322
if (p_driver==nullptr ) {
288
323
logError (__FUNCTION__);
289
324
return ;
@@ -299,23 +334,27 @@ class VS1053Stream : public AudioStreamX {
299
334
300
335
// / returns the VS1053 object
301
336
VS1053 &getVS1053 () {
337
+ LOGD (LOG_METHOD);
302
338
return p_driver->getVS1053 ();
303
339
}
304
340
305
341
// / Defines an alternative encoder that will be used (e.g. MP3Encoder). It must be allocated on the heap!
306
342
bool setEncoder (AudioEncoder *enc){
343
+ LOGI (LOG_METHOD);
307
344
if (p_out!=nullptr ){
308
345
logError (" setEncoder" );
309
346
return false ;
310
347
}
311
- delete p_encoder;
312
- p_encoder = enc;
348
+ if (p_encoder!=nullptr ){
349
+ delete p_encoder;
350
+ p_encoder = enc;
351
+ }
313
352
return true ;
314
353
}
315
354
316
355
protected:
317
356
VS1053Config cfg;
318
- VS1053BaseStream *p_driver= nullptr ;
357
+ VS1053BaseStream *p_driver = nullptr ;
319
358
EncodedAudioStream *p_out = nullptr ;
320
359
AudioEncoder *p_encoder = new WAVEncoder(); // by default we send wav data
321
360
CopyEncoder copy; // used when is_encoded_data == true
0 commit comments