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.
This commit is contained in:
LoRd_MuldeR 2016-08-02 19:50:26 +02:00 committed by Paul B Mahol
parent 82b84c71b0
commit 8ab200fb8a

View File

@ -439,15 +439,12 @@ static void update_gain_history(DynamicAudioNormalizerContext *s, int channel,
if (cqueue_empty(s->gain_history_original[channel]) || if (cqueue_empty(s->gain_history_original[channel]) ||
cqueue_empty(s->gain_history_minimum[channel])) { cqueue_empty(s->gain_history_minimum[channel])) {
const int pre_fill_size = s->filter_size / 2; 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) { 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); cqueue_enqueue(s->gain_history_original[channel], initial_value);
}
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);
} }
} }
@ -456,6 +453,18 @@ static void update_gain_history(DynamicAudioNormalizerContext *s, int channel,
while (cqueue_size(s->gain_history_original[channel]) >= s->filter_size) { while (cqueue_size(s->gain_history_original[channel]) >= s->filter_size) {
double minimum; double minimum;
av_assert0(cqueue_size(s->gain_history_original[channel]) == s->filter_size); 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]); minimum = minimum_filter(s->gain_history_original[channel]);
cqueue_enqueue(s->gain_history_minimum[channel], minimum); cqueue_enqueue(s->gain_history_minimum[channel], minimum);