diff --git a/source/common/audio/sound/s_sound.cpp b/source/common/audio/sound/s_sound.cpp index a38dc9eb8..550924854 100644 --- a/source/common/audio/sound/s_sound.cpp +++ b/source/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/source/common/audio/sound/s_soundinternal.h b/source/common/audio/sound/s_soundinternal.h index 58b3a27c1..b3292637f 100644 --- a/source/common/audio/sound/s_soundinternal.h +++ b/source/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/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index b65003418..cc51f039f 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -853,7 +853,6 @@ int RunGame() TexMan.Init([]() {}, [](BuildInfo &) {}); V_InitFonts(); TileFiles.Init(); - sfx_empty = fileSystem.FindFile("engine/dsempty.lmp"); // this must be done outside the sound code because it's initialized late. I_InitSound(); Mus_InitMusic(); S_ParseSndInfo(); diff --git a/source/exhumed/src/sound.cpp b/source/exhumed/src/sound.cpp index 8fe377e09..d30e4307f 100644 --- a/source/exhumed/src/sound.cpp +++ b/source/exhumed/src/sound.cpp @@ -201,7 +201,6 @@ int LoadSound(const char* name) looped[retval] = true; } auto& newsfx = S_sfx.Last(); - newsfx.Clear(); newsfx.name = nname; newsfx.lumpnum = lump; newsfx.NearLimit = 6; @@ -228,7 +227,6 @@ void InitFX(void) auto& S_sfx = soundEngine->GetSounds(); S_sfx.Resize(1); - S_sfx[0].Clear(); S_sfx[0].lumpnum = sfx_empty; for (size_t i = 0; i < kMaxSoundFiles; i++) { StaticSound[i] = LoadSound(SoundFiles[i]); diff --git a/source/games/duke/src/sounds.cpp b/source/games/duke/src/sounds.cpp index 986c7bc2e..3a077945e 100644 --- a/source/games/duke/src/sounds.cpp +++ b/source/games/duke/src/sounds.cpp @@ -185,10 +185,6 @@ int S_DefineSound(unsigned index, const char *filename, int minpitch, int maxpit if (index >= S_sfx.Size()) { S_sfx.Resize(index + 1); - for (; oldindex <= index; oldindex++) - { - S_sfx[oldindex].Clear(); - } } auto sfx = &S_sfx[index]; bool alreadydefined = !sfx->bTentative; diff --git a/source/sw/src/sounds.cpp b/source/sw/src/sounds.cpp index 1477c83fe..cd1340909 100644 --- a/source/sw/src/sounds.cpp +++ b/source/sw/src/sounds.cpp @@ -481,7 +481,6 @@ void InitFX(void) auto &S_sfx = soundEngine->GetSounds(); S_sfx.Resize(countof(voc)); - for (auto& sfx : S_sfx) { sfx.Clear(); sfx.lumpnum = sfx_empty; } for (size_t i = 1; i < countof(voc); i++) { auto& entry = voc[i];