From a43664c0fd9bb56d2bb4ef3b4f1943a19b767066 Mon Sep 17 00:00:00 2001 From: lizzie Date: Wed, 5 Aug 2026 21:56:18 +0200 Subject: [audio_core] Fix jamboree crash due to OOB access (#4252) Signed-off-by: lizzie - [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions). - [x] I have read and followed the [AI Policy](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/AI.md) - [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability. ------------------- PLEASE test diablo 3 or ANY game that's sensitive to audio changes Just TEST that there's NO regressions on the audio front this fixes a rare Jamboree crash with audio DSP Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4252 Reviewed-by: CamilleLaVey Reviewed-by: Shinmegumi --- .../renderer/command/resample/resample.cpp | 29 +++++++++------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'src/audio_core/renderer/command/resample/resample.cpp') diff --git a/src/audio_core/renderer/command/resample/resample.cpp b/src/audio_core/renderer/command/resample/resample.cpp index 51f4ba39eb..c20b5aa4a8 100644 --- a/src/audio_core/renderer/command/resample/resample.cpp +++ b/src/audio_core/renderer/command/resample/resample.cpp @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later @@ -5,21 +8,13 @@ namespace AudioCore::Renderer { -static void ResampleLowQuality(std::span output, std::span input, - const Common::FixedPoint<49, 15>& sample_rate_ratio, - Common::FixedPoint<49, 15>& fraction, const u32 samples_to_write) { - if (sample_rate_ratio == 1.0f) { - for (u32 i = 0; i < samples_to_write; i++) { - output[i] = input[i]; - } - } else { - u32 read_index{0}; - for (u32 i = 0; i < samples_to_write; i++) { - output[i] = input[read_index + (fraction >= 0.5f)]; - fraction += sample_rate_ratio; - read_index += static_cast(fraction.to_int_floor()); - fraction.clear_int(); - } +static void ResampleLowQuality(std::span output, std::span input, const Common::FixedPoint<49, 15>& sample_rate_ratio, Common::FixedPoint<49, 15>& fraction, const u32 samples_to_write) { + u32 read_index{0}; + for (u32 i = 0; i < samples_to_write; i++) { + output[i] = input[read_index + (fraction >= 0.5f)]; + fraction += sample_rate_ratio; + read_index += u32(fraction.to_int_floor()); + fraction.clear_int(); } } @@ -295,7 +290,7 @@ static void ResampleNormalQuality(std::span output, std::span in auto lut{get_lut()}; u32 read_index{0}; for (u32 i = 0; i < samples_to_write; i++) { - const auto lut_index{(fraction.get_frac() >> 8) * 4}; + const auto lut_index = ((fraction.get_frac() >> 8) << 2) & 511; const Common::FixedPoint<56, 8> sample0{input[read_index + 0] * lut[lut_index + 0]}; const Common::FixedPoint<56, 8> sample1{input[read_index + 1] * lut[lut_index + 1]}; const Common::FixedPoint<56, 8> sample2{input[read_index + 2] * lut[lut_index + 2]}; @@ -845,7 +840,7 @@ static void ResampleHighQuality(std::span output, std::span inpu auto lut{get_lut()}; u32 read_index{0}; for (u32 i = 0; i < samples_to_write; i++) { - const auto lut_index{(fraction.get_frac() >> 8) * 8}; + const auto lut_index = ((fraction.get_frac() >> 8) << 3) & 1023; const Common::FixedPoint<56, 8> sample0{input[read_index + 0] * lut[lut_index + 0]}; const Common::FixedPoint<56, 8> sample1{input[read_index + 1] * lut[lut_index + 1]}; const Common::FixedPoint<56, 8> sample2{input[read_index + 2] * lut[lut_index + 2]}; -- cgit v1.2.3