From bc51bc29337962f6ece3c153af8e65d4c0057ae3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 13 Mar 2023 13:52:43 +0100 Subject: [PATCH] pcm/Normalizer: add method Reset() --- src/filter/plugins/NormalizeFilterPlugin.cxx | 4 ++++ src/pcm/Normalizer.cxx | 10 ++++++++++ src/pcm/Normalizer.hxx | 2 ++ 3 files changed, 16 insertions(+) diff --git a/src/filter/plugins/NormalizeFilterPlugin.cxx b/src/filter/plugins/NormalizeFilterPlugin.cxx index e87ab637a..51e239e65 100644 --- a/src/filter/plugins/NormalizeFilterPlugin.cxx +++ b/src/filter/plugins/NormalizeFilterPlugin.cxx @@ -24,6 +24,10 @@ public: NormalizeFilter &operator=(const NormalizeFilter &) = delete; /* virtual methods from class Filter */ + void Reset() noexcept override { + normalizer.Reset(); + } + std::span FilterPCM(std::span src) override; }; diff --git a/src/pcm/Normalizer.cxx b/src/pcm/Normalizer.cxx index 78c04d2fa..b5757adce 100644 --- a/src/pcm/Normalizer.cxx +++ b/src/pcm/Normalizer.cxx @@ -8,6 +8,16 @@ #include "Traits.hxx" #include "util/Compiler.h" +#include // for std::fill_n() + +void +PcmNormalizer::Reset() noexcept +{ + prev_gain = 0; + pos = 0; + std::fill_n(peaks, bufsz, 0); +} + void PcmNormalizer::ProcessS16(int16_t *gcc_restrict dest, const std::span src) noexcept diff --git a/src/pcm/Normalizer.hxx b/src/pcm/Normalizer.hxx index 155f16d18..911dd5d60 100644 --- a/src/pcm/Normalizer.hxx +++ b/src/pcm/Normalizer.hxx @@ -37,6 +37,8 @@ public: delete[] peaks; } + void Reset() noexcept; + //! Process 16-bit signed data void ProcessS16(int16_t *dest, std::span src) noexcept; };