From 520f3915175cf62e3aaf9f51ea3d6d7b6c89eef7 Mon Sep 17 00:00:00 2001 From: pschatzmann Date: Sat, 4 Nov 2023 16:53:12 +0100 Subject: [PATCH] Correct Broken AudioPlayer (Fade) --- src/AudioCodecs/AudioEncoded.h | 9 +++++++-- src/AudioTools/AudioPlayer.h | 4 +--- src/AudioTools/Fade.h | 2 ++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/AudioCodecs/AudioEncoded.h b/src/AudioCodecs/AudioEncoded.h index 5fd15f96fd..9f76dbe9a9 100644 --- a/src/AudioCodecs/AudioEncoded.h +++ b/src/AudioCodecs/AudioEncoded.h @@ -374,7 +374,7 @@ class EncodedAudioOutput : public AudioStream { return 0; } - if(availableForWrite()==0){ + if(check_available_for_write && availableForWrite()==0){ return 0; } @@ -400,6 +400,10 @@ class EncodedAudioOutput : public AudioStream { void setLogLevel(AudioLogger::LogLevel level){ custom_log_level.set(level); } + /// Is Available for Write check activated ? + bool isCheckAvailableForWrite() { + return check_available_for_write; + } protected: //AudioInfo info; @@ -407,7 +411,8 @@ class EncodedAudioOutput : public AudioStream { AudioEncoder *encoder_ptr = CodecNOP::instance(); // decoder AudioWriter *writer_ptr = nullptr; Print *ptr_out = nullptr; - bool active; + bool active = false; + bool check_available_for_write = false; CustomLogLevel custom_log_level; }; diff --git a/src/AudioTools/AudioPlayer.h b/src/AudioTools/AudioPlayer.h index 45439aa090..f82adb837c 100644 --- a/src/AudioTools/AudioPlayer.h +++ b/src/AudioTools/AudioPlayer.h @@ -169,9 +169,7 @@ namespace audio_tools { autonext = p_source->isAutoNext(); // initial audio info for fade from output when not defined yet - if (fade.audioInfo().channels==0){ - setupFade(); - } + setupFade(); // start dependent objects p_out_decoding->begin(); diff --git a/src/AudioTools/Fade.h b/src/AudioTools/Fade.h index 8512e6e7da..62e18d89a3 100644 --- a/src/AudioTools/Fade.h +++ b/src/AudioTools/Fade.h @@ -253,6 +253,7 @@ class FadeStream : public AudioStream { /// same as setStream void setOutput(Stream &io) { p_io = &io; + p_out = &io; } /// same as setOutput @@ -277,6 +278,7 @@ class FadeStream : public AudioStream { int available() override { return p_io == nullptr ? 0 : p_io->available(); } size_t write(const uint8_t *buffer, size_t size) override { + if (p_out==nullptr) return 0; if (!active) { LOGE("%s", error_msg); return 0;