From af742a753e122d95dfe0b4a0c71f82f40928d311 Mon Sep 17 00:00:00 2001 From: arcum42 Date: Sun, 9 Dec 2018 14:09:22 -0800 Subject: [PATCH] spu2-x: Fix warnings regarding initializing with memset/memzero/etc... (#2682) * spu2-x: Fix warnings regarding initializing with memset/memzero/etc... * Use fill_n instead, per turtleli's suggestion. * spu2-x: Comment out StereoOut initialization. * spu2-x: As requested, remove commented out code. --- plugins/spu2-x/src/RegLog.cpp | 1 + plugins/spu2-x/src/SndOut.cpp | 10 +++------- plugins/spu2-x/src/spu2sys.cpp | 32 ++++++++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/plugins/spu2-x/src/RegLog.cpp b/plugins/spu2-x/src/RegLog.cpp index 1914fc0f57..5b5a0af574 100644 --- a/plugins/spu2-x/src/RegLog.cpp +++ b/plugins/spu2-x/src/RegLog.cpp @@ -178,6 +178,7 @@ void SPU2writeLog(const char *action, u32 rmem, u16 value) break; case REG_S_VMIXL: RegLog(1, "VMIXL0", rmem, core, value); + break; case (REG_S_VMIXL + 2): RegLog(1, "VMIXL1", rmem, core, value); break; diff --git a/plugins/spu2-x/src/SndOut.cpp b/plugins/spu2-x/src/SndOut.cpp index 170853d86d..7963b12b75 100644 --- a/plugins/spu2-x/src/SndOut.cpp +++ b/plugins/spu2-x/src/SndOut.cpp @@ -282,7 +282,7 @@ void SndBuffer::ReadSamples(T *bData) // If quietSamples != 0 it means we have an underrun... // Let's just dull out some silence, because that's usually the least // painful way of dealing with underruns: - memset(bData, 0, quietSamples * sizeof(T)); + std::fill_n(bData, quietSamples, T{}); } template void SndBuffer::ReadSamples(StereoOut16 *); @@ -388,11 +388,6 @@ void SndBuffer::Init() return; } - // clear buffers! - // Fixes loopy sounds on emu resets. - memset(sndTempBuffer, 0, sizeof(StereoOut32) * SndOutPacketSize); - memset(sndTempBuffer16, 0, sizeof(StereoOut16) * SndOutPacketSize); - sndTempProgress = 0; soundtouchInit(); // initializes the timestretching @@ -445,7 +440,8 @@ void SndBuffer::Write(const StereoOut32 &Sample) //Don't play anything directly after loading a savestate, avoids static killing your speakers. if (ssFreeze > 0) { ssFreeze--; - memset(sndTempBuffer, 0, sizeof(StereoOut32) * SndOutPacketSize); // Play silence + // Play silence + std::fill_n(sndTempBuffer, SndOutPacketSize, StereoOut32{}); } #ifndef __POSIX__ if (dspPluginEnabled) { diff --git a/plugins/spu2-x/src/spu2sys.cpp b/plugins/spu2-x/src/spu2sys.cpp index f646d028fb..28364a98e9 100644 --- a/plugins/spu2-x/src/spu2sys.cpp +++ b/plugins/spu2-x/src/spu2sys.cpp @@ -118,8 +118,30 @@ V_Core::~V_Core() throw() void V_Core::Init(int index) { ConLog("* SPU2-X: Init SPU2 core %d \n", index); - memset(this, 0, sizeof(V_Core)); + //memset(this, 0, sizeof(V_Core)); + // Explicitly initializing variables instead. + Mute = false; + DMABits = 0; + NoiseClk = 0; + AutoDMACtrl = 0; + InputDataLeft = 0; + InputPosRead = 0; + InputPosWrite = 0; + InputDataProgress = 0; + ReverbX = 0; + LastEffect.Left = 0; + LastEffect.Right = 0; + CoreEnabled = 0; + AttrBit0 = 0; + DmaMode = 0; + DMAPtr = nullptr; + MADR = 0; + TADR = 0; + KeyOn = 0; + psxmode = false; + psxSoundDataTransferControl = 0; + psxSPUSTAT = 0; const int c = Index = index; @@ -150,7 +172,7 @@ void V_Core::Init(int index) ExtEffectsStartA = EffectsStartA; ExtEffectsEndA = EffectsEndA; - FxEnable = 0; // Uninitialized it's 0 for both cores. Resetting libs however may set this to 0 or 1. + FxEnable = false; // Uninitialized it's 0 for both cores. Resetting libs however may set this to 0 or 1. // These are real PS2 values, mainly constant apart from a few bits: 0x3220EAA4, 0x40505E9C. // These values mean nothing. They do not reflect the actual address the SPU2 is testing, // it would seem that reading the IRQA register returns the last written value, not the @@ -160,7 +182,7 @@ void V_Core::Init(int index) // in the input or output areas, so we're using 0x800. // F1 2005 is known to rely on an uninitialised IRQA being an address which will be hit. IRQA = 0x800; - IRQEnable = 0; // PS2 confirmed + IRQEnable = false; // PS2 confirmed for (uint v = 0; v < NumVoices; ++v) { VoiceGates[v].DryL = -1; @@ -180,7 +202,9 @@ void V_Core::Init(int index) } DMAICounter = 0; - AdmaInProgress = 0; + AutoDmaFree = 0; + AdmaInProgress = false; + DmaStarted = false; Regs.STATX = 0x80; Regs.ENDX = 0xffffff; // PS2 confirmed