@@ -253,7 +253,7 @@ namespace audio_tools {
253
253
return info;
254
254
}
255
255
256
- // / starts / resumes the playing of a matching song
256
+ // / starts / resumes the playing after calling stop()
257
257
virtual void play () {
258
258
TRACED ();
259
259
setActive (true );
@@ -331,13 +331,15 @@ namespace audio_tools {
331
331
332
332
// / The same like start() / stop()
333
333
virtual void setActive (bool isActive){
334
- if (isActive){
335
- fade.setFadeInActive (true );
336
- } else {
337
- fade.setFadeOutActive (true );
338
- copier.copy ();
339
- writeSilence (2048 );
340
- }
334
+ if (is_auto_fade){
335
+ if (isActive){
336
+ fade.setFadeInActive (true );
337
+ } else {
338
+ fade.setFadeOutActive (true );
339
+ copier.copy ();
340
+ writeSilence (2048 );
341
+ }
342
+ }
341
343
active = isActive;
342
344
}
343
345
@@ -450,6 +452,15 @@ namespace audio_tools {
450
452
return &volume_out;
451
453
}
452
454
455
+ // / Activates/deactivates the automatic fade in and fade out to prevent popping sounds: default is active
456
+ bool setAutoFade (bool active){
457
+ is_auto_fade = active;
458
+ }
459
+
460
+ bool isAutoFade () {
461
+ return is_auto_fade;
462
+ }
463
+
453
464
protected:
454
465
bool active = false ;
455
466
bool autonext = true ;
@@ -472,13 +483,14 @@ namespace audio_tools {
472
483
int stream_increment = 1 ; // +1 moves forward; -1 moves backward
473
484
float current_volume = -1.0 ; // illegal value which will trigger an update
474
485
int delay_if_full = 100 ;
486
+ bool is_auto_fade = true ;
475
487
476
488
void setupFade () {
477
489
if (p_final_print != nullptr ) {
478
490
fade.setAudioInfo (p_final_print->audioInfo ());
479
491
} else if (p_final_stream != nullptr ){
480
492
fade.setAudioInfo (p_final_stream->audioInfo ());
481
- }
493
+ }
482
494
}
483
495
484
496
@@ -487,7 +499,7 @@ namespace audio_tools {
487
499
if (p_final_stream==nullptr ) return ;
488
500
if (p_final_stream->availableForWrite ()==0 ) return ;
489
501
if (p_input_stream == nullptr || millis () > timeout) {
490
- fade.setFadeInActive (true );
502
+ if (is_auto_fade) fade.setFadeInActive (true );
491
503
if (autonext) {
492
504
LOGI (" -> timeout - moving by %d" , stream_increment);
493
505
// open next stream
@@ -505,10 +517,12 @@ namespace audio_tools {
505
517
void writeEnd () {
506
518
// end silently
507
519
TRACEI ();
508
- fade.setFadeOutActive (true );
509
- copier.copy ();
510
- // start by fading in
511
- fade.setFadeInActive (true );
520
+ if (is_auto_fade){
521
+ fade.setFadeOutActive (true );
522
+ copier.copy ();
523
+ // start by fading in
524
+ fade.setFadeInActive (true );
525
+ }
512
526
// restart the decoder to make sure it does not contain any audio when we continue
513
527
p_decoder->begin ();
514
528
}
0 commit comments