From 902b88ac1a718f008133186811e98bc929ad94fa Mon Sep 17 00:00:00 2001 From: monster860 Date: Mon, 22 Jul 2019 12:46:10 -0400 Subject: [PATCH] Spu2-x: Fix noise generator. (#3030) Fixes the noise generator outputting a 4.8 kHz tone instead of white noise. The random number generator used in GetNoiseValues currently repeats every 10 samples, which is really really awful for a random number generator. New code based on http://problemkaputt.de/psx-spx.htm#spunoisegenerator --- plugins/spu2-x/src/Mixer.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/plugins/spu2-x/src/Mixer.cpp b/plugins/spu2-x/src/Mixer.cpp index 2c75c4cc9c..060d00a2db 100644 --- a/plugins/spu2-x/src/Mixer.cpp +++ b/plugins/spu2-x/src/Mixer.cpp @@ -257,22 +257,12 @@ static __forceinline void GetNextDataDummy(V_Core &thiscore, uint voiceidx) static s32 __forceinline GetNoiseValues() { - static s32 Seed = 0x41595321; - s32 retval = 0x8000; + static u16 lfsr = 0xC0FEu; - if (Seed & 0x100) - retval = (Seed & 0xff) << 8; - else if (Seed & 0xffff) - retval = 0x7fff; + u16 bit = lfsr ^ (lfsr << 3) ^ (lfsr << 4) ^ (lfsr << 5); + lfsr = (lfsr << 1) | (bit >> 15); - s32 x = _rotr(Seed, 0x5); - x ^= 0x9a; - s32 y = _rotl(x, 0x2); - y += x; - y ^= x; - Seed = _rotr(y, 0x3); - - return retval; + return (s16)lfsr; } ///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////