From e0b6df5081fc609ccb49c3e8eb128a231f739554 Mon Sep 17 00:00:00 2001 From: jatin Date: Wed, 14 Feb 2024 14:29:19 -0800 Subject: [PATCH] Use ScopedValue for level detectors --- .../Compressor/chowdsp_LevelDetectorImpls.h | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/modules/dsp/chowdsp_compressor/Compressor/chowdsp_LevelDetectorImpls.h b/modules/dsp/chowdsp_compressor/Compressor/chowdsp_LevelDetectorImpls.h index 398dcefcf..44c903a94 100644 --- a/modules/dsp/chowdsp_compressor/Compressor/chowdsp_LevelDetectorImpls.h +++ b/modules/dsp/chowdsp_compressor/Compressor/chowdsp_LevelDetectorImpls.h @@ -28,12 +28,13 @@ struct PeakDetector { for (auto [ch, data] : buffer_iters::channels (buffer)) { + ScopedValue _z { z[ch] }; for (auto& x : data) { const auto abs_x = std::abs (x); - const auto b0 = abs_x > z[ch] ? attackCoeffs.b0 : releaseCoeffs.b0; - z[ch] += b0 * (abs_x - z[ch]); - x = z[ch]; + const auto b0 = abs_x > _z.get() ? attackCoeffs.b0 : releaseCoeffs.b0; + _z.get() += b0 * (abs_x - _z.get()); + x = _z.get(); } } } @@ -47,13 +48,14 @@ struct PeakRtTDetector { for (auto [ch, data] : buffer_iters::channels (buffer)) { + ScopedValue _z { z[ch] }; for (auto& x : data) { const auto abs_x = std::abs (x); - const auto b0 = abs_x > z[ch] ? attackCoeffs.b0 : releaseCoeffs.b0; - const auto x_eff = abs_x > z[ch] ? abs_x : thresholdGain; - z[ch] += b0 * (x_eff - z[ch]); - x = z[ch]; + const auto b0 = abs_x > _z.get() ? attackCoeffs.b0 : releaseCoeffs.b0; + const auto x_eff = abs_x > _z.get() ? abs_x : thresholdGain; + _z.get() += b0 * (x_eff - _z.get()); + x = _z.get(); } } } @@ -67,12 +69,13 @@ struct RMSDetector { for (auto [ch, data] : buffer_iters::channels (buffer)) { + ScopedValue _z { z[ch] }; for (auto& x : data) { const auto sq_x = x * x; - const auto& coeffs = sq_x > z[ch] ? attackCoeffs : releaseCoeffs; - z[ch] = coeffs.a1 * z[ch] + coeffs.b0 * sq_x; - x = z[ch]; + const auto& coeffs = sq_x > _z.get() ? attackCoeffs : releaseCoeffs; + _z.get() = coeffs.a1 * _z.get() + coeffs.b0 * sq_x; + x = _z.get(); } }