diff options
author | Chris Robinson <[email protected]> | 2016-08-27 06:28:04 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2016-08-27 06:28:04 -0700 |
commit | 3d59021702c2f6ea4dbdf5d2f6231fd945370e27 (patch) | |
tree | 670a7c60b98e2babacf1bee060aaeba89e314b63 /Alc | |
parent | 4b153dade82b0558c96d54828bd2f9f86dc808fd (diff) |
Clamp the maximum mixing gain boost to 16
The combined source and listener gains now can't exceed a multiplier of 16
(~24dB). This is to avoid mixes getting out of control with large volume
boosts, which reduces the effective precision given by floating-point.
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/ALu.c | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -452,13 +452,15 @@ static void CalcNonAttnSourceParams(ALvoice *voice, const struct ALsourceProps * /* Calculate gains */ DryGain = clampf(SourceVolume, MinVolume, MaxVolume); - DryGain *= ATOMIC_LOAD(&props->Direct.Gain, almemory_order_relaxed) * ListenerGain; + DryGain *= ATOMIC_LOAD(&props->Direct.Gain, almemory_order_relaxed) * ListenerGain; + DryGain = minf(DryGain, GAIN_MIX_MAX); DryGainHF = ATOMIC_LOAD(&props->Direct.GainHF, almemory_order_relaxed); DryGainLF = ATOMIC_LOAD(&props->Direct.GainLF, almemory_order_relaxed); for(i = 0;i < NumSends;i++) { - WetGain[i] = clampf(SourceVolume, MinVolume, MaxVolume); - WetGain[i] *= ATOMIC_LOAD(&props->Send[i].Gain, almemory_order_relaxed) * ListenerGain; + WetGain[i] = clampf(SourceVolume, MinVolume, MaxVolume); + WetGain[i] *= ATOMIC_LOAD(&props->Send[i].Gain, almemory_order_relaxed) * ListenerGain; + WetGain[i] = minf(WetGain[i], GAIN_MIX_MAX); WetGainHF[i] = ATOMIC_LOAD(&props->Send[i].GainHF, almemory_order_relaxed); WetGainLF[i] = ATOMIC_LOAD(&props->Send[i].GainLF, almemory_order_relaxed); } @@ -1086,18 +1088,17 @@ static void CalcAttnSourceParams(ALvoice *voice, const struct ALsourceProps *pro } } - /* Clamp to Min/Max Gain */ - DryGain = clampf(DryGain, MinVolume, MaxVolume); - for(i = 0;i < NumSends;i++) - WetGain[i] = clampf(WetGain[i], MinVolume, MaxVolume); - /* Apply gain and frequency filters */ - DryGain *= ATOMIC_LOAD(&props->Direct.Gain, almemory_order_relaxed) * ListenerGain; + DryGain = clampf(DryGain, MinVolume, MaxVolume); + DryGain *= ATOMIC_LOAD(&props->Direct.Gain, almemory_order_relaxed) * ListenerGain; + DryGain = minf(DryGain, GAIN_MIX_MAX); DryGainHF *= ATOMIC_LOAD(&props->Direct.GainHF, almemory_order_relaxed); DryGainLF *= ATOMIC_LOAD(&props->Direct.GainLF, almemory_order_relaxed); for(i = 0;i < NumSends;i++) { - WetGain[i] *= ATOMIC_LOAD(&props->Send[i].Gain, almemory_order_relaxed) * ListenerGain; + WetGain[i] = clampf(WetGain[i], MinVolume, MaxVolume); + WetGain[i] *= ATOMIC_LOAD(&props->Send[i].Gain, almemory_order_relaxed) * ListenerGain; + WetGain[i] = minf(WetGain[i], GAIN_MIX_MAX); WetGainHF[i] *= ATOMIC_LOAD(&props->Send[i].GainHF, almemory_order_relaxed); WetGainLF[i] *= ATOMIC_LOAD(&props->Send[i].GainLF, almemory_order_relaxed); } |