From 4d127a2f9893a9c5b33f92224e0957a827484e07 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 30 Sep 2019 17:29:04 -0700 Subject: 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. --- alc/mastering.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'alc/mastering.cpp') 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 CompressorInit(const ALuint NumChans, const ALfloat { Comp->mDelay = ::new (static_cast(Comp.get() + 1)) FloatBufferLine[NumChans]; } + std::fill_n(Comp->mDelay, NumChans, FloatBufferLine{}); } Comp->mCrestCoeff = std::exp(-1.0f / (0.200f * SampleRate)); // 200ms -- cgit v1.2.3