aboutsummaryrefslogtreecommitdiffstats
path: root/alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-09-30 17:29:04 -0700
committerChris Robinson <[email protected]>2019-09-30 17:29:04 -0700
commit4d127a2f9893a9c5b33f92224e0957a827484e07 (patch)
tree10c6302f4c5f05bb3f40f57af0c652f43118277f /alc
parentcf617760b6eb68d38493dd546746880cd5c88b90 (diff)
Avoid infs/nans in the crest detector
It needs to be investigated why the rendered mix sometimes has such large sample values when starting, but the compressor/limiter shouldn't generate NaNs because of it.
Diffstat (limited to 'alc')
-rw-r--r--alc/mastering.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/alc/mastering.cpp b/alc/mastering.cpp
index d0a2f78a..46cc3134 100644
--- a/alc/mastering.cpp
+++ b/alc/mastering.cpp
@@ -44,7 +44,7 @@ using namespace std::placeholders;
*/
ALfloat UpdateSlidingHold(SlidingHold *Hold, const ALuint i, const ALfloat in)
{
- static constexpr ALsizei mask{BUFFERSIZE - 1};
+ static constexpr ALuint mask{BUFFERSIZE - 1};
const ALuint length{Hold->mLength};
ALfloat (&values)[BUFFERSIZE] = Hold->mValues;
ALuint (&expiries)[BUFFERSIZE] = Hold->mExpiries;
@@ -133,7 +133,7 @@ static void CrestDetector(Compressor *Comp, const ALuint SamplesToDo)
auto calc_crest = [&y2_rms,&y2_peak,a_crest](const ALfloat x_abs) noexcept -> ALfloat
{
- ALfloat x2 = maxf(0.000001f, x_abs * x_abs);
+ const ALfloat x2{clampf(x_abs * x_abs, 0.000001f, 1000000.0f)};
y2_peak = maxf(x2, lerp(x2, y2_peak, a_crest));
y2_rms = lerp(x2, y2_rms, a_crest);
@@ -398,6 +398,7 @@ std::unique_ptr<Compressor> CompressorInit(const ALuint NumChans, const ALfloat
{
Comp->mDelay = ::new (static_cast<void*>(Comp.get() + 1)) FloatBufferLine[NumChans];
}
+ std::fill_n(Comp->mDelay, NumChans, FloatBufferLine{});
}
Comp->mCrestCoeff = std::exp(-1.0f / (0.200f * SampleRate)); // 200ms