From fcc9a98cad22fe6a40e619b1ca89343af3f00896 Mon Sep 17 00:00:00 2001 From: Max Kellermann <max.kellermann@gmail.com> Date: Mon, 13 Mar 2023 12:34:02 +0100 Subject: [PATCH] pcm/Normalizer: use PcmClamp() --- src/pcm/Normalizer.cxx | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/pcm/Normalizer.cxx b/src/pcm/Normalizer.cxx index 2b3f2af82..ed275af64 100644 --- a/src/pcm/Normalizer.cxx +++ b/src/pcm/Normalizer.cxx @@ -3,10 +3,15 @@ // Based on AudioCompress (c)2007 busybee (http://beesbuzz.biz/ #include "Normalizer.hxx" +#include "Clamp.hxx" +#include "SampleFormat.hxx" +#include "Traits.hxx" void PcmNormalizer::ProcessS16(int16_t *audio, std::size_t count) noexcept { + constexpr SampleFormat format = SampleFormat::S16; + const int slot = (pos + 1) % bufsz; int peakVal = 1, peakPos = 0; @@ -64,18 +69,8 @@ PcmNormalizer::ProcessS16(int16_t *audio, std::size_t count) noexcept const int delta = (newGain - curGain) / (int)ramp; for (std::size_t i = 0; i < count; i++) { - int sample; - //! Amplify the sample - sample = audio[i] * curGain >> 10; - if (sample < -32768) - { - sample = -32768; - } else if (sample > 32767) - { - sample = 32767; - } - audio[i] = sample; + audio[i] = PcmClamp<format>(audio[i] * curGain >> 10); //! Adjust the gain if (i < ramp)