2 * Dynamic Audio Normalizer
3 * Copyright (c) 2015 LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 * Dynamic Audio Normalizer
29 #include "libavutil/avassert.h"
30 #include "libavutil/opt.h"
32 #define FF_BUFQUEUE_SIZE 302
33 #include "libavfilter/bufferqueue.h"
40 typedef struct cqueue {
47 typedef struct DynamicAudioNormalizerContext {
50 struct FFBufQueue queue;
57 int alt_boundary_mode;
60 double max_amplification;
62 double compress_factor;
63 double *prev_amplification_factor;
64 double *dc_correction_value;
65 double *compress_threshold;
66 double *fade_factors[2];
74 cqueue **gain_history_original;
75 cqueue **gain_history_minimum;
76 cqueue **gain_history_smoothed;
79 } DynamicAudioNormalizerContext;
81 #define OFFSET(x) offsetof(DynamicAudioNormalizerContext, x)
82 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
84 static const AVOption dynaudnorm_options[] = {
85 { "framelen", "set the frame length in msec", OFFSET(frame_len_msec), AV_OPT_TYPE_INT, {.i64 = 500}, 10, 8000, FLAGS },
86 { "f", "set the frame length in msec", OFFSET(frame_len_msec), AV_OPT_TYPE_INT, {.i64 = 500}, 10, 8000, FLAGS },
87 { "gausssize", "set the filter size", OFFSET(filter_size), AV_OPT_TYPE_INT, {.i64 = 31}, 3, 301, FLAGS },
88 { "g", "set the filter size", OFFSET(filter_size), AV_OPT_TYPE_INT, {.i64 = 31}, 3, 301, FLAGS },
89 { "peak", "set the peak value", OFFSET(peak_value), AV_OPT_TYPE_DOUBLE, {.dbl = 0.95}, 0.0, 1.0, FLAGS },
90 { "p", "set the peak value", OFFSET(peak_value), AV_OPT_TYPE_DOUBLE, {.dbl = 0.95}, 0.0, 1.0, FLAGS },
91 { "maxgain", "set the max amplification", OFFSET(max_amplification), AV_OPT_TYPE_DOUBLE, {.dbl = 10.0}, 1.0, 100.0, FLAGS },
92 { "m", "set the max amplification", OFFSET(max_amplification), AV_OPT_TYPE_DOUBLE, {.dbl = 10.0}, 1.0, 100.0, FLAGS },
93 { "targetrms", "set the target RMS", OFFSET(target_rms), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 1.0, FLAGS },
94 { "r", "set the target RMS", OFFSET(target_rms), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 1.0, FLAGS },
95 { "coupling", "set channel coupling", OFFSET(channels_coupled), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
96 { "n", "set channel coupling", OFFSET(channels_coupled), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
97 { "correctdc", "set DC correction", OFFSET(dc_correction), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
98 { "c", "set DC correction", OFFSET(dc_correction), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
99 { "altboundary", "set alternative boundary mode", OFFSET(alt_boundary_mode), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
100 { "b", "set alternative boundary mode", OFFSET(alt_boundary_mode), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
101 { "compress", "set the compress factor", OFFSET(compress_factor), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 30.0, FLAGS },
102 { "s", "set the compress factor", OFFSET(compress_factor), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 30.0, FLAGS },
106 AVFILTER_DEFINE_CLASS(dynaudnorm);
108 static av_cold int init(AVFilterContext *ctx)
110 DynamicAudioNormalizerContext *s = ctx->priv;
112 if (!(s->filter_size & 1)) {
113 av_log(ctx, AV_LOG_ERROR, "filter size %d is invalid. Must be an odd value.\n", s->filter_size);
114 return AVERROR(EINVAL);
120 static int query_formats(AVFilterContext *ctx)
122 AVFilterFormats *formats;
123 AVFilterChannelLayouts *layouts;
124 static const enum AVSampleFormat sample_fmts[] = {
130 layouts = ff_all_channel_counts();
132 return AVERROR(ENOMEM);
133 ret = ff_set_common_channel_layouts(ctx, layouts);
137 formats = ff_make_format_list(sample_fmts);
139 return AVERROR(ENOMEM);
140 ret = ff_set_common_formats(ctx, formats);
144 formats = ff_all_samplerates();
146 return AVERROR(ENOMEM);
147 return ff_set_common_samplerates(ctx, formats);
150 static inline int frame_size(int sample_rate, int frame_len_msec)
152 const int frame_size = lrint((double)sample_rate * (frame_len_msec / 1000.0));
153 return frame_size + (frame_size % 2);
156 static void precalculate_fade_factors(double *fade_factors[2], int frame_len)
158 const double step_size = 1.0 / frame_len;
161 for (pos = 0; pos < frame_len; pos++) {
162 fade_factors[0][pos] = 1.0 - (step_size * (pos + 1.0));
163 fade_factors[1][pos] = 1.0 - fade_factors[0][pos];
167 static cqueue *cqueue_create(int size)
171 q = av_malloc(sizeof(cqueue));
179 q->elements = av_malloc_array(size, sizeof(double));
188 static void cqueue_free(cqueue *q)
191 av_free(q->elements);
195 static int cqueue_size(cqueue *q)
197 return q->nb_elements;
200 static int cqueue_empty(cqueue *q)
202 return !q->nb_elements;
205 static int cqueue_enqueue(cqueue *q, double element)
209 av_assert2(q->nb_elements != q->size);
211 i = (q->first + q->nb_elements) % q->size;
212 q->elements[i] = element;
218 static double cqueue_peek(cqueue *q, int index)
220 av_assert2(index < q->nb_elements);
221 return q->elements[(q->first + index) % q->size];
224 static int cqueue_dequeue(cqueue *q, double *element)
226 av_assert2(!cqueue_empty(q));
228 *element = q->elements[q->first];
229 q->first = (q->first + 1) % q->size;
235 static int cqueue_pop(cqueue *q)
237 av_assert2(!cqueue_empty(q));
239 q->first = (q->first + 1) % q->size;
245 static void init_gaussian_filter(DynamicAudioNormalizerContext *s)
247 double total_weight = 0.0;
248 const double sigma = (((s->filter_size / 2.0) - 1.0) / 3.0) + (1.0 / 3.0);
252 // Pre-compute constants
253 const int offset = s->filter_size / 2;
254 const double c1 = 1.0 / (sigma * sqrt(2.0 * M_PI));
255 const double c2 = 2.0 * sigma * sigma;
258 for (i = 0; i < s->filter_size; i++) {
259 const int x = i - offset;
261 s->weights[i] = c1 * exp(-x * x / c2);
262 total_weight += s->weights[i];
266 adjust = 1.0 / total_weight;
267 for (i = 0; i < s->filter_size; i++) {
268 s->weights[i] *= adjust;
272 static av_cold void uninit(AVFilterContext *ctx)
274 DynamicAudioNormalizerContext *s = ctx->priv;
277 av_freep(&s->prev_amplification_factor);
278 av_freep(&s->dc_correction_value);
279 av_freep(&s->compress_threshold);
280 av_freep(&s->fade_factors[0]);
281 av_freep(&s->fade_factors[1]);
283 for (c = 0; c < s->channels; c++) {
284 if (s->gain_history_original)
285 cqueue_free(s->gain_history_original[c]);
286 if (s->gain_history_minimum)
287 cqueue_free(s->gain_history_minimum[c]);
288 if (s->gain_history_smoothed)
289 cqueue_free(s->gain_history_smoothed[c]);
292 av_freep(&s->gain_history_original);
293 av_freep(&s->gain_history_minimum);
294 av_freep(&s->gain_history_smoothed);
296 cqueue_free(s->is_enabled);
297 s->is_enabled = NULL;
299 av_freep(&s->weights);
301 ff_bufqueue_discard_all(&s->queue);
304 static int config_input(AVFilterLink *inlink)
306 AVFilterContext *ctx = inlink->dst;
307 DynamicAudioNormalizerContext *s = ctx->priv;
312 s->frame_len = frame_size(inlink->sample_rate, s->frame_len_msec);
313 av_log(ctx, AV_LOG_DEBUG, "frame len %d\n", s->frame_len);
315 s->fade_factors[0] = av_malloc_array(s->frame_len, sizeof(*s->fade_factors[0]));
316 s->fade_factors[1] = av_malloc_array(s->frame_len, sizeof(*s->fade_factors[1]));
318 s->prev_amplification_factor = av_malloc_array(inlink->channels, sizeof(*s->prev_amplification_factor));
319 s->dc_correction_value = av_calloc(inlink->channels, sizeof(*s->dc_correction_value));
320 s->compress_threshold = av_calloc(inlink->channels, sizeof(*s->compress_threshold));
321 s->gain_history_original = av_calloc(inlink->channels, sizeof(*s->gain_history_original));
322 s->gain_history_minimum = av_calloc(inlink->channels, sizeof(*s->gain_history_minimum));
323 s->gain_history_smoothed = av_calloc(inlink->channels, sizeof(*s->gain_history_smoothed));
324 s->weights = av_malloc_array(s->filter_size, sizeof(*s->weights));
325 s->is_enabled = cqueue_create(s->filter_size);
326 if (!s->prev_amplification_factor || !s->dc_correction_value ||
327 !s->compress_threshold || !s->fade_factors[0] || !s->fade_factors[1] ||
328 !s->gain_history_original || !s->gain_history_minimum ||
329 !s->gain_history_smoothed || !s->is_enabled || !s->weights)
330 return AVERROR(ENOMEM);
332 for (c = 0; c < inlink->channels; c++) {
333 s->prev_amplification_factor[c] = 1.0;
335 s->gain_history_original[c] = cqueue_create(s->filter_size);
336 s->gain_history_minimum[c] = cqueue_create(s->filter_size);
337 s->gain_history_smoothed[c] = cqueue_create(s->filter_size);
339 if (!s->gain_history_original[c] || !s->gain_history_minimum[c] ||
340 !s->gain_history_smoothed[c])
341 return AVERROR(ENOMEM);
344 precalculate_fade_factors(s->fade_factors, s->frame_len);
345 init_gaussian_filter(s);
347 s->channels = inlink->channels;
348 s->delay = s->filter_size;
353 static inline double fade(double prev, double next, int pos,
354 double *fade_factors[2])
356 return fade_factors[0][pos] * prev + fade_factors[1][pos] * next;
359 static inline double pow_2(const double value)
361 return value * value;
364 static inline double bound(const double threshold, const double val)
366 const double CONST = 0.8862269254527580136490837416705725913987747280611935; //sqrt(PI) / 2.0
367 return erf(CONST * (val / threshold)) * threshold;
370 static double find_peak_magnitude(AVFrame *frame, int channel)
372 double max = DBL_EPSILON;
376 for (c = 0; c < frame->channels; c++) {
377 double *data_ptr = (double *)frame->extended_data[c];
379 for (i = 0; i < frame->nb_samples; i++)
380 max = FFMAX(max, fabs(data_ptr[i]));
383 double *data_ptr = (double *)frame->extended_data[channel];
385 for (i = 0; i < frame->nb_samples; i++)
386 max = FFMAX(max, fabs(data_ptr[i]));
392 static double compute_frame_rms(AVFrame *frame, int channel)
394 double rms_value = 0.0;
398 for (c = 0; c < frame->channels; c++) {
399 const double *data_ptr = (double *)frame->extended_data[c];
401 for (i = 0; i < frame->nb_samples; i++) {
402 rms_value += pow_2(data_ptr[i]);
406 rms_value /= frame->nb_samples * frame->channels;
408 const double *data_ptr = (double *)frame->extended_data[channel];
409 for (i = 0; i < frame->nb_samples; i++) {
410 rms_value += pow_2(data_ptr[i]);
413 rms_value /= frame->nb_samples;
416 return FFMAX(sqrt(rms_value), DBL_EPSILON);
419 static double get_max_local_gain(DynamicAudioNormalizerContext *s, AVFrame *frame,
422 const double maximum_gain = s->peak_value / find_peak_magnitude(frame, channel);
423 const double rms_gain = s->target_rms > DBL_EPSILON ? (s->target_rms / compute_frame_rms(frame, channel)) : DBL_MAX;
424 return bound(s->max_amplification, FFMIN(maximum_gain, rms_gain));
427 static double minimum_filter(cqueue *q)
429 double min = DBL_MAX;
432 for (i = 0; i < cqueue_size(q); i++) {
433 min = FFMIN(min, cqueue_peek(q, i));
439 static double gaussian_filter(DynamicAudioNormalizerContext *s, cqueue *q)
444 for (i = 0; i < cqueue_size(q); i++) {
445 result += cqueue_peek(q, i) * s->weights[i];
451 static void update_gain_history(DynamicAudioNormalizerContext *s, int channel,
452 double current_gain_factor)
454 if (cqueue_empty(s->gain_history_original[channel]) ||
455 cqueue_empty(s->gain_history_minimum[channel])) {
456 const int pre_fill_size = s->filter_size / 2;
457 const double initial_value = s->alt_boundary_mode ? current_gain_factor : 1.0;
459 s->prev_amplification_factor[channel] = initial_value;
461 while (cqueue_size(s->gain_history_original[channel]) < pre_fill_size) {
462 cqueue_enqueue(s->gain_history_original[channel], initial_value);
466 cqueue_enqueue(s->gain_history_original[channel], current_gain_factor);
468 while (cqueue_size(s->gain_history_original[channel]) >= s->filter_size) {
470 av_assert0(cqueue_size(s->gain_history_original[channel]) == s->filter_size);
472 if (cqueue_empty(s->gain_history_minimum[channel])) {
473 const int pre_fill_size = s->filter_size / 2;
474 double initial_value = s->alt_boundary_mode ? cqueue_peek(s->gain_history_original[channel], 0) : 1.0;
475 int input = pre_fill_size;
477 while (cqueue_size(s->gain_history_minimum[channel]) < pre_fill_size) {
479 initial_value = FFMIN(initial_value, cqueue_peek(s->gain_history_original[channel], input));
480 cqueue_enqueue(s->gain_history_minimum[channel], initial_value);
484 minimum = minimum_filter(s->gain_history_original[channel]);
486 cqueue_enqueue(s->gain_history_minimum[channel], minimum);
488 cqueue_pop(s->gain_history_original[channel]);
491 while (cqueue_size(s->gain_history_minimum[channel]) >= s->filter_size) {
493 av_assert0(cqueue_size(s->gain_history_minimum[channel]) == s->filter_size);
494 smoothed = gaussian_filter(s, s->gain_history_minimum[channel]);
496 cqueue_enqueue(s->gain_history_smoothed[channel], smoothed);
498 cqueue_pop(s->gain_history_minimum[channel]);
502 static inline double update_value(double new, double old, double aggressiveness)
504 av_assert0((aggressiveness >= 0.0) && (aggressiveness <= 1.0));
505 return aggressiveness * new + (1.0 - aggressiveness) * old;
508 static void perform_dc_correction(DynamicAudioNormalizerContext *s, AVFrame *frame)
510 const double diff = 1.0 / frame->nb_samples;
511 int is_first_frame = cqueue_empty(s->gain_history_original[0]);
514 for (c = 0; c < s->channels; c++) {
515 double *dst_ptr = (double *)frame->extended_data[c];
516 double current_average_value = 0.0;
519 for (i = 0; i < frame->nb_samples; i++)
520 current_average_value += dst_ptr[i] * diff;
522 prev_value = is_first_frame ? current_average_value : s->dc_correction_value[c];
523 s->dc_correction_value[c] = is_first_frame ? current_average_value : update_value(current_average_value, s->dc_correction_value[c], 0.1);
525 for (i = 0; i < frame->nb_samples; i++) {
526 dst_ptr[i] -= fade(prev_value, s->dc_correction_value[c], i, s->fade_factors);
531 static double setup_compress_thresh(double threshold)
533 if ((threshold > DBL_EPSILON) && (threshold < (1.0 - DBL_EPSILON))) {
534 double current_threshold = threshold;
535 double step_size = 1.0;
537 while (step_size > DBL_EPSILON) {
538 while ((llrint((current_threshold + step_size) * (UINT64_C(1) << 63)) >
539 llrint(current_threshold * (UINT64_C(1) << 63))) &&
540 (bound(current_threshold + step_size, 1.0) <= threshold)) {
541 current_threshold += step_size;
547 return current_threshold;
553 static double compute_frame_std_dev(DynamicAudioNormalizerContext *s,
554 AVFrame *frame, int channel)
556 double variance = 0.0;
560 for (c = 0; c < s->channels; c++) {
561 const double *data_ptr = (double *)frame->extended_data[c];
563 for (i = 0; i < frame->nb_samples; i++) {
564 variance += pow_2(data_ptr[i]); // Assume that MEAN is *zero*
567 variance /= (s->channels * frame->nb_samples) - 1;
569 const double *data_ptr = (double *)frame->extended_data[channel];
571 for (i = 0; i < frame->nb_samples; i++) {
572 variance += pow_2(data_ptr[i]); // Assume that MEAN is *zero*
574 variance /= frame->nb_samples - 1;
577 return FFMAX(sqrt(variance), DBL_EPSILON);
580 static void perform_compression(DynamicAudioNormalizerContext *s, AVFrame *frame)
582 int is_first_frame = cqueue_empty(s->gain_history_original[0]);
585 if (s->channels_coupled) {
586 const double standard_deviation = compute_frame_std_dev(s, frame, -1);
587 const double current_threshold = FFMIN(1.0, s->compress_factor * standard_deviation);
589 const double prev_value = is_first_frame ? current_threshold : s->compress_threshold[0];
590 double prev_actual_thresh, curr_actual_thresh;
591 s->compress_threshold[0] = is_first_frame ? current_threshold : update_value(current_threshold, s->compress_threshold[0], (1.0/3.0));
593 prev_actual_thresh = setup_compress_thresh(prev_value);
594 curr_actual_thresh = setup_compress_thresh(s->compress_threshold[0]);
596 for (c = 0; c < s->channels; c++) {
597 double *const dst_ptr = (double *)frame->extended_data[c];
598 for (i = 0; i < frame->nb_samples; i++) {
599 const double localThresh = fade(prev_actual_thresh, curr_actual_thresh, i, s->fade_factors);
600 dst_ptr[i] = copysign(bound(localThresh, fabs(dst_ptr[i])), dst_ptr[i]);
604 for (c = 0; c < s->channels; c++) {
605 const double standard_deviation = compute_frame_std_dev(s, frame, c);
606 const double current_threshold = setup_compress_thresh(FFMIN(1.0, s->compress_factor * standard_deviation));
608 const double prev_value = is_first_frame ? current_threshold : s->compress_threshold[c];
609 double prev_actual_thresh, curr_actual_thresh;
611 s->compress_threshold[c] = is_first_frame ? current_threshold : update_value(current_threshold, s->compress_threshold[c], 1.0/3.0);
613 prev_actual_thresh = setup_compress_thresh(prev_value);
614 curr_actual_thresh = setup_compress_thresh(s->compress_threshold[c]);
616 dst_ptr = (double *)frame->extended_data[c];
617 for (i = 0; i < frame->nb_samples; i++) {
618 const double localThresh = fade(prev_actual_thresh, curr_actual_thresh, i, s->fade_factors);
619 dst_ptr[i] = copysign(bound(localThresh, fabs(dst_ptr[i])), dst_ptr[i]);
625 static void analyze_frame(DynamicAudioNormalizerContext *s, AVFrame *frame)
627 if (s->dc_correction) {
628 perform_dc_correction(s, frame);
631 if (s->compress_factor > DBL_EPSILON) {
632 perform_compression(s, frame);
635 if (s->channels_coupled) {
636 const double current_gain_factor = get_max_local_gain(s, frame, -1);
639 for (c = 0; c < s->channels; c++)
640 update_gain_history(s, c, current_gain_factor);
644 for (c = 0; c < s->channels; c++)
645 update_gain_history(s, c, get_max_local_gain(s, frame, c));
649 static void amplify_frame(DynamicAudioNormalizerContext *s, AVFrame *frame, int enabled)
653 for (c = 0; c < s->channels; c++) {
654 double *dst_ptr = (double *)frame->extended_data[c];
655 double current_amplification_factor;
657 cqueue_dequeue(s->gain_history_smoothed[c], ¤t_amplification_factor);
659 for (i = 0; i < frame->nb_samples && enabled; i++) {
660 const double amplification_factor = fade(s->prev_amplification_factor[c],
661 current_amplification_factor, i,
664 dst_ptr[i] *= amplification_factor;
666 if (fabs(dst_ptr[i]) > s->peak_value)
667 dst_ptr[i] = copysign(s->peak_value, dst_ptr[i]);
670 s->prev_amplification_factor[c] = current_amplification_factor;
674 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
676 AVFilterContext *ctx = inlink->dst;
677 DynamicAudioNormalizerContext *s = ctx->priv;
678 AVFilterLink *outlink = inlink->dst->outputs[0];
681 if (!cqueue_empty(s->gain_history_smoothed[0])) {
683 AVFrame *out = ff_bufqueue_get(&s->queue);
685 cqueue_dequeue(s->is_enabled, &is_enabled);
687 amplify_frame(s, out, is_enabled > 0.);
688 ret = ff_filter_frame(outlink, out);
691 av_frame_make_writable(in);
692 cqueue_enqueue(s->is_enabled, !ctx->is_disabled);
693 analyze_frame(s, in);
694 ff_bufqueue_add(ctx, &s->queue, in);
699 static int flush_buffer(DynamicAudioNormalizerContext *s, AVFilterLink *inlink,
700 AVFilterLink *outlink)
702 AVFrame *out = ff_get_audio_buffer(outlink, s->frame_len);
706 return AVERROR(ENOMEM);
708 for (c = 0; c < s->channels; c++) {
709 double *dst_ptr = (double *)out->extended_data[c];
711 for (i = 0; i < out->nb_samples; i++) {
712 dst_ptr[i] = s->alt_boundary_mode ? DBL_EPSILON : ((s->target_rms > DBL_EPSILON) ? FFMIN(s->peak_value, s->target_rms) : s->peak_value);
713 if (s->dc_correction) {
714 dst_ptr[i] *= ((i % 2) == 1) ? -1 : 1;
715 dst_ptr[i] += s->dc_correction_value[c];
721 return filter_frame(inlink, out);
724 static int flush(AVFilterLink *outlink)
726 AVFilterContext *ctx = outlink->src;
727 DynamicAudioNormalizerContext *s = ctx->priv;
730 if (!cqueue_empty(s->gain_history_smoothed[0])) {
731 ret = flush_buffer(s, ctx->inputs[0], outlink);
732 } else if (s->queue.available) {
733 AVFrame *out = ff_bufqueue_get(&s->queue);
736 ret = ff_filter_frame(outlink, out);
737 s->delay = s->queue.available;
743 static int activate(AVFilterContext *ctx)
745 AVFilterLink *inlink = ctx->inputs[0];
746 AVFilterLink *outlink = ctx->outputs[0];
747 DynamicAudioNormalizerContext *s = ctx->priv;
752 FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
755 ret = ff_inlink_consume_samples(inlink, s->frame_len, s->frame_len, &in);
759 ret = filter_frame(inlink, in);
764 if (ff_inlink_queued_samples(inlink) >= s->frame_len) {
765 ff_filter_set_ready(ctx, 10);
770 if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts)) {
771 if (status == AVERROR_EOF)
775 if (s->eof && s->delay > 0)
776 return flush(outlink);
778 if (s->eof && s->delay <= 0) {
779 ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
784 FF_FILTER_FORWARD_WANTED(outlink, inlink);
786 return FFERROR_NOT_READY;
789 static const AVFilterPad avfilter_af_dynaudnorm_inputs[] = {
792 .type = AVMEDIA_TYPE_AUDIO,
793 .config_props = config_input,
798 static const AVFilterPad avfilter_af_dynaudnorm_outputs[] = {
801 .type = AVMEDIA_TYPE_AUDIO,
806 AVFilter ff_af_dynaudnorm = {
807 .name = "dynaudnorm",
808 .description = NULL_IF_CONFIG_SMALL("Dynamic Audio Normalizer."),
809 .query_formats = query_formats,
810 .priv_size = sizeof(DynamicAudioNormalizerContext),
813 .activate = activate,
814 .inputs = avfilter_af_dynaudnorm_inputs,
815 .outputs = avfilter_af_dynaudnorm_outputs,
816 .priv_class = &dynaudnorm_class,
817 .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL,