From 68575d15a444c6f5e5e20feafaa4aae7d4e94a91 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 23 Jul 2024 22:10:04 +1000 Subject: [PATCH] CDROM: Shift instead of divide in ZigZagInterpolate --- src/core/cdrom.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/cdrom.cpp b/src/core/cdrom.cpp index 0f96c1037..06cd873cb 100644 --- a/src/core/cdrom.cpp +++ b/src/core/cdrom.cpp @@ -353,6 +353,7 @@ template static void DecodeXAADPCMChunks(const u8* chunk_ptr, s16* samples); template static void ResampleXAADPCM(const s16* frames_in, u32 num_frames_in); +static s16 ZigZagInterpolate(const s16* ringbuf, const s16* table, u8 p); static TinyString LBAToMSFString(CDImage::LBA lba); @@ -3137,11 +3138,11 @@ static std::array, 7> s_zigzag_table = { 0x3C07, 0x53E0, -0x16FA, 0x0AFA, -0x0548, 0x027B, -0x00EB, 0x001A, 0x002B, -0x0023, 0x0010, -0x0008, 0x0002, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}}; -static s16 ZigZagInterpolate(const s16* ringbuf, const s16* table, u8 p) +ALWAYS_INLINE_RELEASE s16 CDROM::ZigZagInterpolate(const s16* ringbuf, const s16* table, u8 p) { s32 sum = 0; for (u8 i = 0; i < 29; i++) - sum += (s32(ringbuf[(p - i) & 0x1F]) * s32(table[i])) / 0x8000; + sum += (static_cast(ringbuf[(p - i) & 0x1F]) * static_cast(table[i])) >> 15; return static_cast(std::clamp(sum, -0x8000, 0x7FFF)); }