aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2017-09-22 05:42:04 -0700
committerChris Robinson <[email protected]>2017-09-22 05:42:04 -0700
commit369f52a0d76e1be1407441ca0bb67343cffa95f3 (patch)
treeab40abba1c463603f9401a7dc08cf207379b9794
parent9007b7735519b049668ccd0c787ef52a00934386 (diff)
Add an option to ignore the app's speed of sound for reverb decay
-rw-r--r--Alc/ALc.c5
-rw-r--r--Alc/ALu.c12
-rw-r--r--Alc/effects/reverb.c4
-rw-r--r--OpenAL32/Include/alListener.h3
-rw-r--r--OpenAL32/Include/alu.h1
-rw-r--r--docs/env-vars.txt10
6 files changed, 30 insertions, 5 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 7fcac99d..901b5447 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -885,6 +885,10 @@ static void alc_init(void)
if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
ZScale *= -1.0f;
+ str = getenv("__ALSOFT_REVERB_IGNORES_SOUND_SPEED");
+ if(str && (strcasecmp(str, "true") == 0 || strtol(str, NULL, 0) == 1))
+ OverrideReverbSpeedOfSound = AL_TRUE;
+
ret = altss_create(&LocalContext, ReleaseThreadCtx);
assert(ret == althrd_success);
@@ -2540,6 +2544,7 @@ static ALvoid InitContext(ALCcontext *Context)
listener->Params.MetersPerUnit = listener->MetersPerUnit;
listener->Params.DopplerFactor = 1.0f;
listener->Params.SpeedOfSound = SPEEDOFSOUNDMETRESPERSEC;
+ listener->Params.ReverbSpeedOfSound = SPEEDOFSOUNDMETRESPERSEC;
ATOMIC_INIT(&listener->Update, NULL);
ATOMIC_INIT(&listener->FreeList, NULL);
diff --git a/Alc/ALu.c b/Alc/ALu.c
index dcd00c5b..a2ea4811 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -89,6 +89,9 @@ ALfloat ConeScale = 1.0f;
/* Localized Z scalar for mono sources */
ALfloat ZScale = 1.0f;
+/* Force default speed of sound for distance-related reverb decay. */
+ALboolean OverrideReverbSpeedOfSound = AL_FALSE;
+
const aluMatrixf IdentityMatrixf = {{
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f, 0.0f, 0.0f },
@@ -312,6 +315,11 @@ static ALboolean CalcListenerParams(ALCcontext *Context)
Listener->Params.DopplerFactor = props->DopplerFactor;
Listener->Params.SpeedOfSound = props->SpeedOfSound * props->DopplerVelocity;
+ if(OverrideReverbSpeedOfSound)
+ Listener->Params.ReverbSpeedOfSound = SPEEDOFSOUNDMETRESPERSEC;
+ else
+ Listener->Params.ReverbSpeedOfSound = Listener->Params.SpeedOfSound *
+ Listener->Params.MetersPerUnit;
Listener->Params.SourceDistanceModel = props->SourceDistanceModel;
Listener->Params.DistanceModel = props->DistanceModel;
@@ -1105,8 +1113,8 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALvoiceProps *prop
else if(SendSlots[i]->Params.AuxSendAuto)
{
RoomRolloff[i] = SendSlots[i]->Params.RoomRolloff + props->RoomRolloffFactor;
- DecayDistance[i] = SendSlots[i]->Params.DecayTime * Listener->Params.SpeedOfSound *
- Listener->Params.MetersPerUnit;
+ DecayDistance[i] = SendSlots[i]->Params.DecayTime *
+ Listener->Params.ReverbSpeedOfSound;
DecayHFDistance[i] = DecayDistance[i] * SendSlots[i]->Params.DecayHFRatio;
if(SendSlots[i]->Params.DecayHFLimit)
{
diff --git a/Alc/effects/reverb.c b/Alc/effects/reverb.c
index 455a433a..ee7954c4 100644
--- a/Alc/effects/reverb.c
+++ b/Alc/effects/reverb.c
@@ -1362,8 +1362,8 @@ static ALvoid ALreverbState_update(ALreverbState *State, const ALCcontext *Conte
hfRatio = props->Reverb.DecayHFRatio;
if(props->Reverb.DecayHFLimit && props->Reverb.AirAbsorptionGainHF < 1.0f)
hfRatio = CalcLimitedHfRatio(hfRatio, props->Reverb.AirAbsorptionGainHF,
- props->Reverb.DecayTime, Listener->Params.SpeedOfSound *
- Listener->Params.MetersPerUnit);
+ props->Reverb.DecayTime, Listener->Params.ReverbSpeedOfSound
+ );
/* Calculate the LF/HF decay times. */
lfDecayTime = clampf(props->Reverb.DecayTime * props->Reverb.DecayLFRatio,
diff --git a/OpenAL32/Include/alListener.h b/OpenAL32/Include/alListener.h
index f1a92b0d..eb386f7f 100644
--- a/OpenAL32/Include/alListener.h
+++ b/OpenAL32/Include/alListener.h
@@ -50,7 +50,8 @@ typedef struct ALlistener {
ALfloat MetersPerUnit;
ALfloat DopplerFactor;
- ALfloat SpeedOfSound;
+ ALfloat SpeedOfSound; /* in units per sec! */
+ ALfloat ReverbSpeedOfSound; /* in meters per sec! */
ALboolean SourceDistanceModel;
enum DistanceModel DistanceModel;
diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h
index b322995b..1295fee3 100644
--- a/OpenAL32/Include/alu.h
+++ b/OpenAL32/Include/alu.h
@@ -516,6 +516,7 @@ void aluHandleDisconnect(ALCdevice *device);
extern ALfloat ConeScale;
extern ALfloat ZScale;
+extern ALboolean OverrideReverbSpeedOfSound;
#ifdef __cplusplus
}
diff --git a/docs/env-vars.txt b/docs/env-vars.txt
index b2268643..a973ee81 100644
--- a/docs/env-vars.txt
+++ b/docs/env-vars.txt
@@ -79,3 +79,13 @@ which some applications make use of to protect against partial updates. In an
attempt to standardize on that behavior, OpenAL Soft has changed those methods
accordingly. Setting this to "ignore" restores the previous no-op behavior for
applications that interact poorly with the new behavior.
+
+__ALSOFT_REVERB_IGNORES_SOUND_SPEED
+Older versions of OpenAL Soft ignored the app-specified speed of sound when
+calculating distance-related reverb decays and always assumed the default
+343.3m/s. Now, both of the AL_SPEED_OF_SOUND and AL_METERS_PER_UNIT properties
+are taken into account for speed of sound adjustments to have an appropriate
+affect on the reverb decay. Consequently, applications that use reverb but
+don't set these properties properly may find the reverb decay too strong.
+Setting this to "true" or "1" will revert to the old behavior for those apps
+and assume the default speed of sound for reverb.