From a6842b648283c4026c3f0ed94268138204663448 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 10 Oct 2020 10:21:50 +0200 Subject: [PATCH] - ensure that sfxinfo_t is always fully initialized, regardless how the setup is performed. The recent pitch additions did not do this on all possible paths. --- src/common/audio/sound/s_sound.cpp | 25 +------ src/common/audio/sound/s_soundinternal.h | 84 ++++++++---------------- src/sound/s_advsound.cpp | 14 ---- 3 files changed, 30 insertions(+), 93 deletions(-) diff --git a/src/common/audio/sound/s_sound.cpp b/src/common/audio/sound/s_sound.cpp index a38dc9eb80..5509248547 100644 --- a/src/common/audio/sound/s_sound.cpp +++ b/src/common/audio/sound/s_sound.cpp @@ -50,7 +50,6 @@ enum }; static FRandom pr_soundpitch ("SoundPitch"); SoundEngine* soundEngine; -int sfx_empty = -1; //========================================================================== // @@ -713,10 +712,9 @@ sfxinfo_t *SoundEngine::LoadSound(sfxinfo_t *sfx) { unsigned int i; - // If the sound doesn't exist, replace it with the empty sound. - if (sfx->lumpnum == -1) + if (sfx->lumpnum == sfx_empty) { - sfx->lumpnum = sfx_empty; + return sfx; } // See if there is another sound already initialized with this lump. If so, @@ -1532,31 +1530,12 @@ int SoundEngine::AddSoundLump(const char* logicalname, int lump, int CurrentPitc S_sfx.Reserve(1); sfxinfo_t &newsfx = S_sfx.Last(); - newsfx.data.Clear(); newsfx.name = logicalname; newsfx.lumpnum = lump; newsfx.next = 0; - newsfx.index = 0; - newsfx.Volume = 1; - newsfx.Attenuation = 1; newsfx.PitchMask = CurrentPitchMask; - newsfx.DefPitch = 0.0; - newsfx.DefPitchMax = 0.0; newsfx.NearLimit = nearlimit; - newsfx.LimitRange = 256 * 256; - newsfx.bRandomHeader = false; - newsfx.bLoadRAW = false; - newsfx.b16bit = false; - newsfx.bUsed = false; - newsfx.bSingular = false; - newsfx.bTentative = false; newsfx.ResourceId = resid; - newsfx.RawRate = 0; - newsfx.link = sfxinfo_t::NO_LINK; - newsfx.Rolloff.RolloffType = ROLLOFF_Doom; - newsfx.Rolloff.MinDistance = 0; - newsfx.Rolloff.MaxDistance = 0; - newsfx.LoopStart = -1; if (resid >= 0) ResIdMap[resid] = S_sfx.Size() - 1; return (int)S_sfx.Size()-1; diff --git a/src/common/audio/sound/s_soundinternal.h b/src/common/audio/sound/s_soundinternal.h index 58b3a27c19..b3292637f6 100644 --- a/src/common/audio/sound/s_soundinternal.h +++ b/src/common/audio/sound/s_soundinternal.h @@ -8,7 +8,12 @@ struct FRandomSoundList uint32_t Owner = 0; }; -extern int sfx_empty; +enum +{ + sfx_empty = -1 +}; + + // // SoundFX struct. @@ -17,71 +22,38 @@ struct sfxinfo_t { // Next field is for use by the system sound interface. // A non-null data means the sound has been loaded. - SoundHandle data; + SoundHandle data{}; - FString name; // [RH] Sound name defined in SNDINFO - int lumpnum; // lump number of sfx + FString name; // [RH] Sound name defined in SNDINFO + int lumpnum = sfx_empty; // lump number of sfx - unsigned int next, index; // [RH] For hashing - float Volume; + unsigned int next = -1, index = 0; // [RH] For hashing + float Volume = 1.f; - int ResourceId; // Resource ID as implemented by Blood. Not used by Doom but added for completeness. - uint8_t PitchMask; - int16_t NearLimit; // 0 means unlimited - float LimitRange; // Range for sound limiting (squared for faster computations) - float DefPitch; // A defined pitch instead of a random one the sound plays at, similar to A_StartSound. - float DefPitchMax; // Randomized range with stronger control over pitch itself. + int ResourceId = -1; // Resource ID as implemented by Blood. Not used by Doom but added for completeness. + float LimitRange = 256*256; // Range for sound limiting (squared for faster computations) + float DefPitch = 0.f; // A defined pitch instead of a random one the sound plays at, similar to A_StartSound. + float DefPitchMax = 0.f; // Randomized range with stronger control over pitch itself. - unsigned bRandomHeader:1; - unsigned bLoadRAW:1; - unsigned b16bit:1; - unsigned bUsed:1; - unsigned bSingular:1; + int16_t NearLimit = 4; // 0 means unlimited. + uint8_t PitchMask = 0; + bool bRandomHeader = false; + bool bLoadRAW = false; + bool b16bit = false; + bool bUsed = false; + bool bSingular = false; + bool bTentative = true; - unsigned bTentative:1; TArray UserData; - int RawRate; // Sample rate to use when bLoadRAW is true + int RawRate = 0; // Sample rate to use when bLoadRAW is true + int LoopStart = -1; // -1 means no specific loop defined - int LoopStart; // -1 means no specific loop defined - - unsigned int link; + unsigned int link = NO_LINK;; enum { NO_LINK = 0xffffffff }; - FRolloffInfo Rolloff; - float Attenuation; // Multiplies the attenuation passed to S_Sound. - - void MarkUsed(); // Marks this sound as used. - - void Clear() - { - data.Clear(); - lumpnum = -1; // lump number of sfx - next = -1; - index = 0; // [RH] For hashing - Volume = 1.f; - ResourceId = -1; - PitchMask = 0; - NearLimit = 4; // 0 means unlimited - LimitRange = 256*256; - - bRandomHeader = false; - bLoadRAW = false; - b16bit= false; - bUsed = false; - bSingular = false; - - bTentative = true; - - RawRate = 0; // Sample rate to use when bLoadRAW is true - - LoopStart = 0; // -1 means no specific loop defined - - link = NO_LINK; - - Rolloff = {}; - Attenuation = 1.f; - } + FRolloffInfo Rolloff{}; + float Attenuation = 1.f; // Multiplies the attenuation passed to S_Sound. }; // Rolloff types diff --git a/src/sound/s_advsound.cpp b/src/sound/s_advsound.cpp index 1a4a39e1fe..608826b355 100644 --- a/src/sound/s_advsound.cpp +++ b/src/sound/s_advsound.cpp @@ -766,7 +766,6 @@ void S_ParseSndInfo (bool redefine) S_ShrinkPlayerSoundLists (); - sfx_empty = fileSystem.CheckNumForName ("dsempty", ns_sounds); S_CheckIntegrity(); } @@ -1671,19 +1670,6 @@ int S_FindSkinnedSoundEx (AActor *actor, const char *name, const char *extendedn return S_FindSkinnedSound (actor, id); } -//========================================================================== -// -// sfxinfo_t :: MarkUsed -// -// Marks this sound for precaching. -// -//========================================================================== - -void sfxinfo_t::MarkUsed() -{ - bUsed = true; -} - //========================================================================== // // S_MarkPlayerSounds