From d2f2dde2e1c72e45bca14510763c4b38469ea56d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 13 Mar 2023 12:07:40 +0100 Subject: [PATCH] pcm/Normalizer: eliminate struct CompressorConfig --- src/pcm/Normalizer.cxx | 28 +++++++++++----------------- src/pcm/Normalizer.hxx | 11 ----------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/pcm/Normalizer.cxx b/src/pcm/Normalizer.cxx index df559ab3e..a2eb9c0a4 100644 --- a/src/pcm/Normalizer.cxx +++ b/src/pcm/Normalizer.cxx @@ -12,8 +12,9 @@ #define BUCKETS 400 /*!< How long of a history to use by default */ struct Compressor { - //! The compressor's preferences - struct CompressorConfig prefs; + int target; + int maxgain; + int smooth; //! History of the peak values int *peaks; @@ -33,9 +34,9 @@ Compressor_new(unsigned int history) noexcept { auto obj = new Compressor(); - obj->prefs.target = TARGET; - obj->prefs.maxgain = GAINMAX; - obj->prefs.smooth = GAINSMOOTH; + obj->target = TARGET; + obj->maxgain = GAINMAX; + obj->smooth = GAINSMOOTH; obj->peaks = obj->gain = obj->clipped = nullptr; obj->bufsz = 0; @@ -61,17 +62,10 @@ Compressor_delete(struct Compressor *obj) noexcept delete obj; } -struct CompressorConfig * -Compressor_getConfig(struct Compressor *obj) noexcept -{ - return &obj->prefs; -} - void Compressor_Process_int16(struct Compressor *obj, int16_t *audio, unsigned int count) noexcept { - struct CompressorConfig *prefs = Compressor_getConfig(obj); int16_t *ap; unsigned int i; int *peaks = obj->peaks; @@ -109,15 +103,15 @@ Compressor_Process_int16(struct Compressor *obj, int16_t *audio, } //! Determine target gain - newGain = (1 << 10)*prefs->target/peakVal; + newGain = (1 << 10)*obj->target/peakVal; //! Adjust the gain with inertia from the previous gain value - newGain = (curGain*((1 << prefs->smooth) - 1) + newGain) - >> prefs->smooth; + newGain = (curGain*((1 << obj->smooth) - 1) + newGain) + >> obj->smooth; //! Make sure it's no more than the maximum gain value - if (newGain > (prefs->maxgain << 10)) - newGain = prefs->maxgain << 10; + if (newGain > (obj->maxgain << 10)) + newGain = obj->maxgain << 10; //! Make sure it's no less than 1:1 if (newGain < (1 << 10)) diff --git a/src/pcm/Normalizer.hxx b/src/pcm/Normalizer.hxx index e5450665e..35c5b2f4d 100644 --- a/src/pcm/Normalizer.hxx +++ b/src/pcm/Normalizer.hxx @@ -6,13 +6,6 @@ #include -//! Configuration values for the compressor object -struct CompressorConfig { - int target; - int maxgain; - int smooth; -}; - struct Compressor; //! Create a new compressor (use history value of 0 for default) @@ -23,10 +16,6 @@ Compressor_new(unsigned int history) noexcept; void Compressor_delete(struct Compressor *) noexcept; -//! Get the configuration for a compressor -struct CompressorConfig * -Compressor_getConfig(struct Compressor *) noexcept; - //! Process 16-bit signed data void Compressor_Process_int16(struct Compressor *, int16_t *data, unsigned int count) noexcept;