Skip to content

Commit

Permalink
- removed the limiter flags again and addressed the underlying proble…
Browse files Browse the repository at this point in the history
…m properly.

The real issue is that the number of unattenuated sounds was unchecked and the near limit never kicked in.
To do this properly it is necessary to adjust the limit distance by the attenuation - zero attenuation must mean infinite distance and for high attenuations the distance must be lowered for limiting to work as intended.
The limit for the Doom boss sounds was increased to 4 to compensate for this change.

# Conflicts:
#	src/common/audio/sound/oalsound.cpp
  • Loading branch information
coelckers committed Oct 28, 2020
1 parent 2ebf38c commit d4d187e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
6 changes: 0 additions & 6 deletions src/common/audio/sound/oalsound.cpp
Expand Up @@ -556,7 +556,6 @@ OpenALSoundRenderer::OpenALSoundRenderer()
ALC.EXT_disconnect = !!alcIsExtensionPresent(Device, "ALC_EXT_disconnect");
ALC.SOFT_HRTF = !!alcIsExtensionPresent(Device, "ALC_SOFT_HRTF");
ALC.SOFT_pause_device = !!alcIsExtensionPresent(Device, "ALC_SOFT_pause_device");
ALC.SOFT_output_limiter = !!alcIsExtensionPresent(Device, "ALC_SOFT_output_limiter");

const ALCchar *current = NULL;
if(alcIsExtensionPresent(Device, "ALC_ENUMERATE_ALL_EXT"))
Expand Down Expand Up @@ -593,11 +592,6 @@ OpenALSoundRenderer::OpenALSoundRenderer()
else
attribs.Push(ALC_DONT_CARE_SOFT);
}
if (ALC.SOFT_output_limiter)
{
attribs.Push(ALC_OUTPUT_LIMITER_SOFT);
attribs.Push(ALC_TRUE /* or ALC_FALSE or ALC_DONT_CARE_SOFT */);
}
// Other attribs..?
attribs.Push(0);

Expand Down
10 changes: 6 additions & 4 deletions src/common/audio/sound/s_sound.cpp
Expand Up @@ -463,7 +463,7 @@ FSoundChan *SoundEngine::StartSound(int type, const void *source,
}

// If this sound doesn't like playing near itself, don't play it if that's what would happen.
if (near_limit > 0 && CheckSoundLimit(sfx, pos, near_limit, limit_range, type, source, channel))
if (near_limit > 0 && CheckSoundLimit(sfx, pos, near_limit, limit_range, type, source, channel, attenuation))
{
chanflags |= CHANF_EVICTED;
}
Expand Down Expand Up @@ -675,7 +675,7 @@ void SoundEngine::RestartChannel(FSoundChan *chan)

// If this sound doesn't like playing near itself, don't play it if
// that's what would happen.
if (chan->NearLimit > 0 && CheckSoundLimit(&S_sfx[chan->SoundID], pos, chan->NearLimit, chan->LimitRange, 0, NULL, 0))
if (chan->NearLimit > 0 && CheckSoundLimit(&S_sfx[chan->SoundID], pos, chan->NearLimit, chan->LimitRange, 0, NULL, 0, chan->DistanceScale))
{
return;
}
Expand Down Expand Up @@ -816,7 +816,7 @@ bool SoundEngine::CheckSingular(int sound_id)
//==========================================================================

bool SoundEngine::CheckSoundLimit(sfxinfo_t *sfx, const FVector3 &pos, int near_limit, float limit_range,
int sourcetype, const void *actor, int channel)
int sourcetype, const void *actor, int channel, float attenuation)
{
FSoundChan *chan;
int count;
Expand All @@ -835,7 +835,9 @@ bool SoundEngine::CheckSoundLimit(sfxinfo_t *sfx, const FVector3 &pos, int near_
}

CalcPosVel(chan, &chanorigin, NULL);
if ((chanorigin - pos).LengthSquared() <= limit_range)
// scale the limit distance with the attenuation. An attenuation of 0 means the limit distance is infinite and all sounds within the level are inside the limit.
float attn = std::min(chan->DistanceScale, attenuation);
if (attn <= 0 || (chanorigin - pos).LengthSquared() <= limit_range / attn)
{
count++;
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/audio/sound/s_soundinternal.h
Expand Up @@ -234,7 +234,7 @@ class SoundEngine
bool CheckSingular(int sound_id);
virtual TArray<uint8_t> ReadSound(int lumpnum) = 0;
protected:
virtual bool CheckSoundLimit(sfxinfo_t* sfx, const FVector3& pos, int near_limit, float limit_range, int sourcetype, const void* actor, int channel);
virtual bool CheckSoundLimit(sfxinfo_t* sfx, const FVector3& pos, int near_limit, float limit_range, int sourcetype, const void* actor, int channel, float attenuation);
virtual FSoundID ResolveSound(const void *ent, int srctype, FSoundID soundid, float &attenuation);

public:
Expand Down
4 changes: 2 additions & 2 deletions src/sound/s_doomsound.cpp
Expand Up @@ -95,10 +95,10 @@ class DoomSoundEngine : public SoundEngine
S_sfx[ndx].UserData[0] = 0;
return ndx;
}
bool CheckSoundLimit(sfxinfo_t* sfx, const FVector3& pos, int near_limit, float limit_range, int sourcetype, const void* actor, int channel) override
bool CheckSoundLimit(sfxinfo_t* sfx, const FVector3& pos, int near_limit, float limit_range, int sourcetype, const void* actor, int channel, float attenuation) override
{
if (sourcetype != SOURCE_Actor) actor = nullptr; //ZDoom did this.
return SoundEngine::CheckSoundLimit(sfx, pos, near_limit, limit_range, sourcetype, actor, channel);
return SoundEngine::CheckSoundLimit(sfx, pos, near_limit, limit_range, sourcetype, actor, channel, attenuation);
}


Expand Down
5 changes: 5 additions & 0 deletions wadsrc/static/filter/game-doomchex/sndinfo.txt
Expand Up @@ -321,6 +321,9 @@ spider/attack dsshotgn
spider/death dsspidth
spider/walk dsmetal

$limit spider/sight 4
$limit spider/death 4

// Arachnotron

baby/sight dsbspsit
Expand All @@ -341,6 +344,8 @@ cyber/pain dsdmpain
cyber/death dscybdth
cyber/hoof dshoof

$limit cyber/sight 4
$limit cyber/death 4
// Pain Elemental

pain/sight dspesit
Expand Down

0 comments on commit d4d187e

Please sign in to comment.