mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-08-03 20:24:14 +02:00
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).
This commit is contained in:
@@ -259,9 +259,9 @@ void CGBPlayer_mGBA::ReadScanlines(std::span<u32, AV_REGION_SIZE> 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<u16>(x - (y << 11));
|
||||
return u32(0xffff'ffff'0000'0000ull >> y);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user