From b083ce5912b78f42a90705dac9321ea591517307 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 5 Apr 2026 21:07:00 +0200 Subject: [PATCH] HW/GBPlayer: Use u32 in SampleToPWM `value` contains 16 bits of data and `remainder` contains 11 bits of data. When they're added together, we may end up with 17 bits of data, so the result should be stored as u32 rather than u16. This fixes `y` being set to 0 (minimum amplitude) when it should be set to 32 (maximum amplitude). --- Source/Core/Core/HW/HSP/HSP_DeviceGBPlayer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/HW/HSP/HSP_DeviceGBPlayer.cpp b/Source/Core/Core/HW/HSP/HSP_DeviceGBPlayer.cpp index 5f41359bf2..5301d9ba27 100644 --- a/Source/Core/Core/HW/HSP/HSP_DeviceGBPlayer.cpp +++ b/Source/Core/Core/HW/HSP/HSP_DeviceGBPlayer.cpp @@ -259,9 +259,9 @@ void CGBPlayer_mGBA::ReadScanlines(std::span scanlines) // input to the next invocation of this function to average out quantization errors over time. static constexpr u32 SampleToPWM(u16 value, u16* remainder) { - const u16 x = value + *remainder; - const u16 y = x >> 11; - *remainder = x - (y << 11); + const u32 x = value + *remainder; + const u32 y = x >> 11; + *remainder = static_cast(x - (y << 11)); return u32(0xffff'ffff'0000'0000ull >> y); }