From a65393938075d222ff71f5c543c81ecc88c7ad86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 3 Jun 2024 10:00:02 +0200 Subject: [PATCH] Avoid crashing when atrac3 decoders fail to init due to bad params. Fixes Kosmodrones (though no music). --- Core/HW/Atrac3Standalone.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Core/HW/Atrac3Standalone.cpp b/Core/HW/Atrac3Standalone.cpp index b284be90bd..2e4ad22086 100644 --- a/Core/HW/Atrac3Standalone.cpp +++ b/Core/HW/Atrac3Standalone.cpp @@ -1,5 +1,5 @@ #include "SimpleAudioDec.h" - +#include "Common/LogReporting.h" #include "ext/at3_standalone/at3_decoders.h" inline int16_t clamp16(float f) { @@ -20,12 +20,18 @@ public: blockAlign_ = (int)blockAlign; if (audioType == PSP_CODEC_AT3PLUS) { at3pCtx_ = atrac3p_alloc(channels, &blockAlign_); - if (at3pCtx_) + if (at3pCtx_) { codecOpen_ = true; + } else { + ERROR_LOG(ME, "Failed to open atrac3+ context! (channels=%d blockAlign=%d ed=%d)", channels, blockAlign, extraDataSize); + } } else if (audioType_ == PSP_CODEC_AT3) { at3Ctx_ = atrac3_alloc(channels, &blockAlign_, extraData, (int)extraDataSize); - if (at3Ctx_) + if (at3Ctx_) { codecOpen_ = true; + } else { + ERROR_LOG(ME, "Failed to open atrac3 context! !channels=%d blockAlign=%d ed=%d)", channels, blockAlign, extraDataSize); + } } for (int i = 0; i < 2; i++) { buffers_[i] = new float[4096]; @@ -58,7 +64,12 @@ public: bool Decode(const uint8_t *inbuf, int inbytes, int *inbytesConsumed, int outputChannels, int16_t *outbuf, int *outSamples) override { if (!codecOpen_) { - _dbg_assert_(false); + WARN_LOG_N_TIMES(codecNotOpen, 5, ME, "Atrac3Audio:Decode: Codec not open, not decoding"); + if (outSamples) + *outSamples = 0; + if (inbytesConsumed) + *inbytesConsumed = 0; + return false; } if (inbytes != blockAlign_ && blockAlign_ != 0) { WARN_LOG(ME, "Atrac3Audio::Decode: Unexpected block align %d (expected %d)", inbytes, blockAlign_);