From d04074a5422ddd8dc68ec8e73313269bfc57a1e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 4 Jan 2025 01:10:42 +0100 Subject: [PATCH] Atrac3 (not +): Keep decoding even on broken frames. Fixes some music in some unofficial game mods, whose music got broken in 1.18. Was reported through e-mail by Miguel. --- Core/HW/Atrac3Standalone.cpp | 11 ++++++++++- ext/at3_standalone/atrac3.cpp | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Core/HW/Atrac3Standalone.cpp b/Core/HW/Atrac3Standalone.cpp index e4bc79a3d6..cc34a15957 100644 --- a/Core/HW/Atrac3Standalone.cpp +++ b/Core/HW/Atrac3Standalone.cpp @@ -95,8 +95,17 @@ public: result = atrac3_decode_frame(at3Ctx_, buffers_, &nb_samples, inbuf, inbytes); } if (result < 0) { + // NOTE: Here, to recover from single bad packets, we update inBytesConsumed/outSamples with the regular packet size. + // Otherwise we might try to decode the same packet over and over. + // This is seen in some unofficial game mods, mainly. + if (inbytesConsumed) { + *inbytesConsumed = inbytes; + } if (outSamples) { - *outSamples = 0; + if (*outSamples != 0) { + nb_samples = std::min(*outSamples, nb_samples); + } + *outSamples = nb_samples; } return false; } diff --git a/ext/at3_standalone/atrac3.cpp b/ext/at3_standalone/atrac3.cpp index fd143a9ad6..8c3f7f5664 100644 --- a/ext/at3_standalone/atrac3.cpp +++ b/ext/at3_standalone/atrac3.cpp @@ -755,13 +755,14 @@ int atrac3_decode_frame(ATRAC3Context *ctx, float *out_data[2], int *nb_samples, databuf = buf; } + *nb_samples = SAMPLES_PER_FRAME; + ret = decode_frame(ctx, block_align, channels, databuf, out_data); if (ret) { av_log(AV_LOG_ERROR, "Frame decoding error!"); return ret; } - *nb_samples = SAMPLES_PER_FRAME; return block_align; }