FFmpeg
af_loudnorm.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Kyle Swanson <k@ylo.ph>.
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /* http://k.ylo.ph/2016/04/04/loudnorm.html */
22 
23 #include "libavutil/opt.h"
24 #include "avfilter.h"
25 #include "internal.h"
26 #include "audio.h"
27 #include "ebur128.h"
28 
29 enum FrameType {
35 };
36 
38  OUT,
43 };
44 
50 };
51 
52 typedef struct LoudNormContext {
53  const AVClass *class;
54  double target_i;
55  double target_lra;
56  double target_tp;
57  double measured_i;
58  double measured_lra;
59  double measured_tp;
61  double offset;
62  int linear;
63  int dual_mono;
65 
66  double *buf;
67  int buf_size;
68  int buf_index;
70 
71  double delta[30];
72  double weights[21];
73  double prev_delta;
74  int index;
75 
76  double gain_reduction[2];
77  double *limiter_buf;
78  double *prev_smp;
83  int env_index;
84  int env_cnt;
87 
88  int64_t pts;
92  int channels;
93 
97 
98 #define OFFSET(x) offsetof(LoudNormContext, x)
99 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
100 
101 static const AVOption loudnorm_options[] = {
102  { "I", "set integrated loudness target", OFFSET(target_i), AV_OPT_TYPE_DOUBLE, {.dbl = -24.}, -70., -5., FLAGS },
103  { "i", "set integrated loudness target", OFFSET(target_i), AV_OPT_TYPE_DOUBLE, {.dbl = -24.}, -70., -5., FLAGS },
104  { "LRA", "set loudness range target", OFFSET(target_lra), AV_OPT_TYPE_DOUBLE, {.dbl = 7.}, 1., 20., FLAGS },
105  { "lra", "set loudness range target", OFFSET(target_lra), AV_OPT_TYPE_DOUBLE, {.dbl = 7.}, 1., 20., FLAGS },
106  { "TP", "set maximum true peak", OFFSET(target_tp), AV_OPT_TYPE_DOUBLE, {.dbl = -2.}, -9., 0., FLAGS },
107  { "tp", "set maximum true peak", OFFSET(target_tp), AV_OPT_TYPE_DOUBLE, {.dbl = -2.}, -9., 0., FLAGS },
108  { "measured_I", "measured IL of input file", OFFSET(measured_i), AV_OPT_TYPE_DOUBLE, {.dbl = 0.}, -99., 0., FLAGS },
109  { "measured_i", "measured IL of input file", OFFSET(measured_i), AV_OPT_TYPE_DOUBLE, {.dbl = 0.}, -99., 0., FLAGS },
110  { "measured_LRA", "measured LRA of input file", OFFSET(measured_lra), AV_OPT_TYPE_DOUBLE, {.dbl = 0.}, 0., 99., FLAGS },
111  { "measured_lra", "measured LRA of input file", OFFSET(measured_lra), AV_OPT_TYPE_DOUBLE, {.dbl = 0.}, 0., 99., FLAGS },
112  { "measured_TP", "measured true peak of input file", OFFSET(measured_tp), AV_OPT_TYPE_DOUBLE, {.dbl = 99.}, -99., 99., FLAGS },
113  { "measured_tp", "measured true peak of input file", OFFSET(measured_tp), AV_OPT_TYPE_DOUBLE, {.dbl = 99.}, -99., 99., FLAGS },
114  { "measured_thresh", "measured threshold of input file", OFFSET(measured_thresh), AV_OPT_TYPE_DOUBLE, {.dbl = -70.}, -99., 0., FLAGS },
115  { "offset", "set offset gain", OFFSET(offset), AV_OPT_TYPE_DOUBLE, {.dbl = 0.}, -99., 99., FLAGS },
116  { "linear", "normalize linearly if possible", OFFSET(linear), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
117  { "dual_mono", "treat mono input as dual-mono", OFFSET(dual_mono), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
118  { "print_format", "set print format for stats", OFFSET(print_format), AV_OPT_TYPE_INT, {.i64 = NONE}, NONE, PF_NB -1, FLAGS, "print_format" },
119  { "none", 0, 0, AV_OPT_TYPE_CONST, {.i64 = NONE}, 0, 0, FLAGS, "print_format" },
120  { "json", 0, 0, AV_OPT_TYPE_CONST, {.i64 = JSON}, 0, 0, FLAGS, "print_format" },
121  { "summary", 0, 0, AV_OPT_TYPE_CONST, {.i64 = SUMMARY}, 0, 0, FLAGS, "print_format" },
122  { NULL }
123 };
124 
125 AVFILTER_DEFINE_CLASS(loudnorm);
126 
127 static inline int frame_size(int sample_rate, int frame_len_msec)
128 {
129  const int frame_size = round((double)sample_rate * (frame_len_msec / 1000.0));
130  return frame_size + (frame_size % 2);
131 }
132 
134 {
135  double total_weight = 0.0;
136  const double sigma = 3.5;
137  double adjust;
138  int i;
139 
140  const int offset = 21 / 2;
141  const double c1 = 1.0 / (sigma * sqrt(2.0 * M_PI));
142  const double c2 = 2.0 * pow(sigma, 2.0);
143 
144  for (i = 0; i < 21; i++) {
145  const int x = i - offset;
146  s->weights[i] = c1 * exp(-(pow(x, 2.0) / c2));
147  total_weight += s->weights[i];
148  }
149 
150  adjust = 1.0 / total_weight;
151  for (i = 0; i < 21; i++)
152  s->weights[i] *= adjust;
153 }
154 
156 {
157  double result = 0.;
158  int i;
159 
160  index = index - 10 > 0 ? index - 10 : index + 20;
161  for (i = 0; i < 21; i++)
162  result += s->delta[((index + i) < 30) ? (index + i) : (index + i - 30)] * s->weights[i];
163 
164  return result;
165 }
166 
167 static void detect_peak(LoudNormContext *s, int offset, int nb_samples, int channels, int *peak_delta, double *peak_value)
168 {
169  int n, c, i, index;
170  double ceiling;
171  double *buf;
172 
173  *peak_delta = -1;
174  buf = s->limiter_buf;
175  ceiling = s->target_tp;
176 
177  index = s->limiter_buf_index + (offset * channels) + (1920 * channels);
178  if (index >= s->limiter_buf_size)
179  index -= s->limiter_buf_size;
180 
181  if (s->frame_type == FIRST_FRAME) {
182  for (c = 0; c < channels; c++)
183  s->prev_smp[c] = fabs(buf[index + c - channels]);
184  }
185 
186  for (n = 0; n < nb_samples; n++) {
187  for (c = 0; c < channels; c++) {
188  double this, next, max_peak;
189 
190  this = fabs(buf[(index + c) < s->limiter_buf_size ? (index + c) : (index + c - s->limiter_buf_size)]);
191  next = fabs(buf[(index + c + channels) < s->limiter_buf_size ? (index + c + channels) : (index + c + channels - s->limiter_buf_size)]);
192 
193  if ((s->prev_smp[c] <= this) && (next <= this) && (this > ceiling) && (n > 0)) {
194  int detected;
195 
196  detected = 1;
197  for (i = 2; i < 12; i++) {
198  next = fabs(buf[(index + c + (i * channels)) < s->limiter_buf_size ? (index + c + (i * channels)) : (index + c + (i * channels) - s->limiter_buf_size)]);
199  if (next > this) {
200  detected = 0;
201  break;
202  }
203  }
204 
205  if (!detected)
206  continue;
207 
208  for (c = 0; c < channels; c++) {
209  if (c == 0 || fabs(buf[index + c]) > max_peak)
210  max_peak = fabs(buf[index + c]);
211 
212  s->prev_smp[c] = fabs(buf[(index + c) < s->limiter_buf_size ? (index + c) : (index + c - s->limiter_buf_size)]);
213  }
214 
215  *peak_delta = n;
216  s->peak_index = index;
217  *peak_value = max_peak;
218  return;
219  }
220 
221  s->prev_smp[c] = this;
222  }
223 
224  index += channels;
225  if (index >= s->limiter_buf_size)
226  index -= s->limiter_buf_size;
227  }
228 }
229 
230 static void true_peak_limiter(LoudNormContext *s, double *out, int nb_samples, int channels)
231 {
232  int n, c, index, peak_delta, smp_cnt;
233  double ceiling, peak_value;
234  double *buf;
235 
236  buf = s->limiter_buf;
237  ceiling = s->target_tp;
238  index = s->limiter_buf_index;
239  smp_cnt = 0;
240 
241  if (s->frame_type == FIRST_FRAME) {
242  double max;
243 
244  max = 0.;
245  for (n = 0; n < 1920; n++) {
246  for (c = 0; c < channels; c++) {
247  max = fabs(buf[c]) > max ? fabs(buf[c]) : max;
248  }
249  buf += channels;
250  }
251 
252  if (max > ceiling) {
253  s->gain_reduction[1] = ceiling / max;
254  s->limiter_state = SUSTAIN;
255  buf = s->limiter_buf;
256 
257  for (n = 0; n < 1920; n++) {
258  for (c = 0; c < channels; c++) {
259  double env;
260  env = s->gain_reduction[1];
261  buf[c] *= env;
262  }
263  buf += channels;
264  }
265  }
266 
267  buf = s->limiter_buf;
268  }
269 
270  do {
271 
272  switch(s->limiter_state) {
273  case OUT:
274  detect_peak(s, smp_cnt, nb_samples - smp_cnt, channels, &peak_delta, &peak_value);
275  if (peak_delta != -1) {
276  s->env_cnt = 0;
277  smp_cnt += (peak_delta - s->attack_length);
278  s->gain_reduction[0] = 1.;
279  s->gain_reduction[1] = ceiling / peak_value;
280  s->limiter_state = ATTACK;
281 
282  s->env_index = s->peak_index - (s->attack_length * channels);
283  if (s->env_index < 0)
284  s->env_index += s->limiter_buf_size;
285 
286  s->env_index += (s->env_cnt * channels);
287  if (s->env_index > s->limiter_buf_size)
288  s->env_index -= s->limiter_buf_size;
289 
290  } else {
291  smp_cnt = nb_samples;
292  }
293  break;
294 
295  case ATTACK:
296  for (; s->env_cnt < s->attack_length; s->env_cnt++) {
297  for (c = 0; c < channels; c++) {
298  double env;
299  env = s->gain_reduction[0] - ((double) s->env_cnt / (s->attack_length - 1) * (s->gain_reduction[0] - s->gain_reduction[1]));
300  buf[s->env_index + c] *= env;
301  }
302 
303  s->env_index += channels;
304  if (s->env_index >= s->limiter_buf_size)
305  s->env_index -= s->limiter_buf_size;
306 
307  smp_cnt++;
308  if (smp_cnt >= nb_samples) {
309  s->env_cnt++;
310  break;
311  }
312  }
313 
314  if (smp_cnt < nb_samples) {
315  s->env_cnt = 0;
316  s->attack_length = 1920;
317  s->limiter_state = SUSTAIN;
318  }
319  break;
320 
321  case SUSTAIN:
322  detect_peak(s, smp_cnt, nb_samples, channels, &peak_delta, &peak_value);
323  if (peak_delta == -1) {
324  s->limiter_state = RELEASE;
325  s->gain_reduction[0] = s->gain_reduction[1];
326  s->gain_reduction[1] = 1.;
327  s->env_cnt = 0;
328  break;
329  } else {
330  double gain_reduction;
331  gain_reduction = ceiling / peak_value;
332 
333  if (gain_reduction < s->gain_reduction[1]) {
334  s->limiter_state = ATTACK;
335 
336  s->attack_length = peak_delta;
337  if (s->attack_length <= 1)
338  s->attack_length = 2;
339 
340  s->gain_reduction[0] = s->gain_reduction[1];
341  s->gain_reduction[1] = gain_reduction;
342  s->env_cnt = 0;
343  break;
344  }
345 
346  for (s->env_cnt = 0; s->env_cnt < peak_delta; s->env_cnt++) {
347  for (c = 0; c < channels; c++) {
348  double env;
349  env = s->gain_reduction[1];
350  buf[s->env_index + c] *= env;
351  }
352 
353  s->env_index += channels;
354  if (s->env_index >= s->limiter_buf_size)
355  s->env_index -= s->limiter_buf_size;
356 
357  smp_cnt++;
358  if (smp_cnt >= nb_samples) {
359  s->env_cnt++;
360  break;
361  }
362  }
363  }
364  break;
365 
366  case RELEASE:
367  for (; s->env_cnt < s->release_length; s->env_cnt++) {
368  for (c = 0; c < channels; c++) {
369  double env;
370  env = s->gain_reduction[0] + (((double) s->env_cnt / (s->release_length - 1)) * (s->gain_reduction[1] - s->gain_reduction[0]));
371  buf[s->env_index + c] *= env;
372  }
373 
374  s->env_index += channels;
375  if (s->env_index >= s->limiter_buf_size)
376  s->env_index -= s->limiter_buf_size;
377 
378  smp_cnt++;
379  if (smp_cnt >= nb_samples) {
380  s->env_cnt++;
381  break;
382  }
383  }
384 
385  if (smp_cnt < nb_samples) {
386  s->env_cnt = 0;
387  s->limiter_state = OUT;
388  }
389 
390  break;
391  }
392 
393  } while (smp_cnt < nb_samples);
394 
395  for (n = 0; n < nb_samples; n++) {
396  for (c = 0; c < channels; c++) {
397  out[c] = buf[index + c];
398  if (fabs(out[c]) > ceiling) {
399  out[c] = ceiling * (out[c] < 0 ? -1 : 1);
400  }
401  }
402  out += channels;
403  index += channels;
404  if (index >= s->limiter_buf_size)
405  index -= s->limiter_buf_size;
406  }
407 }
408 
410 {
411  AVFilterContext *ctx = inlink->dst;
412  LoudNormContext *s = ctx->priv;
413  AVFilterLink *outlink = ctx->outputs[0];
414  AVFrame *out;
415  const double *src;
416  double *dst;
417  double *buf;
418  double *limiter_buf;
419  int i, n, c, subframe_length, src_index;
420  double gain, gain_next, env_global, env_shortterm,
421  global, shortterm, lra, relative_threshold;
422 
423  if (av_frame_is_writable(in)) {
424  out = in;
425  } else {
426  out = ff_get_audio_buffer(outlink, in->nb_samples);
427  if (!out) {
428  av_frame_free(&in);
429  return AVERROR(ENOMEM);
430  }
432  }
433 
434  if (s->pts == AV_NOPTS_VALUE)
435  s->pts = in->pts;
436 
437  out->pts = s->pts;
438  src = (const double *)in->data[0];
439  dst = (double *)out->data[0];
440  buf = s->buf;
441  limiter_buf = s->limiter_buf;
442 
444 
445  if (s->frame_type == FIRST_FRAME && in->nb_samples < frame_size(inlink->sample_rate, 3000)) {
446  double offset, offset_tp, true_peak;
447 
448  ff_ebur128_loudness_global(s->r128_in, &global);
449  for (c = 0; c < inlink->channels; c++) {
450  double tmp;
451  ff_ebur128_sample_peak(s->r128_in, c, &tmp);
452  if (c == 0 || tmp > true_peak)
453  true_peak = tmp;
454  }
455 
456  offset = pow(10., (s->target_i - global) / 20.);
457  offset_tp = true_peak * offset;
458  s->offset = offset_tp < s->target_tp ? offset : s->target_tp - true_peak;
459  s->frame_type = LINEAR_MODE;
460  }
461 
462  switch (s->frame_type) {
463  case FIRST_FRAME:
464  for (n = 0; n < in->nb_samples; n++) {
465  for (c = 0; c < inlink->channels; c++) {
466  buf[s->buf_index + c] = src[c];
467  }
468  src += inlink->channels;
469  s->buf_index += inlink->channels;
470  }
471 
472  ff_ebur128_loudness_shortterm(s->r128_in, &shortterm);
473 
474  if (shortterm < s->measured_thresh) {
475  s->above_threshold = 0;
476  env_shortterm = shortterm <= -70. ? 0. : s->target_i - s->measured_i;
477  } else {
478  s->above_threshold = 1;
479  env_shortterm = shortterm <= -70. ? 0. : s->target_i - shortterm;
480  }
481 
482  for (n = 0; n < 30; n++)
483  s->delta[n] = pow(10., env_shortterm / 20.);
484  s->prev_delta = s->delta[s->index];
485 
486  s->buf_index =
487  s->limiter_buf_index = 0;
488 
489  for (n = 0; n < (s->limiter_buf_size / inlink->channels); n++) {
490  for (c = 0; c < inlink->channels; c++) {
491  limiter_buf[s->limiter_buf_index + c] = buf[s->buf_index + c] * s->delta[s->index] * s->offset;
492  }
493  s->limiter_buf_index += inlink->channels;
494  if (s->limiter_buf_index >= s->limiter_buf_size)
495  s->limiter_buf_index -= s->limiter_buf_size;
496 
497  s->buf_index += inlink->channels;
498  }
499 
500  subframe_length = frame_size(inlink->sample_rate, 100);
501  true_peak_limiter(s, dst, subframe_length, inlink->channels);
502  ff_ebur128_add_frames_double(s->r128_out, dst, subframe_length);
503 
504  s->pts +=
505  out->nb_samples =
506  inlink->min_samples =
507  inlink->max_samples = subframe_length;
508 
509  s->frame_type = INNER_FRAME;
510  break;
511 
512  case INNER_FRAME:
513  gain = gaussian_filter(s, s->index + 10 < 30 ? s->index + 10 : s->index + 10 - 30);
514  gain_next = gaussian_filter(s, s->index + 11 < 30 ? s->index + 11 : s->index + 11 - 30);
515 
516  for (n = 0; n < in->nb_samples; n++) {
517  for (c = 0; c < inlink->channels; c++) {
518  buf[s->prev_buf_index + c] = src[c];
519  limiter_buf[s->limiter_buf_index + c] = buf[s->buf_index + c] * (gain + (((double) n / in->nb_samples) * (gain_next - gain))) * s->offset;
520  }
521  src += inlink->channels;
522 
523  s->limiter_buf_index += inlink->channels;
524  if (s->limiter_buf_index >= s->limiter_buf_size)
525  s->limiter_buf_index -= s->limiter_buf_size;
526 
527  s->prev_buf_index += inlink->channels;
528  if (s->prev_buf_index >= s->buf_size)
529  s->prev_buf_index -= s->buf_size;
530 
531  s->buf_index += inlink->channels;
532  if (s->buf_index >= s->buf_size)
533  s->buf_index -= s->buf_size;
534  }
535 
536  subframe_length = (frame_size(inlink->sample_rate, 100) - in->nb_samples) * inlink->channels;
537  s->limiter_buf_index = s->limiter_buf_index + subframe_length < s->limiter_buf_size ? s->limiter_buf_index + subframe_length : s->limiter_buf_index + subframe_length - s->limiter_buf_size;
538 
539  true_peak_limiter(s, dst, in->nb_samples, inlink->channels);
540  ff_ebur128_add_frames_double(s->r128_out, dst, in->nb_samples);
541 
542  ff_ebur128_loudness_range(s->r128_in, &lra);
543  ff_ebur128_loudness_global(s->r128_in, &global);
544  ff_ebur128_loudness_shortterm(s->r128_in, &shortterm);
545  ff_ebur128_relative_threshold(s->r128_in, &relative_threshold);
546 
547  if (s->above_threshold == 0) {
548  double shortterm_out;
549 
550  if (shortterm > s->measured_thresh)
551  s->prev_delta *= 1.0058;
552 
553  ff_ebur128_loudness_shortterm(s->r128_out, &shortterm_out);
554  if (shortterm_out >= s->target_i)
555  s->above_threshold = 1;
556  }
557 
558  if (shortterm < relative_threshold || shortterm <= -70. || s->above_threshold == 0) {
559  s->delta[s->index] = s->prev_delta;
560  } else {
561  env_global = fabs(shortterm - global) < (s->target_lra / 2.) ? shortterm - global : (s->target_lra / 2.) * ((shortterm - global) < 0 ? -1 : 1);
562  env_shortterm = s->target_i - shortterm;
563  s->delta[s->index] = pow(10., (env_global + env_shortterm) / 20.);
564  }
565 
566  s->prev_delta = s->delta[s->index];
567  s->index++;
568  if (s->index >= 30)
569  s->index -= 30;
570  s->prev_nb_samples = in->nb_samples;
571  s->pts += in->nb_samples;
572  break;
573 
574  case FINAL_FRAME:
575  gain = gaussian_filter(s, s->index + 10 < 30 ? s->index + 10 : s->index + 10 - 30);
576  s->limiter_buf_index = 0;
577  src_index = 0;
578 
579  for (n = 0; n < s->limiter_buf_size / inlink->channels; n++) {
580  for (c = 0; c < inlink->channels; c++) {
581  s->limiter_buf[s->limiter_buf_index + c] = src[src_index + c] * gain * s->offset;
582  }
583  src_index += inlink->channels;
584 
585  s->limiter_buf_index += inlink->channels;
586  if (s->limiter_buf_index >= s->limiter_buf_size)
587  s->limiter_buf_index -= s->limiter_buf_size;
588  }
589 
590  subframe_length = frame_size(inlink->sample_rate, 100);
591  for (i = 0; i < in->nb_samples / subframe_length; i++) {
592  true_peak_limiter(s, dst, subframe_length, inlink->channels);
593 
594  for (n = 0; n < subframe_length; n++) {
595  for (c = 0; c < inlink->channels; c++) {
596  if (src_index < (in->nb_samples * inlink->channels)) {
597  limiter_buf[s->limiter_buf_index + c] = src[src_index + c] * gain * s->offset;
598  } else {
599  limiter_buf[s->limiter_buf_index + c] = 0.;
600  }
601  }
602 
603  if (src_index < (in->nb_samples * inlink->channels))
604  src_index += inlink->channels;
605 
606  s->limiter_buf_index += inlink->channels;
607  if (s->limiter_buf_index >= s->limiter_buf_size)
608  s->limiter_buf_index -= s->limiter_buf_size;
609  }
610 
611  dst += (subframe_length * inlink->channels);
612  }
613 
614  dst = (double *)out->data[0];
615  ff_ebur128_add_frames_double(s->r128_out, dst, in->nb_samples);
616  break;
617 
618  case LINEAR_MODE:
619  for (n = 0; n < in->nb_samples; n++) {
620  for (c = 0; c < inlink->channels; c++) {
621  dst[c] = src[c] * s->offset;
622  }
623  src += inlink->channels;
624  dst += inlink->channels;
625  }
626 
627  dst = (double *)out->data[0];
628  ff_ebur128_add_frames_double(s->r128_out, dst, in->nb_samples);
629  s->pts += in->nb_samples;
630  break;
631  }
632 
633  if (in != out)
634  av_frame_free(&in);
635 
636  return ff_filter_frame(outlink, out);
637 }
638 
639 static int request_frame(AVFilterLink *outlink)
640 {
641  int ret;
642  AVFilterContext *ctx = outlink->src;
643  AVFilterLink *inlink = ctx->inputs[0];
644  LoudNormContext *s = ctx->priv;
645 
647  if (ret == AVERROR_EOF && s->frame_type == INNER_FRAME) {
648  double *src;
649  double *buf;
650  int nb_samples, n, c, offset;
651  AVFrame *frame;
652 
653  nb_samples = (s->buf_size / inlink->channels) - s->prev_nb_samples;
654  nb_samples -= (frame_size(inlink->sample_rate, 100) - s->prev_nb_samples);
655 
656  frame = ff_get_audio_buffer(outlink, nb_samples);
657  if (!frame)
658  return AVERROR(ENOMEM);
659  frame->nb_samples = nb_samples;
660 
661  buf = s->buf;
662  src = (double *)frame->data[0];
663 
664  offset = ((s->limiter_buf_size / inlink->channels) - s->prev_nb_samples) * inlink->channels;
665  offset -= (frame_size(inlink->sample_rate, 100) - s->prev_nb_samples) * inlink->channels;
666  s->buf_index = s->buf_index - offset < 0 ? s->buf_index - offset + s->buf_size : s->buf_index - offset;
667 
668  for (n = 0; n < nb_samples; n++) {
669  for (c = 0; c < inlink->channels; c++) {
670  src[c] = buf[s->buf_index + c];
671  }
672  src += inlink->channels;
673  s->buf_index += inlink->channels;
674  if (s->buf_index >= s->buf_size)
675  s->buf_index -= s->buf_size;
676  }
677 
678  s->frame_type = FINAL_FRAME;
680  }
681  return ret;
682 }
683 
685 {
686  LoudNormContext *s = ctx->priv;
688  AVFilterLink *inlink = ctx->inputs[0];
689  AVFilterLink *outlink = ctx->outputs[0];
690  static const int input_srate[] = {192000, -1};
691  static const enum AVSampleFormat sample_fmts[] = {
694  };
696  if (ret < 0)
697  return ret;
698 
700  if (ret < 0)
701  return ret;
702 
703  if (s->frame_type != LINEAR_MODE) {
704  formats = ff_make_format_list(input_srate);
705  if (!formats)
706  return AVERROR(ENOMEM);
707  ret = ff_formats_ref(formats, &inlink->outcfg.samplerates);
708  if (ret < 0)
709  return ret;
711  if (ret < 0)
712  return ret;
713  }
714 
715  return 0;
716 }
717 
719 {
720  AVFilterContext *ctx = inlink->dst;
721  LoudNormContext *s = ctx->priv;
722 
724  if (!s->r128_in)
725  return AVERROR(ENOMEM);
726 
728  if (!s->r128_out)
729  return AVERROR(ENOMEM);
730 
731  if (inlink->channels == 1 && s->dual_mono) {
734  }
735 
736  s->buf_size = frame_size(inlink->sample_rate, 3000) * inlink->channels;
737  s->buf = av_malloc_array(s->buf_size, sizeof(*s->buf));
738  if (!s->buf)
739  return AVERROR(ENOMEM);
740 
741  s->limiter_buf_size = frame_size(inlink->sample_rate, 210) * inlink->channels;
742  s->limiter_buf = av_malloc_array(s->buf_size, sizeof(*s->limiter_buf));
743  if (!s->limiter_buf)
744  return AVERROR(ENOMEM);
745 
746  s->prev_smp = av_malloc_array(inlink->channels, sizeof(*s->prev_smp));
747  if (!s->prev_smp)
748  return AVERROR(ENOMEM);
749 
751 
752  if (s->frame_type != LINEAR_MODE) {
753  inlink->min_samples =
754  inlink->max_samples = frame_size(inlink->sample_rate, 3000);
755  }
756 
757  s->pts = AV_NOPTS_VALUE;
758  s->buf_index =
759  s->prev_buf_index =
760  s->limiter_buf_index = 0;
761  s->channels = inlink->channels;
762  s->index = 1;
763  s->limiter_state = OUT;
764  s->offset = pow(10., s->offset / 20.);
765  s->target_tp = pow(10., s->target_tp / 20.);
766  s->attack_length = frame_size(inlink->sample_rate, 10);
767  s->release_length = frame_size(inlink->sample_rate, 100);
768 
769  return 0;
770 }
771 
773 {
774  LoudNormContext *s = ctx->priv;
775  s->frame_type = FIRST_FRAME;
776 
777  if (s->linear) {
778  double offset, offset_tp;
779  offset = s->target_i - s->measured_i;
780  offset_tp = s->measured_tp + offset;
781 
782  if (s->measured_tp != 99 && s->measured_thresh != -70 && s->measured_lra != 0 && s->measured_i != 0) {
783  if ((offset_tp <= s->target_tp) && (s->measured_lra <= s->target_lra)) {
784  s->frame_type = LINEAR_MODE;
785  s->offset = offset;
786  }
787  }
788  }
789 
790  return 0;
791 }
792 
794 {
795  LoudNormContext *s = ctx->priv;
796  double i_in, i_out, lra_in, lra_out, thresh_in, thresh_out, tp_in, tp_out;
797  int c;
798 
799  if (!s->r128_in || !s->r128_out)
800  goto end;
801 
802  ff_ebur128_loudness_range(s->r128_in, &lra_in);
803  ff_ebur128_loudness_global(s->r128_in, &i_in);
804  ff_ebur128_relative_threshold(s->r128_in, &thresh_in);
805  for (c = 0; c < s->channels; c++) {
806  double tmp;
807  ff_ebur128_sample_peak(s->r128_in, c, &tmp);
808  if ((c == 0) || (tmp > tp_in))
809  tp_in = tmp;
810  }
811 
812  ff_ebur128_loudness_range(s->r128_out, &lra_out);
813  ff_ebur128_loudness_global(s->r128_out, &i_out);
814  ff_ebur128_relative_threshold(s->r128_out, &thresh_out);
815  for (c = 0; c < s->channels; c++) {
816  double tmp;
817  ff_ebur128_sample_peak(s->r128_out, c, &tmp);
818  if ((c == 0) || (tmp > tp_out))
819  tp_out = tmp;
820  }
821 
822  switch(s->print_format) {
823  case NONE:
824  break;
825 
826  case JSON:
828  "\n{\n"
829  "\t\"input_i\" : \"%.2f\",\n"
830  "\t\"input_tp\" : \"%.2f\",\n"
831  "\t\"input_lra\" : \"%.2f\",\n"
832  "\t\"input_thresh\" : \"%.2f\",\n"
833  "\t\"output_i\" : \"%.2f\",\n"
834  "\t\"output_tp\" : \"%+.2f\",\n"
835  "\t\"output_lra\" : \"%.2f\",\n"
836  "\t\"output_thresh\" : \"%.2f\",\n"
837  "\t\"normalization_type\" : \"%s\",\n"
838  "\t\"target_offset\" : \"%.2f\"\n"
839  "}\n",
840  i_in,
841  20. * log10(tp_in),
842  lra_in,
843  thresh_in,
844  i_out,
845  20. * log10(tp_out),
846  lra_out,
847  thresh_out,
848  s->frame_type == LINEAR_MODE ? "linear" : "dynamic",
849  s->target_i - i_out
850  );
851  break;
852 
853  case SUMMARY:
855  "\n"
856  "Input Integrated: %+6.1f LUFS\n"
857  "Input True Peak: %+6.1f dBTP\n"
858  "Input LRA: %6.1f LU\n"
859  "Input Threshold: %+6.1f LUFS\n"
860  "\n"
861  "Output Integrated: %+6.1f LUFS\n"
862  "Output True Peak: %+6.1f dBTP\n"
863  "Output LRA: %6.1f LU\n"
864  "Output Threshold: %+6.1f LUFS\n"
865  "\n"
866  "Normalization Type: %s\n"
867  "Target Offset: %+6.1f LU\n",
868  i_in,
869  20. * log10(tp_in),
870  lra_in,
871  thresh_in,
872  i_out,
873  20. * log10(tp_out),
874  lra_out,
875  thresh_out,
876  s->frame_type == LINEAR_MODE ? "Linear" : "Dynamic",
877  s->target_i - i_out
878  );
879  break;
880  }
881 
882 end:
883  if (s->r128_in)
884  ff_ebur128_destroy(&s->r128_in);
885  if (s->r128_out)
886  ff_ebur128_destroy(&s->r128_out);
887  av_freep(&s->limiter_buf);
888  av_freep(&s->prev_smp);
889  av_freep(&s->buf);
890 }
891 
893  {
894  .name = "default",
895  .type = AVMEDIA_TYPE_AUDIO,
896  .config_props = config_input,
897  .filter_frame = filter_frame,
898  },
899 };
900 
902  {
903  .name = "default",
904  .request_frame = request_frame,
905  .type = AVMEDIA_TYPE_AUDIO,
906  },
907 };
908 
910  .name = "loudnorm",
911  .description = NULL_IF_CONFIG_SMALL("EBU R128 loudness normalization"),
912  .priv_size = sizeof(LoudNormContext),
913  .priv_class = &loudnorm_class,
914  .init = init,
915  .uninit = uninit,
919 };
formats
formats
Definition: signature.h:48
init
static av_cold int init(AVFilterContext *ctx)
Definition: af_loudnorm.c:772
STATE_NB
@ STATE_NB
Definition: af_loudnorm.c:42
ff_get_audio_buffer
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:88
AVFilterFormatsConfig::samplerates
AVFilterFormats * samplerates
Lists of supported sample rates, only for audio.
Definition: avfilter.h:511
LoudNormContext::weights
double weights[21]
Definition: af_loudnorm.c:72
SUSTAIN
@ SUSTAIN
Definition: af_loudnorm.c:40
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
NONE
@ NONE
Definition: af_loudnorm.c:46
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_loudnorm.c:793
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:381
out
FILE * out
Definition: movenc.c:54
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1018
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
frame_size
static int frame_size(int sample_rate, int frame_len_msec)
Definition: af_loudnorm.c:127
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:109
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:424
index
fg index
Definition: ffmpeg_filter.c:167
LoudNormContext::peak_index
int peak_index
Definition: af_loudnorm.c:82
AVOption
AVOption.
Definition: opt.h:247
FILTER_QUERY_FUNC
#define FILTER_QUERY_FUNC(func)
Definition: internal.h:168
LoudNormContext::prev_smp
double * prev_smp
Definition: af_loudnorm.c:78
linear
static int linear(InterplayACMContext *s, unsigned ind, unsigned col)
Definition: interplayacm.c:131
ff_request_frame
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:420
FF_EBUR128_MODE_I
@ FF_EBUR128_MODE_I
can call ff_ebur128_loudness_global_* and ff_ebur128_relative_threshold
Definition: ebur128.h:89
print_format
static char * print_format
Definition: ffprobe.c:126
LoudNormContext::r128_in
FFEBUR128State * r128_in
Definition: af_loudnorm.c:94
max
#define max(a, b)
Definition: cuda_runtime.h:33
LoudNormContext::print_format
enum PrintFormat print_format
Definition: af_loudnorm.c:64
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:169
c1
static const uint64_t c1
Definition: murmur3.c:51
avfilter_af_loudnorm_outputs
static const AVFilterPad avfilter_af_loudnorm_outputs[]
Definition: af_loudnorm.c:901
LoudNormContext::prev_nb_samples
int prev_nb_samples
Definition: af_loudnorm.c:91
sample_rate
sample_rate
Definition: ffmpeg_filter.c:153
ff_ebur128_loudness_range
int ff_ebur128_loudness_range(FFEBUR128State *st, double *out)
Get loudness range (LRA) of programme in LU.
Definition: ebur128.c:708
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:338
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
JSON
@ JSON
Definition: af_loudnorm.c:47
LoudNormContext::target_tp
double target_tp
Definition: af_loudnorm.c:56
INNER_FRAME
@ INNER_FRAME
Definition: af_loudnorm.c:31
LoudNormContext::above_threshold
int above_threshold
Definition: af_loudnorm.c:90
ff_ebur128_destroy
void ff_ebur128_destroy(FFEBUR128State **st)
Destroy library state.
Definition: ebur128.c:303
ATTACK
@ ATTACK
Definition: af_loudnorm.c:39
LoudNormContext::env_index
int env_index
Definition: af_loudnorm.c:83
RELEASE
@ RELEASE
Definition: af_loudnorm.c:41
true_peak_limiter
static void true_peak_limiter(LoudNormContext *s, double *out, int nb_samples, int channels)
Definition: af_loudnorm.c:230
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
FF_EBUR128_DUAL_MONO
@ FF_EBUR128_DUAL_MONO
a channel that is counted twice
Definition: ebur128.h:51
FLAGS
#define FLAGS
Definition: af_loudnorm.c:99
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_loudnorm.c:409
av_cold
#define av_cold
Definition: attributes.h:90
LoudNormContext::index
int index
Definition: af_loudnorm.c:74
FF_EBUR128_MODE_LRA
@ FF_EBUR128_MODE_LRA
can call ff_ebur128_loudness_range
Definition: ebur128.h:91
SUMMARY
@ SUMMARY
Definition: af_loudnorm.c:48
s
#define s(width, name)
Definition: cbs_vp9.c:257
ff_ebur128_add_frames_double
void ff_ebur128_add_frames_double(FFEBUR128State *st, const double *src, size_t frames)
Add frames to be processed.
adjust
static int adjust(int x, int size)
Definition: mobiclip.c:514
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:226
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:555
ff_set_common_formats_from_list
int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_format_list(fmts))
Definition: formats.c:705
LoudNormContext::measured_tp
double measured_tp
Definition: af_loudnorm.c:59
LoudNormContext::limiter_state
enum LimiterState limiter_state
Definition: af_loudnorm.c:81
ctx
AVFormatContext * ctx
Definition: movenc.c:48
channels
channels
Definition: aptx.h:33
LoudNormContext::env_cnt
int env_cnt
Definition: af_loudnorm.c:84
LoudNormContext::prev_delta
double prev_delta
Definition: af_loudnorm.c:73
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:191
FrameType
FrameType
G723.1 frame types.
Definition: g723_1.h:63
ff_af_loudnorm
const AVFilter ff_af_loudnorm
Definition: af_loudnorm.c:909
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
result
and forward the result(frame or status change) to the corresponding input. If nothing is possible
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:537
FRAME_NB
@ FRAME_NB
Definition: af_loudnorm.c:34
LoudNormContext::measured_lra
double measured_lra
Definition: af_loudnorm.c:58
LoudNormContext::delta
double delta[30]
Definition: af_loudnorm.c:71
ff_ebur128_sample_peak
int ff_ebur128_sample_peak(FFEBUR128State *st, unsigned int channel_number, double *out)
Get maximum sample peak of selected channel in float format.
Definition: ebur128.c:713
src
#define src
Definition: vp8dsp.c:255
loudnorm_options
static const AVOption loudnorm_options[]
Definition: af_loudnorm.c:101
LoudNormContext::buf_index
int buf_index
Definition: af_loudnorm.c:68
LoudNormContext::attack_length
int attack_length
Definition: af_loudnorm.c:85
LoudNormContext::limiter_buf_index
int limiter_buf_index
Definition: af_loudnorm.c:79
ff_set_common_all_channel_counts
int ff_set_common_all_channel_counts(AVFilterContext *ctx)
Equivalent to ff_set_common_channel_layouts(ctx, ff_all_channel_counts())
Definition: formats.c:671
exp
int8_t exp
Definition: eval.c:72
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
LoudNormContext::limiter_buf
double * limiter_buf
Definition: af_loudnorm.c:77
LoudNormContext::release_length
int release_length
Definition: af_loudnorm.c:86
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_loudnorm.c:684
LoudNormContext::measured_i
double measured_i
Definition: af_loudnorm.c:57
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(loudnorm)
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
ff_ebur128_loudness_shortterm
int ff_ebur128_loudness_shortterm(FFEBUR128State *st, double *out)
Get short-term loudness (last 3s) in LUFS.
Definition: ebur128.c:616
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
init_gaussian_filter
static void init_gaussian_filter(LoudNormContext *s)
Definition: af_loudnorm.c:133
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:473
PrintFormat
PrintFormat
Definition: af_loudnorm.c:45
FF_EBUR128_MODE_S
@ FF_EBUR128_MODE_S
can call ff_ebur128_loudness_shortterm
Definition: ebur128.h:87
ff_ebur128_init
FFEBUR128State * ff_ebur128_init(unsigned int channels, unsigned long samplerate, unsigned long window, int mode)
Initialize library state.
Definition: ebur128.c:218
LoudNormContext::prev_buf_index
int prev_buf_index
Definition: af_loudnorm.c:69
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
OUT
@ OUT
Definition: af_loudnorm.c:38
LoudNormContext::target_i
double target_i
Definition: af_loudnorm.c:54
LoudNormContext
Definition: af_loudnorm.c:52
M_PI
#define M_PI
Definition: mathematics.h:52
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
internal.h
LoudNormContext::frame_type
enum FrameType frame_type
Definition: af_loudnorm.c:89
LoudNormContext::pts
int64_t pts
Definition: af_loudnorm.c:88
LimiterState
LimiterState
Definition: af_loudnorm.c:37
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:397
LoudNormContext::measured_thresh
double measured_thresh
Definition: af_loudnorm.c:60
LoudNormContext::buf
double * buf
Definition: af_loudnorm.c:66
LoudNormContext::offset
double offset
Definition: af_loudnorm.c:61
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
LoudNormContext::limiter_buf_size
int limiter_buf_size
Definition: af_loudnorm.c:80
ff_ebur128_set_channel
int ff_ebur128_set_channel(FFEBUR128State *st, unsigned int channel_number, int value)
Set channel type.
Definition: ebur128.c:444
round
static av_always_inline av_const double round(double x)
Definition: libm.h:444
ebur128.h
libebur128 - a library for loudness measurement according to the EBU R128 standard.
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
FFEBUR128State
Contains information about the state of a loudness measurement.
Definition: ebur128.h:103
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
avfilter_af_loudnorm_inputs
static const AVFilterPad avfilter_af_loudnorm_inputs[]
Definition: af_loudnorm.c:892
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: af_loudnorm.c:639
AVFilter
Filter definition.
Definition: avfilter.h:165
ret
ret
Definition: filter_design.txt:187
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
LoudNormContext::channels
int channels
Definition: af_loudnorm.c:92
FINAL_FRAME
@ FINAL_FRAME
Definition: af_loudnorm.c:32
LoudNormContext::buf_size
int buf_size
Definition: af_loudnorm.c:67
c2
static const uint64_t c2
Definition: murmur3.c:52
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_loudnorm.c:718
LoudNormContext::gain_reduction
double gain_reduction[2]
Definition: af_loudnorm.c:76
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
PF_NB
@ PF_NB
Definition: af_loudnorm.c:49
AVFilterContext
An instance of a filter.
Definition: avfilter.h:402
LoudNormContext::linear
int linear
Definition: af_loudnorm.c:62
audio.h
LINEAR_MODE
@ LINEAR_MODE
Definition: af_loudnorm.c:33
LoudNormContext::dual_mono
int dual_mono
Definition: af_loudnorm.c:63
OFFSET
#define OFFSET(x)
Definition: af_loudnorm.c:98
ff_ebur128_relative_threshold
int ff_ebur128_relative_threshold(FFEBUR128State *st, double *out)
Get relative threshold in LUFS.
Definition: ebur128.c:579
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:241
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
FF_EBUR128_MODE_SAMPLE_PEAK
@ FF_EBUR128_MODE_SAMPLE_PEAK
can call ff_ebur128_sample_peak
Definition: ebur128.h:93
detect_peak
static void detect_peak(LoudNormContext *s, int offset, int nb_samples, int channels, int *peak_delta, double *peak_value)
Definition: af_loudnorm.c:167
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
gaussian_filter
static double gaussian_filter(LoudNormContext *s, int index)
Definition: af_loudnorm.c:155
LoudNormContext::r128_out
FFEBUR128State * r128_out
Definition: af_loudnorm.c:95
AV_SAMPLE_FMT_DBL
@ AV_SAMPLE_FMT_DBL
double
Definition: samplefmt.h:64
FIRST_FRAME
@ FIRST_FRAME
Definition: af_loudnorm.c:30
ff_ebur128_loudness_global
int ff_ebur128_loudness_global(FFEBUR128State *st, double *out)
Get global integrated loudness in LUFS.
Definition: ebur128.c:595
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
LoudNormContext::target_lra
double target_lra
Definition: af_loudnorm.c:55