Added $PitchSet <logical name> <float> for SNDINFO.

- Sets the direct pitch of the sound to the specific float. Default is 0.0, meaning do not set a specific pitch. Regular pitch is 1.0.
- Only works for direct sound definitions.
- Overrides $PitchShift unless value is <= 0.0
- Overridden by A_StartSound's pitch parameter if the value > 0.0.
This commit is contained in:
Major Cooke 2020-07-23 14:41:55 -05:00 committed by drfrag
parent f02d0d44d9
commit 09f5d1b666
3 changed files with 22 additions and 3 deletions

View file

@ -131,6 +131,7 @@ enum SICommands
SI_MusicAlias,
SI_EDFOverride,
SI_Attenuation,
SI_PitchSet,
};
// Blood was a cool game. If Monolith ever releases the source for it,
@ -226,6 +227,7 @@ static const char *SICommandStrings[] =
"$musicalias",
"$edfoverride",
"$attenuation",
"$pitchset",
NULL
};
@ -1076,6 +1078,17 @@ static void S_AddSNDINFO (int lump)
}
break;
case SI_PitchSet: {
// $pitchset <logical name> <pitch amount as float>
int sfx;
sc.MustGetString();
sfx = soundEngine->FindSoundTentative(sc.String);
sc.MustGetFloat();
S_sfx[sfx].DefPitch = (float)sc.Float;
}
break;
case SI_PitchShiftRange:
// $pitchshiftrange <pitch shift amount>
sc.MustGetNumber ();

View file

@ -410,6 +410,7 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source,
// the referenced sound so some additional checks are required
int near_limit = sfx->NearLimit;
float limit_range = sfx->LimitRange;
float defpitch = sfx->DefPitch;
auto pitchmask = sfx->PitchMask;
rolloff = &sfx->Rolloff;
@ -425,6 +426,7 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source,
{
near_limit = newsfx->NearLimit;
limit_range = newsfx->LimitRange;
defpitch = newsfx->DefPitch;
}
if (rolloff->MinDistance == 0)
{
@ -532,7 +534,7 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source,
return NULL;
}
// Vary the sfx pitches.
// Vary the sfx pitches. Overridden by $PitchSet and A_StartSound.
if (pitchmask != 0)
{
pitch = DEFAULT_PITCH - (rand() & pitchmask) + (rand() & pitchmask);
@ -603,9 +605,11 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source,
{
chan->Source = source;
}
if (spitch > 0.0)
if (spitch > 0.0) // A_StartSound has top priority over all others.
SetPitch(chan, spitch);
else if (defpitch > 0.0) // $PitchSet overrides $PitchShift
SetPitch(chan, defpitch);
}
return chan;
@ -1501,6 +1505,7 @@ int SoundEngine::AddSoundLump(const char* logicalname, int lump, int CurrentPitc
newsfx.Volume = 1;
newsfx.Attenuation = 1;
newsfx.PitchMask = CurrentPitchMask;
newsfx.DefPitch = 0.0;
newsfx.NearLimit = nearlimit;
newsfx.LimitRange = 256 * 256;
newsfx.bRandomHeader = false;

View file

@ -29,6 +29,7 @@ struct sfxinfo_t
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.
unsigned bRandomHeader:1;
unsigned bLoadRAW:1;