- make sure that sfxinfo_t is always fully initialized by adding initializer values to all fields.

Let's hope this finally fixes those sound hiccups.
This commit is contained in:
Christoph Oelckers 2020-10-10 09:47:00 +02:00
parent 2237113a77
commit 16fd505f9a
6 changed files with 30 additions and 87 deletions

View file

@ -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;

View file

@ -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<int> 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

View file

@ -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();

View file

@ -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]);

View file

@ -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;

View file

@ -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];