diff options
author | LoRd_MuldeR <mulder2@gmx.de> | 2016-08-02 19:50:26 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2016-08-02 20:00:44 +0200 |
commit | 8ab200fb8adedc98f935a80539f65bd62136e44f (patch) | |
tree | 1c3f3a15785759eca7d62f20069f2dc209cf4a12 /libavfilter | |
parent | 82b84c71b009884c8d041361027718b19922c76d (diff) | |
download | ffmpeg-8ab200fb8adedc98f935a80539f65bd62136e44f.tar.gz |
avfilter/af_dynaudnorm: improve pre-filling code
In order to avoid possible clipping at the very
beginning. Especially apparent when "alternative"
boundary mode is used.
Adopted from original commit by committer.
Diffstat (limited to 'libavfilter')
-rw-r--r-- | libavfilter/af_dynaudnorm.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/libavfilter/af_dynaudnorm.c b/libavfilter/af_dynaudnorm.c index 1dd221ce57..6801209231 100644 --- a/libavfilter/af_dynaudnorm.c +++ b/libavfilter/af_dynaudnorm.c @@ -439,15 +439,12 @@ static void update_gain_history(DynamicAudioNormalizerContext *s, int channel, if (cqueue_empty(s->gain_history_original[channel]) || cqueue_empty(s->gain_history_minimum[channel])) { const int pre_fill_size = s->filter_size / 2; + const double initial_value = s->alt_boundary_mode ? current_gain_factor : 1.0; - s->prev_amplification_factor[channel] = s->alt_boundary_mode ? current_gain_factor : 1.0; + s->prev_amplification_factor[channel] = initial_value; while (cqueue_size(s->gain_history_original[channel]) < pre_fill_size) { - cqueue_enqueue(s->gain_history_original[channel], s->alt_boundary_mode ? current_gain_factor : 1.0); - } - - while (cqueue_size(s->gain_history_minimum[channel]) < pre_fill_size) { - cqueue_enqueue(s->gain_history_minimum[channel], s->alt_boundary_mode ? current_gain_factor : 1.0); + cqueue_enqueue(s->gain_history_original[channel], initial_value); } } @@ -456,6 +453,18 @@ static void update_gain_history(DynamicAudioNormalizerContext *s, int channel, while (cqueue_size(s->gain_history_original[channel]) >= s->filter_size) { double minimum; av_assert0(cqueue_size(s->gain_history_original[channel]) == s->filter_size); + + if (cqueue_empty(s->gain_history_minimum[channel])) { + const int pre_fill_size = s->filter_size / 2; + double initial_value = s->alt_boundary_mode ? cqueue_peek(s->gain_history_original[channel], 0) : 1.0; + int input = pre_fill_size; + + while (cqueue_size(s->gain_history_minimum[channel]) < pre_fill_size) { + initial_value = FFMIN(initial_value, cqueue_peek(s->gain_history_original[channel], ++input)); + cqueue_enqueue(s->gain_history_minimum[channel], initial_value); + } + } + minimum = minimum_filter(s->gain_history_original[channel]); cqueue_enqueue(s->gain_history_minimum[channel], minimum); |