From 48c8c7daf5b9d516e86ff6d72745f3437e38664a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 13 Mar 2023 12:06:30 +0100 Subject: [PATCH] pcm/Normalizer: move code to ctor/dtor --- src/pcm/Normalizer.cxx | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/pcm/Normalizer.cxx b/src/pcm/Normalizer.cxx index af59af62a..0168c527c 100644 --- a/src/pcm/Normalizer.cxx +++ b/src/pcm/Normalizer.cxx @@ -15,41 +15,41 @@ struct Compressor { static constexpr int smooth = 8; //! History of the peak values - int *peaks; + int *const peaks; //! History of the gain values - int *gain; + int *const gain; //! History of clip amounts - int *clipped; + int *const clipped; - unsigned int pos; - unsigned int bufsz; + unsigned int pos = 0; + const unsigned int bufsz; + + Compressor(unsigned history) noexcept + :peaks(new int[history]{}), + gain(new int[history]{}), + clipped(new int[history]{}), + bufsz(history) + { + } + + ~Compressor() noexcept { + delete[] peaks; + delete[] gain; + delete[] clipped; + } }; struct Compressor * Compressor_new(unsigned int history) noexcept { - auto obj = new Compressor(); - - obj->peaks = obj->gain = obj->clipped = nullptr; - obj->bufsz = 0; - obj->pos = 0; - - obj->bufsz = history; - obj->peaks = new int[history]{}; - obj->gain = new int[history]{}; - obj->clipped = new int[history]{}; - - return obj; + return new Compressor(history); } void Compressor_delete(struct Compressor *obj) noexcept { - delete[] obj->peaks; - delete[] obj->gain; - delete[] obj->clipped; delete obj; }