From 5021a13aa94a758e32cdf548e21077604f080005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Wed, 14 Jul 2021 13:24:10 +0200 Subject: [PATCH] DSPHLE: Fix running and is_stream checks in AX HLE A voice is considered running if and only if `running` equals 1, not if `running` is not equal to 0. This fixes https://bugs.dolphin-emu.org/issues/12508 because for some reason *The Sims 2 - Castaway* sets `running` to 8 when a stream finishes playing; previously our AX HLE would just loop the voice and eventually crash after accessing invalid memory addresses. Thanks to JMC47 and delroth's help, I've verified that this is the correct check for the following ucodes: GC: * 0x3ad3b7ac * 0x3daf59b9 * 0x4e8a8b21 * 0x07f88145 * 0xe2136399 * 0x3389a79e Wii: * 0x347112ba * 0xfa450138 * 0xadbc06bd And while I was fixing the running check, I noticed that the is_stream field was also being handled incorrectly, so I've fixed that as well. --- Source/Core/Core/HW/DSPHLE/UCodes/AXStructs.h | 4 ++-- Source/Core/Core/HW/DSPHLE/UCodes/AXVoice.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/AXStructs.h b/Source/Core/Core/HW/DSPHLE/UCodes/AXStructs.h index c575423315..bbb8e67770 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/AXStructs.h +++ b/Source/Core/Core/HW/DSPHLE/UCodes/AXStructs.h @@ -236,8 +236,8 @@ struct AXPB u16 coef_select; u16 mixer_control; - u16 running; // 1=RUN 0=STOP - u16 is_stream; // 1 = stream, 0 = one shot + u16 running; // 1 = playing, anything else = stopped + u16 is_stream; // 1 = stream, anything else = one shot PBMixer mixer; PBInitialTimeDelay initial_time_delay; diff --git a/Source/Core/Core/HW/DSPHLE/UCodes/AXVoice.h b/Source/Core/Core/HW/DSPHLE/UCodes/AXVoice.h index aa9c56fe05..b35016c7b6 100644 --- a/Source/Core/Core/HW/DSPHLE/UCodes/AXVoice.h +++ b/Source/Core/Core/HW/DSPHLE/UCodes/AXVoice.h @@ -156,7 +156,7 @@ protected: { // Set the ADPCM info to continue processing at loop_addr. SetPredScale(acc_pb->adpcm_loop_info.pred_scale); - if (!acc_pb->is_stream) + if (acc_pb->is_stream != 1) { SetYn1(acc_pb->adpcm_loop_info.yn1); SetYn2(acc_pb->adpcm_loop_info.yn2); @@ -403,7 +403,7 @@ void ProcessVoice(PB_TYPE& pb, const AXBuffers& buffers, u16 count, AXMixControl const s16* coeffs) { // If the voice is not running, nothing to do. - if (!pb.running) + if (pb.running != 1) return; // Read input samples, performing sample rate conversion if needed.