diff --git a/src/filter/plugins/NormalizeFilterPlugin.cxx b/src/filter/plugins/NormalizeFilterPlugin.cxx index 2b501fb5c..d347bbb43 100644 --- a/src/filter/plugins/NormalizeFilterPlugin.cxx +++ b/src/filter/plugins/NormalizeFilterPlugin.cxx @@ -18,7 +18,7 @@ class NormalizeFilter final : public Filter { public: explicit NormalizeFilter(const AudioFormat &audio_format) - :Filter(audio_format), compressor(Compressor_new(0)) { + :Filter(audio_format), compressor(Compressor_new()) { } ~NormalizeFilter() override { diff --git a/src/pcm/Normalizer.cxx b/src/pcm/Normalizer.cxx index a2eb9c0a4..af59af62a 100644 --- a/src/pcm/Normalizer.cxx +++ b/src/pcm/Normalizer.cxx @@ -4,17 +4,15 @@ #include "Normalizer.hxx" -/*** Default configuration stuff ***/ -#define TARGET 16384 /*!< Target level (on a scale of 0-32767) */ - -#define GAINMAX 32 /*!< The maximum amount to amplify by */ -#define GAINSMOOTH 8 /*!< How much inertia ramping has*/ -#define BUCKETS 400 /*!< How long of a history to use by default */ - struct Compressor { - int target; - int maxgain; - int smooth; + ///! Target level (on a scale of 0-32767) + static constexpr int target = 16384; + + //! The maximum amount to amplify by + static constexpr int maxgain = 32; + + //! How much inertia ramping has + static constexpr int smooth = 8; //! History of the peak values int *peaks; @@ -34,17 +32,10 @@ Compressor_new(unsigned int history) noexcept { auto obj = new Compressor(); - obj->target = TARGET; - obj->maxgain = GAINMAX; - obj->smooth = GAINSMOOTH; - obj->peaks = obj->gain = obj->clipped = nullptr; obj->bufsz = 0; obj->pos = 0; - if (!history) - history = BUCKETS; - obj->bufsz = history; obj->peaks = new int[history]{}; obj->gain = new int[history]{}; diff --git a/src/pcm/Normalizer.hxx b/src/pcm/Normalizer.hxx index 35c5b2f4d..fde6b6507 100644 --- a/src/pcm/Normalizer.hxx +++ b/src/pcm/Normalizer.hxx @@ -10,7 +10,7 @@ struct Compressor; //! Create a new compressor (use history value of 0 for default) struct Compressor * -Compressor_new(unsigned int history) noexcept; +Compressor_new(unsigned int history = 400) noexcept; //! Delete a compressor void diff --git a/test/run_normalize.cxx b/test/run_normalize.cxx index 4145a96d7..9de9437dc 100644 --- a/test/run_normalize.cxx +++ b/test/run_normalize.cxx @@ -35,7 +35,7 @@ try { if (argc > 1) audio_format = ParseAudioFormat(argv[1], false); - compressor = Compressor_new(0); + compressor = Compressor_new(); while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) { Compressor_Process_int16(compressor,