FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
af_compand.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1999 Chris Bagwell
3  * Copyright (c) 1999 Nick Bailey
4  * Copyright (c) 2007 Rob Sykes <robs@users.sourceforge.net>
5  * Copyright (c) 2013 Paul B Mahol
6  * Copyright (c) 2014 Andrew Kelley
7  *
8  * This file is part of FFmpeg.
9  *
10  * FFmpeg is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * FFmpeg is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with FFmpeg; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24 
25 /**
26  * @file
27  * audio compand filter
28  */
29 
30 #include "libavutil/avassert.h"
31 #include "libavutil/avstring.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/samplefmt.h"
34 #include "audio.h"
35 #include "avfilter.h"
36 #include "internal.h"
37 
38 typedef struct ChanParam {
39  double attack;
40  double decay;
41  double volume;
42 } ChanParam;
43 
44 typedef struct CompandSegment {
45  double x, y;
46  double a, b;
48 
49 typedef struct CompandContext {
50  const AVClass *class;
52  char *attacks, *decays, *points;
55  double in_min_lin;
56  double out_min_lin;
57  double curve_dB;
58  double gain_dB;
60  double delay;
65  int64_t pts;
66 
69 
70 #define OFFSET(x) offsetof(CompandContext, x)
71 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
72 
73 static const AVOption compand_options[] = {
74  { "attacks", "set time over which increase of volume is determined", OFFSET(attacks), AV_OPT_TYPE_STRING, { .str = "0.3" }, 0, 0, A },
75  { "decays", "set time over which decrease of volume is determined", OFFSET(decays), AV_OPT_TYPE_STRING, { .str = "0.8" }, 0, 0, A },
76  { "points", "set points of transfer function", OFFSET(points), AV_OPT_TYPE_STRING, { .str = "-70/-70|-60/-20" }, 0, 0, A },
77  { "soft-knee", "set soft-knee", OFFSET(curve_dB), AV_OPT_TYPE_DOUBLE, { .dbl = 0.01 }, 0.01, 900, A },
78  { "gain", "set output gain", OFFSET(gain_dB), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, -900, 900, A },
79  { "volume", "set initial volume", OFFSET(initial_volume), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, -900, 0, A },
80  { "delay", "set delay for samples before sending them to volume adjuster", OFFSET(delay), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, 0, 20, A },
81  { NULL }
82 };
83 
84 AVFILTER_DEFINE_CLASS(compand);
85 
87 {
88  CompandContext *s = ctx->priv;
89  s->pts = AV_NOPTS_VALUE;
90  return 0;
91 }
92 
94 {
95  CompandContext *s = ctx->priv;
96 
97  av_freep(&s->channels);
98  av_freep(&s->segments);
100 }
101 
103 {
106  static const enum AVSampleFormat sample_fmts[] = {
109  };
110  int ret;
111 
112  layouts = ff_all_channel_counts();
113  if (!layouts)
114  return AVERROR(ENOMEM);
115  ret = ff_set_common_channel_layouts(ctx, layouts);
116  if (ret < 0)
117  return ret;
118 
119  formats = ff_make_format_list(sample_fmts);
120  if (!formats)
121  return AVERROR(ENOMEM);
122  ret = ff_set_common_formats(ctx, formats);
123  if (ret < 0)
124  return ret;
125 
126  formats = ff_all_samplerates();
127  if (!formats)
128  return AVERROR(ENOMEM);
129  return ff_set_common_samplerates(ctx, formats);
130 }
131 
132 static void count_items(char *item_str, int *nb_items)
133 {
134  char *p;
135 
136  *nb_items = 1;
137  for (p = item_str; *p; p++) {
138  if (*p == ' ' || *p == '|')
139  (*nb_items)++;
140  }
141 }
142 
143 static void update_volume(ChanParam *cp, double in)
144 {
145  double delta = in - cp->volume;
146 
147  if (delta > 0.0)
148  cp->volume += delta * cp->attack;
149  else
150  cp->volume += delta * cp->decay;
151 }
152 
153 static double get_volume(CompandContext *s, double in_lin)
154 {
155  CompandSegment *cs;
156  double in_log, out_log;
157  int i;
158 
159  if (in_lin < s->in_min_lin)
160  return s->out_min_lin;
161 
162  in_log = log(in_lin);
163 
164  for (i = 1; i < s->nb_segments; i++)
165  if (in_log <= s->segments[i].x)
166  break;
167  cs = &s->segments[i - 1];
168  in_log -= cs->x;
169  out_log = cs->y + in_log * (cs->a * in_log + cs->b);
170 
171  return exp(out_log);
172 }
173 
175 {
176  CompandContext *s = ctx->priv;
177  AVFilterLink *inlink = ctx->inputs[0];
178  const int channels = inlink->channels;
179  const int nb_samples = frame->nb_samples;
180  AVFrame *out_frame;
181  int chan, i;
182  int err;
183 
184  if (av_frame_is_writable(frame)) {
185  out_frame = frame;
186  } else {
187  out_frame = ff_get_audio_buffer(inlink, nb_samples);
188  if (!out_frame) {
189  av_frame_free(&frame);
190  return AVERROR(ENOMEM);
191  }
192  err = av_frame_copy_props(out_frame, frame);
193  if (err < 0) {
194  av_frame_free(&out_frame);
195  av_frame_free(&frame);
196  return err;
197  }
198  }
199 
200  for (chan = 0; chan < channels; chan++) {
201  const double *src = (double *)frame->extended_data[chan];
202  double *dst = (double *)out_frame->extended_data[chan];
203  ChanParam *cp = &s->channels[chan];
204 
205  for (i = 0; i < nb_samples; i++) {
206  update_volume(cp, fabs(src[i]));
207 
208  dst[i] = src[i] * get_volume(s, cp->volume);
209  }
210  }
211 
212  if (frame != out_frame)
213  av_frame_free(&frame);
214 
215  return ff_filter_frame(ctx->outputs[0], out_frame);
216 }
217 
218 #define MOD(a, b) (((a) >= (b)) ? (a) - (b) : (a))
219 
221 {
222  CompandContext *s = ctx->priv;
223  AVFilterLink *inlink = ctx->inputs[0];
224  const int channels = inlink->channels;
225  const int nb_samples = frame->nb_samples;
226  int chan, i, av_uninit(dindex), oindex, av_uninit(count);
227  AVFrame *out_frame = NULL;
228  int err;
229 
230  if (s->pts == AV_NOPTS_VALUE) {
231  s->pts = (frame->pts == AV_NOPTS_VALUE) ? 0 : frame->pts;
232  }
233 
234  av_assert1(channels > 0); /* would corrupt delay_count and delay_index */
235 
236  for (chan = 0; chan < channels; chan++) {
237  AVFrame *delay_frame = s->delay_frame;
238  const double *src = (double *)frame->extended_data[chan];
239  double *dbuf = (double *)delay_frame->extended_data[chan];
240  ChanParam *cp = &s->channels[chan];
241  double *dst;
242 
243  count = s->delay_count;
244  dindex = s->delay_index;
245  for (i = 0, oindex = 0; i < nb_samples; i++) {
246  const double in = src[i];
247  update_volume(cp, fabs(in));
248 
249  if (count >= s->delay_samples) {
250  if (!out_frame) {
251  out_frame = ff_get_audio_buffer(inlink, nb_samples - i);
252  if (!out_frame) {
253  av_frame_free(&frame);
254  return AVERROR(ENOMEM);
255  }
256  err = av_frame_copy_props(out_frame, frame);
257  if (err < 0) {
258  av_frame_free(&out_frame);
259  av_frame_free(&frame);
260  return err;
261  }
262  out_frame->pts = s->pts;
263  s->pts += av_rescale_q(nb_samples - i,
264  (AVRational){ 1, inlink->sample_rate },
265  inlink->time_base);
266  }
267 
268  dst = (double *)out_frame->extended_data[chan];
269  dst[oindex++] = dbuf[dindex] * get_volume(s, cp->volume);
270  } else {
271  count++;
272  }
273 
274  dbuf[dindex] = in;
275  dindex = MOD(dindex + 1, s->delay_samples);
276  }
277  }
278 
279  s->delay_count = count;
280  s->delay_index = dindex;
281 
282  av_frame_free(&frame);
283 
284  if (out_frame) {
285  err = ff_filter_frame(ctx->outputs[0], out_frame);
286  return err;
287  }
288 
289  return 0;
290 }
291 
292 static int compand_drain(AVFilterLink *outlink)
293 {
294  AVFilterContext *ctx = outlink->src;
295  CompandContext *s = ctx->priv;
296  const int channels = outlink->channels;
297  AVFrame *frame = NULL;
298  int chan, i, dindex;
299 
300  /* 2048 is to limit output frame size during drain */
301  frame = ff_get_audio_buffer(outlink, FFMIN(2048, s->delay_count));
302  if (!frame)
303  return AVERROR(ENOMEM);
304  frame->pts = s->pts;
305  s->pts += av_rescale_q(frame->nb_samples,
306  (AVRational){ 1, outlink->sample_rate }, outlink->time_base);
307 
308  av_assert0(channels > 0);
309  for (chan = 0; chan < channels; chan++) {
310  AVFrame *delay_frame = s->delay_frame;
311  double *dbuf = (double *)delay_frame->extended_data[chan];
312  double *dst = (double *)frame->extended_data[chan];
313  ChanParam *cp = &s->channels[chan];
314 
315  dindex = s->delay_index;
316  for (i = 0; i < frame->nb_samples; i++) {
317  dst[i] = dbuf[dindex] * get_volume(s, cp->volume);
318  dindex = MOD(dindex + 1, s->delay_samples);
319  }
320  }
321  s->delay_count -= frame->nb_samples;
322  s->delay_index = dindex;
323 
324  return ff_filter_frame(outlink, frame);
325 }
326 
327 static int config_output(AVFilterLink *outlink)
328 {
329  AVFilterContext *ctx = outlink->src;
330  CompandContext *s = ctx->priv;
331  const int sample_rate = outlink->sample_rate;
332  double radius = s->curve_dB * M_LN10 / 20.0;
333  char *p, *saveptr = NULL;
334  const int channels = outlink->channels;
335  int nb_attacks, nb_decays, nb_points;
336  int new_nb_items, num;
337  int i;
338  int err;
339 
340 
341  count_items(s->attacks, &nb_attacks);
342  count_items(s->decays, &nb_decays);
343  count_items(s->points, &nb_points);
344 
345  if (channels <= 0) {
346  av_log(ctx, AV_LOG_ERROR, "Invalid number of channels: %d\n", channels);
347  return AVERROR(EINVAL);
348  }
349 
350  if (nb_attacks > channels || nb_decays > channels) {
351  av_log(ctx, AV_LOG_ERROR,
352  "Number of attacks/decays bigger than number of channels.\n");
353  return AVERROR(EINVAL);
354  }
355 
356  uninit(ctx);
357 
358  s->channels = av_mallocz_array(channels, sizeof(*s->channels));
359  s->nb_segments = (nb_points + 4) * 2;
360  s->segments = av_mallocz_array(s->nb_segments, sizeof(*s->segments));
361 
362  if (!s->channels || !s->segments) {
363  uninit(ctx);
364  return AVERROR(ENOMEM);
365  }
366 
367  p = s->attacks;
368  for (i = 0, new_nb_items = 0; i < nb_attacks; i++) {
369  char *tstr = av_strtok(p, " |", &saveptr);
370  p = NULL;
371  new_nb_items += sscanf(tstr, "%lf", &s->channels[i].attack) == 1;
372  if (s->channels[i].attack < 0) {
373  uninit(ctx);
374  return AVERROR(EINVAL);
375  }
376  }
377  nb_attacks = new_nb_items;
378 
379  p = s->decays;
380  for (i = 0, new_nb_items = 0; i < nb_decays; i++) {
381  char *tstr = av_strtok(p, " |", &saveptr);
382  p = NULL;
383  new_nb_items += sscanf(tstr, "%lf", &s->channels[i].decay) == 1;
384  if (s->channels[i].decay < 0) {
385  uninit(ctx);
386  return AVERROR(EINVAL);
387  }
388  }
389  nb_decays = new_nb_items;
390 
391  if (nb_attacks != nb_decays) {
392  av_log(ctx, AV_LOG_ERROR,
393  "Number of attacks %d differs from number of decays %d.\n",
394  nb_attacks, nb_decays);
395  uninit(ctx);
396  return AVERROR(EINVAL);
397  }
398 
399  for (i = nb_decays; i < channels; i++) {
400  s->channels[i].attack = s->channels[nb_decays - 1].attack;
401  s->channels[i].decay = s->channels[nb_decays - 1].decay;
402  }
403 
404 #define S(x) s->segments[2 * ((x) + 1)]
405  p = s->points;
406  for (i = 0, new_nb_items = 0; i < nb_points; i++) {
407  char *tstr = av_strtok(p, " |", &saveptr);
408  p = NULL;
409  if (sscanf(tstr, "%lf/%lf", &S(i).x, &S(i).y) != 2) {
410  av_log(ctx, AV_LOG_ERROR,
411  "Invalid and/or missing input/output value.\n");
412  uninit(ctx);
413  return AVERROR(EINVAL);
414  }
415  if (i && S(i - 1).x > S(i).x) {
416  av_log(ctx, AV_LOG_ERROR,
417  "Transfer function input values must be increasing.\n");
418  uninit(ctx);
419  return AVERROR(EINVAL);
420  }
421  S(i).y -= S(i).x;
422  av_log(ctx, AV_LOG_DEBUG, "%d: x=%f y=%f\n", i, S(i).x, S(i).y);
423  new_nb_items++;
424  }
425  num = new_nb_items;
426 
427  /* Add 0,0 if necessary */
428  if (num == 0 || S(num - 1).x)
429  num++;
430 
431 #undef S
432 #define S(x) s->segments[2 * (x)]
433  /* Add a tail off segment at the start */
434  S(0).x = S(1).x - 2 * s->curve_dB;
435  S(0).y = S(1).y;
436  num++;
437 
438  /* Join adjacent colinear segments */
439  for (i = 2; i < num; i++) {
440  double g1 = (S(i - 1).y - S(i - 2).y) * (S(i - 0).x - S(i - 1).x);
441  double g2 = (S(i - 0).y - S(i - 1).y) * (S(i - 1).x - S(i - 2).x);
442  int j;
443 
444  if (fabs(g1 - g2))
445  continue;
446  num--;
447  for (j = --i; j < num; j++)
448  S(j) = S(j + 1);
449  }
450 
451  for (i = 0; i < s->nb_segments; i += 2) {
452  s->segments[i].y += s->gain_dB;
453  s->segments[i].x *= M_LN10 / 20;
454  s->segments[i].y *= M_LN10 / 20;
455  }
456 
457 #define L(x) s->segments[i - (x)]
458  for (i = 4; i < s->nb_segments; i += 2) {
459  double x, y, cx, cy, in1, in2, out1, out2, theta, len, r;
460 
461  L(4).a = 0;
462  L(4).b = (L(2).y - L(4).y) / (L(2).x - L(4).x);
463 
464  L(2).a = 0;
465  L(2).b = (L(0).y - L(2).y) / (L(0).x - L(2).x);
466 
467  theta = atan2(L(2).y - L(4).y, L(2).x - L(4).x);
468  len = hypot(L(2).x - L(4).x, L(2).y - L(4).y);
469  r = FFMIN(radius, len);
470  L(3).x = L(2).x - r * cos(theta);
471  L(3).y = L(2).y - r * sin(theta);
472 
473  theta = atan2(L(0).y - L(2).y, L(0).x - L(2).x);
474  len = hypot(L(0).x - L(2).x, L(0).y - L(2).y);
475  r = FFMIN(radius, len / 2);
476  x = L(2).x + r * cos(theta);
477  y = L(2).y + r * sin(theta);
478 
479  cx = (L(3).x + L(2).x + x) / 3;
480  cy = (L(3).y + L(2).y + y) / 3;
481 
482  L(2).x = x;
483  L(2).y = y;
484 
485  in1 = cx - L(3).x;
486  out1 = cy - L(3).y;
487  in2 = L(2).x - L(3).x;
488  out2 = L(2).y - L(3).y;
489  L(3).a = (out2 / in2 - out1 / in1) / (in2 - in1);
490  L(3).b = out1 / in1 - L(3).a * in1;
491  }
492  L(3).x = 0;
493  L(3).y = L(2).y;
494 
495  s->in_min_lin = exp(s->segments[1].x);
496  s->out_min_lin = exp(s->segments[1].y);
497 
498  for (i = 0; i < channels; i++) {
499  ChanParam *cp = &s->channels[i];
500 
501  if (cp->attack > 1.0 / sample_rate)
502  cp->attack = 1.0 - exp(-1.0 / (sample_rate * cp->attack));
503  else
504  cp->attack = 1.0;
505  if (cp->decay > 1.0 / sample_rate)
506  cp->decay = 1.0 - exp(-1.0 / (sample_rate * cp->decay));
507  else
508  cp->decay = 1.0;
509  cp->volume = ff_exp10(s->initial_volume / 20);
510  }
511 
512  s->delay_samples = s->delay * sample_rate;
513  if (s->delay_samples <= 0) {
515  return 0;
516  }
517 
519  if (!s->delay_frame) {
520  uninit(ctx);
521  return AVERROR(ENOMEM);
522  }
523 
524  s->delay_frame->format = outlink->format;
527 
528  err = av_frame_get_buffer(s->delay_frame, 32);
529  if (err)
530  return err;
531 
532  s->compand = compand_delay;
533  return 0;
534 }
535 
536 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
537 {
538  AVFilterContext *ctx = inlink->dst;
539  CompandContext *s = ctx->priv;
540 
541  return s->compand(ctx, frame);
542 }
543 
544 static int request_frame(AVFilterLink *outlink)
545 {
546  AVFilterContext *ctx = outlink->src;
547  CompandContext *s = ctx->priv;
548  int ret = 0;
549 
550  ret = ff_request_frame(ctx->inputs[0]);
551 
552  if (ret == AVERROR_EOF && !ctx->is_disabled && s->delay_count)
553  ret = compand_drain(outlink);
554 
555  return ret;
556 }
557 
558 static const AVFilterPad compand_inputs[] = {
559  {
560  .name = "default",
561  .type = AVMEDIA_TYPE_AUDIO,
562  .filter_frame = filter_frame,
563  },
564  { NULL }
565 };
566 
567 static const AVFilterPad compand_outputs[] = {
568  {
569  .name = "default",
570  .request_frame = request_frame,
571  .config_props = config_output,
572  .type = AVMEDIA_TYPE_AUDIO,
573  },
574  { NULL }
575 };
576 
577 
579  .name = "compand",
580  .description = NULL_IF_CONFIG_SMALL(
581  "Compress or expand audio dynamic range."),
582  .query_formats = query_formats,
583  .priv_size = sizeof(CompandContext),
584  .priv_class = &compand_class,
585  .init = init,
586  .uninit = uninit,
587  .inputs = compand_inputs,
588  .outputs = compand_outputs,
589 };
#define L(x)
static const AVFilterPad compand_inputs[]
Definition: af_compand.c:558
#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:549
char * points
Definition: af_compand.c:52
const char * s
Definition: avisynth_c.h:631
This structure describes decoded (raw) audio or video data.
Definition: frame.h:181
static const AVOption compand_options[]
Definition: af_compand.c:73
AVOption.
Definition: opt.h:245
AVFormatContext * ctx
Definition: movenc-test.c:48
static double get_volume(CompandContext *s, double in_lin)
Definition: af_compand.c:153
Main libavfilter public API header.
int64_t pts
Definition: af_compand.c:65
AVFILTER_DEFINE_CLASS(compand)
double out_min_lin
Definition: af_compand.c:56
double, planar
Definition: samplefmt.h:71
#define OFFSET(x)
Definition: af_compand.c:70
double in_min_lin
Definition: af_compand.c:55
static enum AVSampleFormat formats[]
double attack
Definition: af_compand.c:39
static const AVFilterPad compand_outputs[]
Definition: af_compand.c:567
static void update_volume(ChanParam *cp, double in)
Definition: af_compand.c:143
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:351
static av_cold int init(AVFilterContext *ctx)
Definition: af_compand.c:86
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
const char * name
Pad name.
Definition: internal.h:59
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:312
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1163
#define av_cold
Definition: attributes.h:82
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:141
float delta
AVOptions.
static int compand_delay(AVFilterContext *ctx, AVFrame *frame)
Definition: af_compand.c:220
static int query_formats(AVFilterContext *ctx)
Definition: af_compand.c:102
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:262
static AVFrame * frame
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:53
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
static int compand_nodelay(AVFilterContext *ctx, AVFrame *frame)
Definition: af_compand.c:174
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
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:568
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:65
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:154
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
const char * r
Definition: vf_curves.c:107
void * priv
private data for use by the filter
Definition: avfilter.h:319
AVFilter ff_af_compand
Definition: af_compand.c:578
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
simple assert() macros that are a bit more flexible than ISO C assert().
GLsizei count
Definition: opengl_enc.c:109
int8_t exp
Definition: eval.c:63
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:343
static int request_frame(AVFilterLink *outlink)
Definition: af_compand.c:544
ChanParam * channels
Definition: af_compand.c:54
static av_const double hypot(double x, double y)
Definition: libm.h:366
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
#define FFMIN(a, b)
Definition: common.h:96
char * decays
Definition: af_compand.c:52
CompandSegment * segments
Definition: af_compand.c:53
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:385
#define src
Definition: vp9dsp.c:530
double delay
Definition: af_compand.c:60
A list of supported channel layouts.
Definition: formats.h:85
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:242
sample_rate
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:375
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:59
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:505
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;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);returnNULL;}returnac;}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;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->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);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
Definition: log.h:67
#define A
Definition: af_compand.c:71
Filter definition.
Definition: avfilter.h:141
rational number numerator/denominator
Definition: rational.h:43
double curve_dB
Definition: af_compand.c:57
#define S(x)
const char * name
Filter name.
Definition: avfilter.h:145
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:316
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:271
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok()...
Definition: avstring.c:184
#define M_LN10
Definition: mathematics.h:37
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_compand.c:93
double gain_dB
Definition: af_compand.c:58
double decay
Definition: af_compand.c:40
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition: af_compand.c:536
static int config_output(AVFilterLink *outlink)
Definition: af_compand.c:327
static int compand_drain(AVFilterLink *outlink)
Definition: af_compand.c:292
int len
int(* compand)(AVFilterContext *ctx, AVFrame *frame)
Definition: af_compand.c:67
static void count_items(char *item_str, int *nb_items)
Definition: af_compand.c:132
char * attacks
Definition: af_compand.c:52
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:304
#define av_uninit(x)
Definition: attributes.h:149
AVFrame * delay_frame
Definition: af_compand.c:61
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:229
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
#define av_freep(p)
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
Definition: internal.h:306
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:356
double initial_volume
Definition: af_compand.c:59
double volume
Definition: af_compand.c:41
internal API functions
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition...
Definition: formats.c:410
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:225
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:235
#define MOD(a, b)
Definition: af_compand.c:218
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:556
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:565
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:240