FFmpeg
af_adeclick.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Paul B Mahol
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 #include "libavutil/audio_fifo.h"
22 #include "libavutil/opt.h"
23 #include "avfilter.h"
24 #include "audio.h"
25 #include "filters.h"
26 #include "formats.h"
27 #include "internal.h"
28 
29 typedef struct DeclickChannel {
30  double *auxiliary;
31  double *detection;
32  double *acoefficients;
33  double *acorrelation;
34  double *tmp;
35  double *interpolated;
36  double *matrix;
38  double *vector;
40  double *y;
41  int y_size;
43  int *index;
44  unsigned *histogram;
47 
48 typedef struct AudioDeclickContext {
49  const AVClass *class;
50 
51  double w;
52  double overlap;
53  double threshold;
54  double ar;
55  double burst;
56  int method;
57  int nb_hbins;
58 
59  int is_declip;
60  int ar_order;
63  int hop_size;
65 
70 
72 
73  int64_t pts;
75  uint64_t nb_samples;
76  uint64_t detected_errors;
78  int eof;
79 
81  double *window_func_lut;
82 
83  int (*detector)(struct AudioDeclickContext *s, DeclickChannel *c,
84  double sigmae, double *detection,
85  double *acoefficients, uint8_t *click, int *index,
86  const double *src, double *dst);
88 
89 #define OFFSET(x) offsetof(AudioDeclickContext, x)
90 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
91 
92 static const AVOption adeclick_options[] = {
93  { "w", "set window size", OFFSET(w), AV_OPT_TYPE_DOUBLE, {.dbl=55}, 10, 100, AF },
94  { "o", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_DOUBLE, {.dbl=75}, 50, 95, AF },
95  { "a", "set autoregression order", OFFSET(ar), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 0, 25, AF },
96  { "t", "set threshold", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 1, 100, AF },
97  { "b", "set burst fusion", OFFSET(burst), AV_OPT_TYPE_DOUBLE, {.dbl=2}, 0, 10, AF },
98  { "m", "set overlap method", OFFSET(method), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, AF, "m" },
99  { "a", "overlap-add", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "m" },
100  { "s", "overlap-save", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "m" },
101  { NULL }
102 };
103 
104 AVFILTER_DEFINE_CLASS(adeclick);
105 
107 {
110  static const enum AVSampleFormat sample_fmts[] = {
113  };
114  int ret;
115 
116  formats = ff_make_format_list(sample_fmts);
117  if (!formats)
118  return AVERROR(ENOMEM);
119  ret = ff_set_common_formats(ctx, formats);
120  if (ret < 0)
121  return ret;
122 
123  layouts = ff_all_channel_counts();
124  if (!layouts)
125  return AVERROR(ENOMEM);
126 
127  ret = ff_set_common_channel_layouts(ctx, layouts);
128  if (ret < 0)
129  return ret;
130 
131  formats = ff_all_samplerates();
132  return ff_set_common_samplerates(ctx, formats);
133 }
134 
136 {
137  AVFilterContext *ctx = inlink->dst;
138  AudioDeclickContext *s = ctx->priv;
139  int i;
140 
141  s->pts = AV_NOPTS_VALUE;
142  s->window_size = inlink->sample_rate * s->w / 1000.;
143  if (s->window_size < 100)
144  return AVERROR(EINVAL);
145  s->ar_order = FFMAX(s->window_size * s->ar / 100., 1);
146  s->nb_burst_samples = s->window_size * s->burst / 1000.;
147  s->hop_size = s->window_size * (1. - (s->overlap / 100.));
148  if (s->hop_size < 1)
149  return AVERROR(EINVAL);
150 
152  if (!s->window_func_lut)
153  return AVERROR(ENOMEM);
154  for (i = 0; i < s->window_size; i++)
155  s->window_func_lut[i] = sin(M_PI * i / s->window_size) *
156  (1. - (s->overlap / 100.)) * M_PI_2;
157 
158  av_frame_free(&s->in);
159  av_frame_free(&s->out);
160  av_frame_free(&s->buffer);
161  av_frame_free(&s->is);
162  s->in = ff_get_audio_buffer(inlink, s->window_size);
163  s->out = ff_get_audio_buffer(inlink, s->window_size);
164  s->buffer = ff_get_audio_buffer(inlink, s->window_size * 2);
165  s->is = ff_get_audio_buffer(inlink, s->window_size);
166  if (!s->in || !s->out || !s->buffer || !s->is)
167  return AVERROR(ENOMEM);
168 
169  s->fifo = av_audio_fifo_alloc(inlink->format, inlink->channels, s->window_size);
170  if (!s->fifo)
171  return AVERROR(ENOMEM);
172  s->overlap_skip = s->method ? (s->window_size - s->hop_size) / 2 : 0;
173  if (s->overlap_skip > 0) {
174  av_audio_fifo_write(s->fifo, (void **)s->in->extended_data,
175  s->overlap_skip);
176  }
177 
178  s->nb_channels = inlink->channels;
179  s->chan = av_calloc(inlink->channels, sizeof(*s->chan));
180  if (!s->chan)
181  return AVERROR(ENOMEM);
182 
183  for (i = 0; i < inlink->channels; i++) {
184  DeclickChannel *c = &s->chan[i];
185 
186  c->detection = av_calloc(s->window_size, sizeof(*c->detection));
187  c->auxiliary = av_calloc(s->ar_order + 1, sizeof(*c->auxiliary));
188  c->acoefficients = av_calloc(s->ar_order + 1, sizeof(*c->acoefficients));
189  c->acorrelation = av_calloc(s->ar_order + 1, sizeof(*c->acorrelation));
190  c->tmp = av_calloc(s->ar_order, sizeof(*c->tmp));
191  c->click = av_calloc(s->window_size, sizeof(*c->click));
192  c->index = av_calloc(s->window_size, sizeof(*c->index));
193  c->interpolated = av_calloc(s->window_size, sizeof(*c->interpolated));
194  if (!c->auxiliary || !c->acoefficients || !c->detection || !c->click ||
195  !c->index || !c->interpolated || !c->acorrelation || !c->tmp)
196  return AVERROR(ENOMEM);
197  }
198 
199  return 0;
200 }
201 
202 static void autocorrelation(const double *input, int order, int size,
203  double *output, double scale)
204 {
205  int i, j;
206 
207  for (i = 0; i <= order; i++) {
208  double value = 0.;
209 
210  for (j = i; j < size; j++)
211  value += input[j] * input[j - i];
212 
213  output[i] = value * scale;
214  }
215 }
216 
217 static double autoregression(const double *samples, int ar_order,
218  int nb_samples, double *k, double *r, double *a)
219 {
220  double alpha;
221  int i, j;
222 
223  memset(a, 0, ar_order * sizeof(*a));
224 
225  autocorrelation(samples, ar_order, nb_samples, r, 1. / nb_samples);
226 
227  /* Levinson-Durbin algorithm */
228  k[0] = a[0] = -r[1] / r[0];
229  alpha = r[0] * (1. - k[0] * k[0]);
230  for (i = 1; i < ar_order; i++) {
231  double epsilon = 0.;
232 
233  for (j = 0; j < i; j++)
234  epsilon += a[j] * r[i - j];
235  epsilon += r[i + 1];
236 
237  k[i] = -epsilon / alpha;
238  alpha *= (1. - k[i] * k[i]);
239  for (j = i - 1; j >= 0; j--)
240  k[j] = a[j] + k[i] * a[i - j - 1];
241  for (j = 0; j <= i; j++)
242  a[j] = k[j];
243  }
244 
245  k[0] = 1.;
246  for (i = 1; i <= ar_order; i++)
247  k[i] = a[i - 1];
248 
249  return sqrt(alpha);
250 }
251 
252 static int isfinite_array(double *samples, int nb_samples)
253 {
254  int i;
255 
256  for (i = 0; i < nb_samples; i++)
257  if (!isfinite(samples[i]))
258  return 0;
259 
260  return 1;
261 }
262 
263 static int find_index(int *index, int value, int size)
264 {
265  int i, start, end;
266 
267  if ((value < index[0]) || (value > index[size - 1]))
268  return 1;
269 
270  i = start = 0;
271  end = size - 1;
272 
273  while (start <= end) {
274  i = (end + start) / 2;
275  if (index[i] == value)
276  return 0;
277  if (value < index[i])
278  end = i - 1;
279  if (value > index[i])
280  start = i + 1;
281  }
282 
283  return 1;
284 }
285 
286 static int factorization(double *matrix, int n)
287 {
288  int i, j, k;
289 
290  for (i = 0; i < n; i++) {
291  const int in = i * n;
292  double value;
293 
294  value = matrix[in + i];
295  for (j = 0; j < i; j++)
296  value -= matrix[j * n + j] * matrix[in + j] * matrix[in + j];
297 
298  if (value == 0.) {
299  return -1;
300  }
301 
302  matrix[in + i] = value;
303  for (j = i + 1; j < n; j++) {
304  const int jn = j * n;
305  double x;
306 
307  x = matrix[jn + i];
308  for (k = 0; k < i; k++)
309  x -= matrix[k * n + k] * matrix[in + k] * matrix[jn + k];
310  matrix[jn + i] = x / matrix[in + i];
311  }
312  }
313 
314  return 0;
315 }
316 
318  double *vector, int n, double *out)
319 {
320  int i, j, ret;
321  double *y;
322 
323  ret = factorization(matrix, n);
324  if (ret < 0)
325  return ret;
326 
327  av_fast_malloc(&c->y, &c->y_size, n * sizeof(*c->y));
328  y = c->y;
329  if (!y)
330  return AVERROR(ENOMEM);
331 
332  for (i = 0; i < n; i++) {
333  const int in = i * n;
334  double value;
335 
336  value = vector[i];
337  for (j = 0; j < i; j++)
338  value -= matrix[in + j] * y[j];
339  y[i] = value;
340  }
341 
342  for (i = n - 1; i >= 0; i--) {
343  out[i] = y[i] / matrix[i * n + i];
344  for (j = i + 1; j < n; j++)
345  out[i] -= matrix[j * n + i] * out[j];
346  }
347 
348  return 0;
349 }
350 
351 static int interpolation(DeclickChannel *c, const double *src, int ar_order,
352  double *acoefficients, int *index, int nb_errors,
353  double *auxiliary, double *interpolated)
354 {
355  double *vector, *matrix;
356  int i, j;
357 
358  av_fast_malloc(&c->matrix, &c->matrix_size, nb_errors * nb_errors * sizeof(*c->matrix));
359  matrix = c->matrix;
360  if (!matrix)
361  return AVERROR(ENOMEM);
362 
363  av_fast_malloc(&c->vector, &c->vector_size, nb_errors * sizeof(*c->vector));
364  vector = c->vector;
365  if (!vector)
366  return AVERROR(ENOMEM);
367 
368  autocorrelation(acoefficients, ar_order, ar_order + 1, auxiliary, 1.);
369 
370  for (i = 0; i < nb_errors; i++) {
371  const int im = i * nb_errors;
372 
373  for (j = i; j < nb_errors; j++) {
374  if (abs(index[j] - index[i]) <= ar_order) {
375  matrix[j * nb_errors + i] = matrix[im + j] = auxiliary[abs(index[j] - index[i])];
376  } else {
377  matrix[j * nb_errors + i] = matrix[im + j] = 0;
378  }
379  }
380  }
381 
382  for (i = 0; i < nb_errors; i++) {
383  double value = 0.;
384 
385  for (j = -ar_order; j <= ar_order; j++)
386  if (find_index(index, index[i] - j, nb_errors))
387  value -= src[index[i] - j] * auxiliary[abs(j)];
388 
389  vector[i] = value;
390  }
391 
392  return do_interpolation(c, matrix, vector, nb_errors, interpolated);
393 }
394 
396  double unused0,
397  double *unused1, double *unused2,
398  uint8_t *clip, int *index,
399  const double *src, double *dst)
400 {
401  const double threshold = s->threshold;
402  double max_amplitude = 0;
403  unsigned *histogram;
404  int i, nb_clips = 0;
405 
406  av_fast_malloc(&c->histogram, &c->histogram_size, s->nb_hbins * sizeof(*c->histogram));
407  if (!c->histogram)
408  return AVERROR(ENOMEM);
409  histogram = c->histogram;
410  memset(histogram, 0, sizeof(*histogram) * s->nb_hbins);
411 
412  for (i = 0; i < s->window_size; i++) {
413  const unsigned index = fmin(fabs(src[i]), 1) * (s->nb_hbins - 1);
414 
415  histogram[index]++;
416  dst[i] = src[i];
417  clip[i] = 0;
418  }
419 
420  for (i = s->nb_hbins - 1; i > 1; i--) {
421  if (histogram[i]) {
422  if (histogram[i] / (double)FFMAX(histogram[i - 1], 1) > threshold) {
423  max_amplitude = i / (double)s->nb_hbins;
424  }
425  break;
426  }
427  }
428 
429  if (max_amplitude > 0.) {
430  for (i = 0; i < s->window_size; i++) {
431  clip[i] = fabs(src[i]) >= max_amplitude;
432  }
433  }
434 
435  memset(clip, 0, s->ar_order * sizeof(*clip));
436  memset(clip + (s->window_size - s->ar_order), 0, s->ar_order * sizeof(*clip));
437 
438  for (i = s->ar_order; i < s->window_size - s->ar_order; i++)
439  if (clip[i])
440  index[nb_clips++] = i;
441 
442  return nb_clips;
443 }
444 
446  double sigmae,
447  double *detection, double *acoefficients,
448  uint8_t *click, int *index,
449  const double *src, double *dst)
450 {
451  const double threshold = s->threshold;
452  int i, j, nb_clicks = 0, prev = -1;
453 
454  memset(detection, 0, s->window_size * sizeof(*detection));
455 
456  for (i = s->ar_order; i < s->window_size; i++) {
457  for (j = 0; j <= s->ar_order; j++) {
458  detection[i] += acoefficients[j] * src[i - j];
459  }
460  }
461 
462  for (i = 0; i < s->window_size; i++) {
463  click[i] = fabs(detection[i]) > sigmae * threshold;
464  dst[i] = src[i];
465  }
466 
467  for (i = 0; i < s->window_size; i++) {
468  if (!click[i])
469  continue;
470 
471  if (prev >= 0 && (i > prev + 1) && (i <= s->nb_burst_samples + prev))
472  for (j = prev + 1; j < i; j++)
473  click[j] = 1;
474  prev = i;
475  }
476 
477  memset(click, 0, s->ar_order * sizeof(*click));
478  memset(click + (s->window_size - s->ar_order), 0, s->ar_order * sizeof(*click));
479 
480  for (i = s->ar_order; i < s->window_size - s->ar_order; i++)
481  if (click[i])
482  index[nb_clicks++] = i;
483 
484  return nb_clicks;
485 }
486 
487 typedef struct ThreadData {
489 } ThreadData;
490 
491 static int filter_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
492 {
493  AudioDeclickContext *s = ctx->priv;
494  ThreadData *td = arg;
495  AVFrame *out = td->out;
496  const double *src = (const double *)s->in->extended_data[ch];
497  double *is = (double *)s->is->extended_data[ch];
498  double *dst = (double *)s->out->extended_data[ch];
499  double *ptr = (double *)out->extended_data[ch];
500  double *buf = (double *)s->buffer->extended_data[ch];
501  const double *w = s->window_func_lut;
502  DeclickChannel *c = &s->chan[ch];
503  double sigmae;
504  int j, ret;
505 
506  sigmae = autoregression(src, s->ar_order, s->window_size, c->acoefficients, c->acorrelation, c->tmp);
507 
508  if (isfinite_array(c->acoefficients, s->ar_order + 1)) {
509  double *interpolated = c->interpolated;
510  int *index = c->index;
511  int nb_errors;
512 
513  nb_errors = s->detector(s, c, sigmae, c->detection, c->acoefficients,
514  c->click, index, src, dst);
515  if (nb_errors > 0) {
516  ret = interpolation(c, src, s->ar_order, c->acoefficients, index,
517  nb_errors, c->auxiliary, interpolated);
518  if (ret < 0)
519  return ret;
520 
521  for (j = 0; j < nb_errors; j++) {
522  dst[index[j]] = interpolated[j];
523  is[index[j]] = 1;
524  }
525  }
526  } else {
527  memcpy(dst, src, s->window_size * sizeof(*dst));
528  }
529 
530  if (s->method == 0) {
531  for (j = 0; j < s->window_size; j++)
532  buf[j] += dst[j] * w[j];
533  } else {
534  const int skip = s->overlap_skip;
535 
536  for (j = 0; j < s->hop_size; j++)
537  buf[j] = dst[skip + j];
538  }
539  for (j = 0; j < s->hop_size; j++)
540  ptr[j] = buf[j];
541 
542  memmove(buf, buf + s->hop_size, (s->window_size * 2 - s->hop_size) * sizeof(*buf));
543  memmove(is, is + s->hop_size, (s->window_size - s->hop_size) * sizeof(*is));
544  memset(buf + s->window_size * 2 - s->hop_size, 0, s->hop_size * sizeof(*buf));
545  memset(is + s->window_size - s->hop_size, 0, s->hop_size * sizeof(*is));
546 
547  return 0;
548 }
549 
551 {
552  AVFilterContext *ctx = inlink->dst;
553  AVFilterLink *outlink = ctx->outputs[0];
554  AudioDeclickContext *s = ctx->priv;
555  AVFrame *out = NULL;
556  int ret = 0, j, ch, detected_errors = 0;
557  ThreadData td;
558 
559  out = ff_get_audio_buffer(outlink, s->hop_size);
560  if (!out)
561  return AVERROR(ENOMEM);
562 
563  ret = av_audio_fifo_peek(s->fifo, (void **)s->in->extended_data,
564  s->window_size);
565  if (ret < 0)
566  goto fail;
567 
568  td.out = out;
569  ret = ctx->internal->execute(ctx, filter_channel, &td, NULL, inlink->channels);
570  if (ret < 0)
571  goto fail;
572 
573  for (ch = 0; ch < s->in->channels; ch++) {
574  double *is = (double *)s->is->extended_data[ch];
575 
576  for (j = 0; j < s->hop_size; j++) {
577  if (is[j])
578  detected_errors++;
579  }
580  }
581 
583 
584  if (s->samples_left > 0)
585  out->nb_samples = FFMIN(s->hop_size, s->samples_left);
586 
587  out->pts = s->pts;
588  s->pts += s->hop_size;
589 
590  s->detected_errors += detected_errors;
591  s->nb_samples += out->nb_samples * inlink->channels;
592 
593  ret = ff_filter_frame(outlink, out);
594  if (ret < 0)
595  return ret;
596 
597  if (s->samples_left > 0) {
598  s->samples_left -= s->hop_size;
599  if (s->samples_left <= 0)
601  }
602 
603 fail:
604  if (ret < 0)
605  av_frame_free(&out);
606  return ret;
607 }
608 
610 {
611  AVFilterLink *inlink = ctx->inputs[0];
612  AVFilterLink *outlink = ctx->outputs[0];
613  AudioDeclickContext *s = ctx->priv;
614  AVFrame *in;
615  int ret, status;
616  int64_t pts;
617 
618  FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
619 
620  ret = ff_inlink_consume_samples(inlink, s->window_size, s->window_size, &in);
621  if (ret < 0)
622  return ret;
623  if (ret > 0) {
624  if (s->pts == AV_NOPTS_VALUE)
625  s->pts = in->pts;
626 
627  ret = av_audio_fifo_write(s->fifo, (void **)in->extended_data,
628  in->nb_samples);
629  av_frame_free(&in);
630  if (ret < 0)
631  return ret;
632  }
633 
634  if (av_audio_fifo_size(s->fifo) >= s->window_size ||
635  s->samples_left > 0)
636  return filter_frame(inlink);
637 
638  if (av_audio_fifo_size(s->fifo) >= s->window_size) {
639  ff_filter_set_ready(ctx, 100);
640  return 0;
641  }
642 
643  if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts)) {
644  if (status == AVERROR_EOF) {
645  s->eof = 1;
647  ff_filter_set_ready(ctx, 100);
648  return 0;
649  }
650  }
651 
652  if (s->eof && s->samples_left <= 0) {
653  ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
654  return 0;
655  }
656 
657  if (!s->eof)
658  FF_FILTER_FORWARD_WANTED(outlink, inlink);
659 
660  return FFERROR_NOT_READY;
661 }
662 
664 {
665  AudioDeclickContext *s = ctx->priv;
666 
667  s->is_declip = !strcmp(ctx->filter->name, "adeclip");
668  if (s->is_declip) {
669  s->detector = detect_clips;
670  } else {
671  s->detector = detect_clicks;
672  }
673 
674  return 0;
675 }
676 
678 {
679  AudioDeclickContext *s = ctx->priv;
680  int i;
681 
682  av_log(ctx, AV_LOG_INFO, "Detected %s in %"PRId64" of %"PRId64" samples (%g%%).\n",
683  s->is_declip ? "clips" : "clicks", s->detected_errors,
684  s->nb_samples, 100. * s->detected_errors / s->nb_samples);
685 
688  av_frame_free(&s->in);
689  av_frame_free(&s->out);
690  av_frame_free(&s->buffer);
691  av_frame_free(&s->is);
692 
693  if (s->chan) {
694  for (i = 0; i < s->nb_channels; i++) {
695  DeclickChannel *c = &s->chan[i];
696 
697  av_freep(&c->detection);
698  av_freep(&c->auxiliary);
699  av_freep(&c->acoefficients);
700  av_freep(&c->acorrelation);
701  av_freep(&c->tmp);
702  av_freep(&c->click);
703  av_freep(&c->index);
704  av_freep(&c->interpolated);
705  av_freep(&c->matrix);
706  c->matrix_size = 0;
707  av_freep(&c->histogram);
708  c->histogram_size = 0;
709  av_freep(&c->vector);
710  c->vector_size = 0;
711  av_freep(&c->y);
712  c->y_size = 0;
713  }
714  }
715  av_freep(&s->chan);
716  s->nb_channels = 0;
717 }
718 
719 static const AVFilterPad inputs[] = {
720  {
721  .name = "default",
722  .type = AVMEDIA_TYPE_AUDIO,
723  .config_props = config_input,
724  },
725  { NULL }
726 };
727 
728 static const AVFilterPad outputs[] = {
729  {
730  .name = "default",
731  .type = AVMEDIA_TYPE_AUDIO,
732  },
733  { NULL }
734 };
735 
737  .name = "adeclick",
738  .description = NULL_IF_CONFIG_SMALL("Remove impulsive noise from input audio."),
739  .query_formats = query_formats,
740  .priv_size = sizeof(AudioDeclickContext),
741  .priv_class = &adeclick_class,
742  .init = init,
743  .activate = activate,
744  .uninit = uninit,
745  .inputs = inputs,
746  .outputs = outputs,
748 };
749 
750 static const AVOption adeclip_options[] = {
751  { "w", "set window size", OFFSET(w), AV_OPT_TYPE_DOUBLE, {.dbl=55}, 10, 100, AF },
752  { "o", "set window overlap", OFFSET(overlap), AV_OPT_TYPE_DOUBLE, {.dbl=75}, 50, 95, AF },
753  { "a", "set autoregression order", OFFSET(ar), AV_OPT_TYPE_DOUBLE, {.dbl=8}, 0, 25, AF },
754  { "t", "set threshold", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl=10}, 1, 100, AF },
755  { "n", "set histogram size", OFFSET(nb_hbins), AV_OPT_TYPE_INT, {.i64=1000}, 100, 9999, AF },
756  { "m", "set overlap method", OFFSET(method), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, AF, "m" },
757  { "a", "overlap-add", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, AF, "m" },
758  { "s", "overlap-save", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, AF, "m" },
759  { NULL }
760 };
761 
762 AVFILTER_DEFINE_CLASS(adeclip);
763 
765  .name = "adeclip",
766  .description = NULL_IF_CONFIG_SMALL("Remove clipping from input audio."),
767  .query_formats = query_formats,
768  .priv_size = sizeof(AudioDeclickContext),
769  .priv_class = &adeclip_class,
770  .init = init,
771  .activate = activate,
772  .uninit = uninit,
773  .inputs = inputs,
774  .outputs = outputs,
776 };
#define NULL
Definition: coverity.c:32
int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *layouts)
A helper for query_formats() which sets all links to the same list of channel layouts/sample rates...
Definition: formats.c:550
static int detect_clips(AudioDeclickContext *s, DeclickChannel *c, double unused0, double *unused1, double *unused2, uint8_t *clip, int *index, const double *src, double *dst)
Definition: af_adeclick.c:395
#define OFFSET(x)
Definition: af_adeclick.c:89
AVFrame * out
Definition: af_adeclick.c:488
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
Definition: audio_fifo.c:59
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
AVOption.
Definition: opt.h:246
static const AVFilterPad outputs[]
Definition: af_adeclick.c:728
Main libavfilter public API header.
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
Definition: audio_fifo.c:45
double, planar
Definition: samplefmt.h:70
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:36
static int config_input(AVFilterLink *inlink)
Definition: af_adeclick.c:135
return FFERROR_NOT_READY
#define src
Definition: vp8dsp.c:254
static av_cold int init(AVFilterContext *ctx)
Definition: af_adeclick.c:663
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:189
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:244
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
DeclickChannel * chan
Definition: af_adeclick.c:71
const char * name
Pad name.
Definition: internal.h:60
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1093
int(* detector)(struct AudioDeclickContext *s, DeclickChannel *c, double sigmae, double *detection, double *acoefficients, uint8_t *click, int *index, const double *src, double *dst)
Definition: af_adeclick.c:83
uint8_t
#define av_cold
Definition: attributes.h:82
AVOptions.
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
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
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:108
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:388
uint8_t * click
Definition: af_adeclick.c:42
#define AVERROR_EOF
End of file.
Definition: error.h:55
ptrdiff_t size
Definition: opengl_enc.c:100
#define av_log(a,...)
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition: filters.h:199
A filter pad used for either input or output.
Definition: internal.h:54
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1449
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:569
#define td
Definition: regdef.h:70
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:86
#define isfinite(x)
Definition: libm.h:359
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
const char * r
Definition: vf_curves.c:114
void * priv
private data for use by the filter
Definition: avfilter.h:353
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:116
const char * arg
Definition: jacosubdec.c:66
static int find_index(int *index, int value, int size)
Definition: af_adeclick.c:263
double * window_func_lut
Definition: af_adeclick.c:81
#define FFMAX(a, b)
Definition: common.h:94
#define fail()
Definition: checkasm.h:122
Context for an Audio FIFO Buffer.
Definition: audio_fifo.c:34
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: mem.c:500
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
Definition: audio_fifo.c:228
int channels
number of audio channels, only used for audio.
Definition: frame.h:601
#define FFMIN(a, b)
Definition: common.h:96
unsigned * histogram
Definition: af_adeclick.c:44
static int detect_clicks(AudioDeclickContext *s, DeclickChannel *c, double sigmae, double *detection, double *acoefficients, uint8_t *click, int *index, const double *src, double *dst)
Definition: af_adeclick.c:445
uint8_t w
Definition: llviddspenc.c:38
#define M_PI_2
Definition: mathematics.h:55
static int interpolation(DeclickChannel *c, const double *src, int ar_order, double *acoefficients, int *index, int nb_errors, double *auxiliary, double *interpolated)
Definition: af_adeclick.c:351
AVFormatContext * ctx
Definition: movenc.c:48
static int activate(AVFilterContext *ctx)
Definition: af_adeclick.c:609
#define s(width, name)
Definition: cbs_vp9.c:257
AVAudioFifo * fifo
Definition: af_adeclick.c:80
int n
Definition: avisynth_c.h:760
static const AVOption adeclip_options[]
Definition: af_adeclick.c:750
AVFilter ff_af_adeclick
Definition: af_adeclick.c:736
A list of supported channel layouts.
Definition: formats.h:85
double * detection
Definition: af_adeclick.c:31
double * y
Definition: af_adeclick.c:40
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
double * acoefficients
Definition: af_adeclick.c:32
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
static int filter_frame(AVFilterLink *inlink)
Definition: af_adeclick.c:550
Used for passing data between threads.
Definition: dsddec.c:64
#define abs(x)
Definition: cuda_runtime.h:35
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link&#39;s FIFO and update the link&#39;s stats.
Definition: avfilter.c:1513
static const int16_t alpha[]
Definition: ilbcdata.h:55
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_adeclick.c:677
static int filter_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs)
Definition: af_adeclick.c:491
static const AVOption adeclick_options[]
Definition: af_adeclick.c:92
void * buf
Definition: avisynth_c.h:766
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
double * vector
Definition: af_adeclick.c:38
static void autocorrelation(const double *input, int order, int size, double *output, double scale)
Definition: af_adeclick.c:202
#define AF
Definition: af_adeclick.c:90
AVFilter ff_af_adeclip
Definition: af_adeclick.c:764
float im
Definition: fft.c:82
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
const char * name
Filter name.
Definition: avfilter.h:148
double * interpolated
Definition: af_adeclick.c:35
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(const int64_t *) pi *(1.0f/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(const int64_t *) pi *(1.0/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(UINT64_C(1)<< 63)))#define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};static void cpy1(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, len);}static void cpy2(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 2 *len);}static void cpy4(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 4 *len);}static void cpy8(uint8_t **dst, const uint8_t **src, int len){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;}void swri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len){int ch;int off=0;const int os=(out->planar?1:out->ch_count)*out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){int planes=in->planar?in->ch_count:1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){int planes=out->planar?out->ch_count:1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){int planes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:394
static int64_t pts
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:378
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
Definition: audio_fifo.c:112
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
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
Definition: audio_fifo.c:201
double * acorrelation
Definition: af_adeclick.c:33
int
double * matrix
Definition: af_adeclick.c:36
static int isfinite_array(double *samples, int nb_samples)
Definition: af_adeclick.c:252
static double clip(void *opaque, double val)
Clip value val in the minval - maxval range.
Definition: vf_lut.c:162
static int factorization(double *matrix, int n)
Definition: af_adeclick.c:286
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition: avfilter.c:193
static const AVFilterPad inputs[]
Definition: af_adeclick.c:719
double fmin(double, double)
avfilter_execute_func * execute
Definition: internal.h:155
FF_FILTER_FORWARD_WANTED(outlink, inlink)
static int do_interpolation(DeclickChannel *c, double *matrix, double *vector, int n, double *out)
Definition: af_adeclick.c:317
uint64_t detected_errors
Definition: af_adeclick.c:76
double * tmp
Definition: af_adeclick.c:34
Audio FIFO Buffer.
double * auxiliary
Definition: af_adeclick.c:30
The official guide to swscale for confused that is
Definition: swscale.txt:2
A list of supported formats for one end of a filter link.
Definition: formats.h:64
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
Definition: audio_fifo.c:138
An instance of a filter.
Definition: avfilter.h:338
static int query_formats(AVFilterContext *ctx)
Definition: af_adeclick.c:106
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
FILE * out
Definition: movenc.c:54
Filter the word “frame” indicates either a video frame or a group of audio samples
#define av_freep(p)
AVFILTER_DEFINE_CLASS(adeclick)
void INT64 start
Definition: avisynth_c.h:766
#define M_PI
Definition: mathematics.h:52
formats
Definition: signature.h:48
internal API functions
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
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition...
Definition: formats.c:409
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:342
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:361
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:341
for(j=16;j >0;--j)
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:557
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
static double autoregression(const double *samples, int ar_order, int nb_samples, double *k, double *r, double *a)
Definition: af_adeclick.c:217