diff options
author | Chris Robinson <[email protected]> | 2023-09-05 12:05:08 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-09-05 12:05:08 -0700 |
commit | a1841b46a086530174177cb5f3e2cdd1eb1848a2 (patch) | |
tree | e22ea383e8f2e0dfc45f28969d6f780e028ac5c5 /alc | |
parent | 1351a2a7d98cf288e44773c3cb4ff67929b3e6fc (diff) |
Include the early and late reverb gain for the decay fade timer
Diffstat (limited to 'alc')
-rw-r--r-- | alc/effects/reverb.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp index 330c404d..a4155792 100644 --- a/alc/effects/reverb.cpp +++ b/alc/effects/reverb.cpp @@ -1244,9 +1244,36 @@ void ReverbState::update(const ContextBase *Context, const EffectSlot *Slot, props->Reverb.DecayTime, hfDecayTime, lf0norm, hf0norm, frequency); } - const float decaySamples{(props->Reverb.ReflectionsDelay + props->Reverb.LateReverbDelay - + props->Reverb.DecayTime) * frequency}; - pipeline.mFadeSampleCount = static_cast<size_t>(minf(decaySamples, 1'000'000.0f)); + /* Calculate the gain at the start of the late reverb stage, and the gain + * difference from the decay target (0.001, or -60dB). + */ + const float decayBase{props->Reverb.ReflectionsGain * props->Reverb.LateReverbGain}; + const float decayDiff{ReverbDecayGain / decayBase}; + + if(decayDiff < 1.0f) + { + /* Given the DecayTime (the amount of time for the late reverb to decay + * by -60dB), calculate the time to decay to -60dB from the start of + * the late reverb. + */ + const float diffTime{std::log10(decayDiff)*(20.0f / -60.0f) * props->Reverb.DecayTime}; + + const float decaySamples{(props->Reverb.ReflectionsDelay + props->Reverb.LateReverbDelay + + diffTime) * frequency}; + /* Limit to 100,000 samples (a touch over 2 seconds at 48khz) to + * avoid excessive double-processing. + */ + pipeline.mFadeSampleCount = static_cast<size_t>(minf(decaySamples, 100'000.0f)); + } + else + { + /* Otherwise, if the late reverb already starts at -60dB or less, only + * include the time to get to the late reverb. + */ + const float decaySamples{(props->Reverb.ReflectionsDelay + props->Reverb.LateReverbDelay) + * frequency}; + pipeline.mFadeSampleCount = static_cast<size_t>(minf(decaySamples, 100'000.0f)); + } } |