pcm/Normalizer: replace the gain array with a simple prev_gain variable

This commit is contained in:
Max Kellermann 2023-03-13 13:42:50 +01:00
parent c0d38d941a
commit 2ea634c302
2 changed files with 3 additions and 8 deletions

View File

@ -42,7 +42,7 @@ PcmNormalizer::ProcessS16(int16_t *gcc_restrict dest,
int newGain = (1 << 10)*target/peakVal; int newGain = (1 << 10)*target/peakVal;
//! Adjust the gain with inertia from the previous gain value //! Adjust the gain with inertia from the previous gain value
int curGain = gain[pos]; int curGain = prev_gain;
newGain = (curGain*((1 << smooth) - 1) + newGain) >> smooth; newGain = (curGain*((1 << smooth) - 1) + newGain) >> smooth;
//! Make sure it's no more than the maximum gain value //! Make sure it's no more than the maximum gain value
@ -63,7 +63,7 @@ PcmNormalizer::ProcessS16(int16_t *gcc_restrict dest,
} }
//! Record the new gain //! Record the new gain
gain[slot] = newGain; prev_gain = newGain;
if (!ramp) if (!ramp)
ramp = 1; ramp = 1;

View File

@ -21,8 +21,7 @@ class PcmNormalizer {
//! History of the peak values //! History of the peak values
int *const peaks; int *const peaks;
//! History of the gain values int prev_gain = 0;
int *const gain;
std::size_t pos = 0; std::size_t pos = 0;
const std::size_t bufsz; const std::size_t bufsz;
@ -30,14 +29,12 @@ class PcmNormalizer {
public: public:
PcmNormalizer(std::size_t history=400) noexcept PcmNormalizer(std::size_t history=400) noexcept
:peaks(new int[history]{}), :peaks(new int[history]{}),
gain(new int[history]{}),
bufsz(history) bufsz(history)
{ {
} }
~PcmNormalizer() noexcept { ~PcmNormalizer() noexcept {
delete[] peaks; delete[] peaks;
delete[] gain;
} }
//! Process 16-bit signed data //! Process 16-bit signed data
@ -45,5 +42,3 @@ public:
}; };
//! TODO: Compressor_Process_int32, Compressor_Process_float, others as needed //! TODO: Compressor_Process_int32, Compressor_Process_float, others as needed
//! TODO: functions for getting at the peak/gain/clip history buffers (for monitoring)