FFmpeg
af_volume.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Stefano Sabatini
3  * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * audio volume filter
25  */
26 
28 #include "libavutil/common.h"
29 #include "libavutil/eval.h"
30 #include "libavutil/ffmath.h"
31 #include "libavutil/float_dsp.h"
32 #include "libavutil/intreadwrite.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/replaygain.h"
35 
36 #include "audio.h"
37 #include "avfilter.h"
38 #include "formats.h"
39 #include "internal.h"
40 #include "af_volume.h"
41 
42 static const char * const precision_str[] = {
43  "fixed", "float", "double"
44 };
45 
46 static const char *const var_names[] = {
47  "n", ///< frame number (starting at zero)
48  "nb_channels", ///< number of channels
49  "nb_consumed_samples", ///< number of samples consumed by the filter
50  "nb_samples", ///< number of samples in the current frame
51  "pos", ///< position in the file of the frame
52  "pts", ///< frame presentation timestamp
53  "sample_rate", ///< sample rate
54  "startpts", ///< PTS at start of stream
55  "startt", ///< time at start of stream
56  "t", ///< time in the file of the frame
57  "tb", ///< timebase
58  "volume", ///< last set value
59  NULL
60 };
61 
62 #define OFFSET(x) offsetof(VolumeContext, x)
63 #define A AV_OPT_FLAG_AUDIO_PARAM
64 #define F AV_OPT_FLAG_FILTERING_PARAM
65 #define T AV_OPT_FLAG_RUNTIME_PARAM
66 
67 static const AVOption volume_options[] = {
68  { "volume", "set volume adjustment expression",
69  OFFSET(volume_expr), AV_OPT_TYPE_STRING, { .str = "1.0" }, .flags = A|F|T },
70  { "precision", "select mathematical precision",
71  OFFSET(precision), AV_OPT_TYPE_INT, { .i64 = PRECISION_FLOAT }, PRECISION_FIXED, PRECISION_DOUBLE, A|F, "precision" },
72  { "fixed", "select 8-bit fixed-point", 0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_FIXED }, INT_MIN, INT_MAX, A|F, "precision" },
73  { "float", "select 32-bit floating-point", 0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_FLOAT }, INT_MIN, INT_MAX, A|F, "precision" },
74  { "double", "select 64-bit floating-point", 0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_DOUBLE }, INT_MIN, INT_MAX, A|F, "precision" },
75  { "eval", "specify when to evaluate expressions", OFFSET(eval_mode), AV_OPT_TYPE_INT, {.i64 = EVAL_MODE_ONCE}, 0, EVAL_MODE_NB-1, .flags = A|F, "eval" },
76  { "once", "eval volume expression once", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_ONCE}, .flags = A|F, .unit = "eval" },
77  { "frame", "eval volume expression per-frame", 0, AV_OPT_TYPE_CONST, {.i64=EVAL_MODE_FRAME}, .flags = A|F, .unit = "eval" },
78  { "replaygain", "Apply replaygain side data when present",
79  OFFSET(replaygain), AV_OPT_TYPE_INT, { .i64 = REPLAYGAIN_DROP }, REPLAYGAIN_DROP, REPLAYGAIN_ALBUM, A|F, "replaygain" },
80  { "drop", "replaygain side data is dropped", 0, AV_OPT_TYPE_CONST, { .i64 = REPLAYGAIN_DROP }, 0, 0, A|F, "replaygain" },
81  { "ignore", "replaygain side data is ignored", 0, AV_OPT_TYPE_CONST, { .i64 = REPLAYGAIN_IGNORE }, 0, 0, A|F, "replaygain" },
82  { "track", "track gain is preferred", 0, AV_OPT_TYPE_CONST, { .i64 = REPLAYGAIN_TRACK }, 0, 0, A|F, "replaygain" },
83  { "album", "album gain is preferred", 0, AV_OPT_TYPE_CONST, { .i64 = REPLAYGAIN_ALBUM }, 0, 0, A|F, "replaygain" },
84  { "replaygain_preamp", "Apply replaygain pre-amplification",
85  OFFSET(replaygain_preamp), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, -15.0, 15.0, A|F },
86  { "replaygain_noclip", "Apply replaygain clipping prevention",
87  OFFSET(replaygain_noclip), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, A|F },
88  { NULL }
89 };
90 
91 AVFILTER_DEFINE_CLASS(volume);
92 
93 static int set_expr(AVExpr **pexpr, const char *expr, void *log_ctx)
94 {
95  int ret;
96  AVExpr *old = NULL;
97 
98  if (*pexpr)
99  old = *pexpr;
100  ret = av_expr_parse(pexpr, expr, var_names,
101  NULL, NULL, NULL, NULL, 0, log_ctx);
102  if (ret < 0) {
103  av_log(log_ctx, AV_LOG_ERROR,
104  "Error when evaluating the volume expression '%s'\n", expr);
105  *pexpr = old;
106  return ret;
107  }
108 
109  av_expr_free(old);
110  return 0;
111 }
112 
114 {
115  VolumeContext *vol = ctx->priv;
116 
117  vol->fdsp = avpriv_float_dsp_alloc(0);
118  if (!vol->fdsp)
119  return AVERROR(ENOMEM);
120 
121  return set_expr(&vol->volume_pexpr, vol->volume_expr, ctx);
122 }
123 
125 {
126  VolumeContext *vol = ctx->priv;
128  av_opt_free(vol);
129  av_freep(&vol->fdsp);
130 }
131 
133 {
134  VolumeContext *vol = ctx->priv;
137  static const enum AVSampleFormat sample_fmts[][7] = {
138  [PRECISION_FIXED] = {
146  },
147  [PRECISION_FLOAT] = {
150  AV_SAMPLE_FMT_NONE
151  },
152  [PRECISION_DOUBLE] = {
155  AV_SAMPLE_FMT_NONE
156  }
157  };
158  int ret;
159 
160  layouts = ff_all_channel_counts();
161  if (!layouts)
162  return AVERROR(ENOMEM);
163  ret = ff_set_common_channel_layouts(ctx, layouts);
164  if (ret < 0)
165  return ret;
166 
167  formats = ff_make_format_list(sample_fmts[vol->precision]);
168  if (!formats)
169  return AVERROR(ENOMEM);
170  ret = ff_set_common_formats(ctx, formats);
171  if (ret < 0)
172  return ret;
173 
174  formats = ff_all_samplerates();
175  if (!formats)
176  return AVERROR(ENOMEM);
177  return ff_set_common_samplerates(ctx, formats);
178 }
179 
180 static inline void scale_samples_u8(uint8_t *dst, const uint8_t *src,
181  int nb_samples, int volume)
182 {
183  int i;
184  for (i = 0; i < nb_samples; i++)
185  dst[i] = av_clip_uint8(((((int64_t)src[i] - 128) * volume + 128) >> 8) + 128);
186 }
187 
188 static inline void scale_samples_u8_small(uint8_t *dst, const uint8_t *src,
189  int nb_samples, int volume)
190 {
191  int i;
192  for (i = 0; i < nb_samples; i++)
193  dst[i] = av_clip_uint8((((src[i] - 128) * volume + 128) >> 8) + 128);
194 }
195 
196 static inline void scale_samples_s16(uint8_t *dst, const uint8_t *src,
197  int nb_samples, int volume)
198 {
199  int i;
200  int16_t *smp_dst = (int16_t *)dst;
201  const int16_t *smp_src = (const int16_t *)src;
202  for (i = 0; i < nb_samples; i++)
203  smp_dst[i] = av_clip_int16(((int64_t)smp_src[i] * volume + 128) >> 8);
204 }
205 
206 static inline void scale_samples_s16_small(uint8_t *dst, const uint8_t *src,
207  int nb_samples, int volume)
208 {
209  int i;
210  int16_t *smp_dst = (int16_t *)dst;
211  const int16_t *smp_src = (const int16_t *)src;
212  for (i = 0; i < nb_samples; i++)
213  smp_dst[i] = av_clip_int16((smp_src[i] * volume + 128) >> 8);
214 }
215 
216 static inline void scale_samples_s32(uint8_t *dst, const uint8_t *src,
217  int nb_samples, int volume)
218 {
219  int i;
220  int32_t *smp_dst = (int32_t *)dst;
221  const int32_t *smp_src = (const int32_t *)src;
222  for (i = 0; i < nb_samples; i++)
223  smp_dst[i] = av_clipl_int32((((int64_t)smp_src[i] * volume + 128) >> 8));
224 }
225 
227 {
228  vol->samples_align = 1;
229 
230  switch (av_get_packed_sample_fmt(vol->sample_fmt)) {
231  case AV_SAMPLE_FMT_U8:
232  if (vol->volume_i < 0x1000000)
234  else
236  break;
237  case AV_SAMPLE_FMT_S16:
238  if (vol->volume_i < 0x10000)
240  else
242  break;
243  case AV_SAMPLE_FMT_S32:
245  break;
246  case AV_SAMPLE_FMT_FLT:
247  vol->samples_align = 4;
248  break;
249  case AV_SAMPLE_FMT_DBL:
250  vol->samples_align = 8;
251  break;
252  }
253 
254  if (ARCH_X86)
255  ff_volume_init_x86(vol);
256 }
257 
259 {
260  VolumeContext *vol = ctx->priv;
261 
262  vol->volume = av_expr_eval(vol->volume_pexpr, vol->var_values, NULL);
263  if (isnan(vol->volume)) {
264  if (vol->eval_mode == EVAL_MODE_ONCE) {
265  av_log(ctx, AV_LOG_ERROR, "Invalid value NaN for volume\n");
266  return AVERROR(EINVAL);
267  } else {
268  av_log(ctx, AV_LOG_WARNING, "Invalid value NaN for volume, setting to 0\n");
269  vol->volume = 0;
270  }
271  }
272  vol->var_values[VAR_VOLUME] = vol->volume;
273 
274  av_log(ctx, AV_LOG_VERBOSE, "n:%f t:%f pts:%f precision:%s ",
275  vol->var_values[VAR_N], vol->var_values[VAR_T], vol->var_values[VAR_PTS],
276  precision_str[vol->precision]);
277 
278  if (vol->precision == PRECISION_FIXED) {
279  vol->volume_i = (int)(vol->volume * 256 + 0.5);
280  vol->volume = vol->volume_i / 256.0;
281  av_log(ctx, AV_LOG_VERBOSE, "volume_i:%d/255 ", vol->volume_i);
282  }
283  av_log(ctx, AV_LOG_VERBOSE, "volume:%f volume_dB:%f\n",
284  vol->volume, 20.0*log10(vol->volume));
285 
286  volume_init(vol);
287  return 0;
288 }
289 
290 static int config_output(AVFilterLink *outlink)
291 {
292  AVFilterContext *ctx = outlink->src;
293  VolumeContext *vol = ctx->priv;
294  AVFilterLink *inlink = ctx->inputs[0];
295 
296  vol->sample_fmt = inlink->format;
297  vol->channels = inlink->channels;
298  vol->planes = av_sample_fmt_is_planar(inlink->format) ? vol->channels : 1;
299 
300  vol->var_values[VAR_N] =
302  vol->var_values[VAR_NB_SAMPLES] =
303  vol->var_values[VAR_POS] =
304  vol->var_values[VAR_PTS] =
305  vol->var_values[VAR_STARTPTS] =
306  vol->var_values[VAR_STARTT] =
307  vol->var_values[VAR_T] =
308  vol->var_values[VAR_VOLUME] = NAN;
309 
310  vol->var_values[VAR_NB_CHANNELS] = inlink->channels;
311  vol->var_values[VAR_TB] = av_q2d(inlink->time_base);
312  vol->var_values[VAR_SAMPLE_RATE] = inlink->sample_rate;
313 
314  av_log(inlink->src, AV_LOG_VERBOSE, "tb:%f sample_rate:%f nb_channels:%f\n",
315  vol->var_values[VAR_TB],
318 
319  return set_volume(ctx);
320 }
321 
322 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
323  char *res, int res_len, int flags)
324 {
325  VolumeContext *vol = ctx->priv;
326  int ret = AVERROR(ENOSYS);
327 
328  if (!strcmp(cmd, "volume")) {
329  if ((ret = set_expr(&vol->volume_pexpr, args, ctx)) < 0)
330  return ret;
331  if (vol->eval_mode == EVAL_MODE_ONCE)
332  set_volume(ctx);
333  }
334 
335  return ret;
336 }
337 
338 #define D2TS(d) (isnan(d) ? AV_NOPTS_VALUE : (int64_t)(d))
339 #define TS2D(ts) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts))
340 #define TS2T(ts, tb) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts)*av_q2d(tb))
341 
343 {
344  AVFilterContext *ctx = inlink->dst;
345  VolumeContext *vol = inlink->dst->priv;
346  AVFilterLink *outlink = inlink->dst->outputs[0];
347  int nb_samples = buf->nb_samples;
348  AVFrame *out_buf;
349  int64_t pos;
351  int ret;
352 
353  if (sd && vol->replaygain != REPLAYGAIN_IGNORE) {
354  if (vol->replaygain != REPLAYGAIN_DROP) {
355  AVReplayGain *replaygain = (AVReplayGain*)sd->data;
356  int32_t gain = 100000;
357  uint32_t peak = 100000;
358  float g, p;
359 
360  if (vol->replaygain == REPLAYGAIN_TRACK &&
361  replaygain->track_gain != INT32_MIN) {
362  gain = replaygain->track_gain;
363 
364  if (replaygain->track_peak != 0)
365  peak = replaygain->track_peak;
366  } else if (replaygain->album_gain != INT32_MIN) {
367  gain = replaygain->album_gain;
368 
369  if (replaygain->album_peak != 0)
370  peak = replaygain->album_peak;
371  } else {
372  av_log(inlink->dst, AV_LOG_WARNING, "Both ReplayGain gain "
373  "values are unknown.\n");
374  }
375  g = gain / 100000.0f;
376  p = peak / 100000.0f;
377 
378  av_log(inlink->dst, AV_LOG_VERBOSE,
379  "Using gain %f dB from replaygain side data.\n", g);
380 
381  vol->volume = ff_exp10((g + vol->replaygain_preamp) / 20);
382  if (vol->replaygain_noclip)
383  vol->volume = FFMIN(vol->volume, 1.0 / p);
384  vol->volume_i = (int)(vol->volume * 256 + 0.5);
385 
386  volume_init(vol);
387  }
389  }
390 
391  if (isnan(vol->var_values[VAR_STARTPTS])) {
392  vol->var_values[VAR_STARTPTS] = TS2D(buf->pts);
393  vol->var_values[VAR_STARTT ] = TS2T(buf->pts, inlink->time_base);
394  }
395  vol->var_values[VAR_PTS] = TS2D(buf->pts);
396  vol->var_values[VAR_T ] = TS2T(buf->pts, inlink->time_base);
397  vol->var_values[VAR_N ] = inlink->frame_count_out;
398 
399  pos = buf->pkt_pos;
400  vol->var_values[VAR_POS] = pos == -1 ? NAN : pos;
401  if (vol->eval_mode == EVAL_MODE_FRAME)
402  set_volume(ctx);
403 
404  if (vol->volume == 1.0 || vol->volume_i == 256) {
405  out_buf = buf;
406  goto end;
407  }
408 
409  /* do volume scaling in-place if input buffer is writable */
410  if (av_frame_is_writable(buf)
411  && (vol->precision != PRECISION_FIXED || vol->volume_i > 0)) {
412  out_buf = buf;
413  } else {
414  out_buf = ff_get_audio_buffer(outlink, nb_samples);
415  if (!out_buf) {
416  av_frame_free(&buf);
417  return AVERROR(ENOMEM);
418  }
419  ret = av_frame_copy_props(out_buf, buf);
420  if (ret < 0) {
421  av_frame_free(&out_buf);
422  av_frame_free(&buf);
423  return ret;
424  }
425  }
426 
427  if (vol->precision != PRECISION_FIXED || vol->volume_i > 0) {
428  int p, plane_samples;
429 
431  plane_samples = FFALIGN(nb_samples, vol->samples_align);
432  else
433  plane_samples = FFALIGN(nb_samples * vol->channels, vol->samples_align);
434 
435  if (vol->precision == PRECISION_FIXED) {
436  for (p = 0; p < vol->planes; p++) {
437  vol->scale_samples(out_buf->extended_data[p],
438  buf->extended_data[p], plane_samples,
439  vol->volume_i);
440  }
442  for (p = 0; p < vol->planes; p++) {
443  vol->fdsp->vector_fmul_scalar((float *)out_buf->extended_data[p],
444  (const float *)buf->extended_data[p],
445  vol->volume, plane_samples);
446  }
447  } else {
448  for (p = 0; p < vol->planes; p++) {
449  vol->fdsp->vector_dmul_scalar((double *)out_buf->extended_data[p],
450  (const double *)buf->extended_data[p],
451  vol->volume, plane_samples);
452  }
453  }
454  }
455 
456  emms_c();
457 
458  if (buf != out_buf)
459  av_frame_free(&buf);
460 
461 end:
463  return ff_filter_frame(outlink, out_buf);
464 }
465 
467  {
468  .name = "default",
469  .type = AVMEDIA_TYPE_AUDIO,
470  .filter_frame = filter_frame,
471  },
472  { NULL }
473 };
474 
476  {
477  .name = "default",
478  .type = AVMEDIA_TYPE_AUDIO,
479  .config_props = config_output,
480  },
481  { NULL }
482 };
483 
485  .name = "volume",
486  .description = NULL_IF_CONFIG_SMALL("Change input volume."),
487  .query_formats = query_formats,
488  .priv_size = sizeof(VolumeContext),
489  .priv_class = &volume_class,
490  .init = init,
491  .uninit = uninit,
492  .inputs = avfilter_af_volume_inputs,
493  .outputs = avfilter_af_volume_outputs,
496 };
int replaygain
Definition: af_volume.h:77
float, planar
Definition: samplefmt.h:69
#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
#define A
Definition: af_volume.c:63
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
AVOption.
Definition: opt.h:246
int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder
Definition: frame.h:566
Definition: aeval.c:48
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
Main libavfilter public API header.
const char * g
Definition: vf_curves.c:115
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_volume.c:124
static const char *const var_names[]
Definition: af_volume.c:46
static av_cold void volume_init(VolumeContext *vol)
Definition: af_volume.c:226
double, planar
Definition: samplefmt.h:70
static av_cold int init(AVFilterContext *ctx)
Definition: af_volume.c:113
static int set_volume(AVFilterContext *ctx)
Definition: af_volume.c:258
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition: eval.c:685
double var_values[VAR_VARS_NB]
Definition: af_volume.h:75
#define src
Definition: vp8dsp.c:254
#define TS2T(ts, tb)
Definition: af_volume.c:340
uint32_t track_peak
Peak track amplitude, with 100000 representing full scale (but values may overflow).
Definition: replaygain.h:39
AVFilter ff_af_volume
Definition: af_volume.c:484
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:734
const char * volume_expr
Definition: af_volume.h:73
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:125
double replaygain_preamp
Definition: af_volume.h:78
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:1075
uint8_t
#define av_cold
Definition: attributes.h:82
AV_SAMPLE_FMT_U8
AVOptions.
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:388
Definition: eval.c:157
Structure to hold side data for an AVFrame.
Definition: frame.h:201
int samples_align
Definition: af_volume.h:88
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
signed 32 bits
Definition: samplefmt.h:62
#define FFALIGN(x, a)
Definition: macros.h:48
int32_t album_gain
Same as track_gain, but for the whole album.
Definition: replaygain.h:43
#define av_log(a,...)
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:112
static void scale_samples_s32(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
Definition: af_volume.c:216
A filter pad used for either input or output.
Definition: internal.h:54
void(* vector_dmul_scalar)(double *dst, const double *src, double mul, int len)
Multiply a vector of double by a scalar double.
Definition: float_dsp.h:100
audio volume filter
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
Definition: ffmath.h:42
#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:569
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
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
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
void * priv
private data for use by the filter
Definition: avfilter.h:353
AVFILTER_DEFINE_CLASS(volume)
static int query_formats(AVFilterContext *ctx)
Definition: af_volume.c:132
#define F
Definition: af_volume.c:64
static void scale_samples_s16(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
Definition: af_volume.c:196
audio channel layout utility functions
#define NAN
Definition: mathematics.h:64
#define FFMIN(a, b)
Definition: common.h:96
signed 32 bits, planar
Definition: samplefmt.h:68
static void scale_samples_u8_small(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
Definition: af_volume.c:188
int replaygain_noclip
Definition: af_volume.h:79
int32_t
AVFormatContext * ctx
Definition: movenc.c:48
Definition: aeval.c:51
unsigned 8 bits, planar
Definition: samplefmt.h:66
static const AVFilterPad avfilter_af_volume_outputs[]
Definition: af_volume.c:475
static void scale_samples_u8(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
Definition: af_volume.c:180
#define TS2D(ts)
Definition: af_volume.c:339
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static const char *const precision_str[]
Definition: af_volume.c:42
A list of supported channel layouts.
Definition: formats.h:85
if(ret)
double volume
Definition: af_volume.h:80
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:368
enum AVSampleFormat sample_fmt
Definition: af_volume.h:84
AVFloatDSPContext * fdsp
Definition: af_volume.h:70
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:336
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
uint8_t * data
Definition: frame.h:203
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
Definition: frame.c:805
void * buf
Definition: avisynth_c.h:766
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 inputs
Filter definition.
Definition: avfilter.h:144
#define isnan(x)
Definition: libm.h:340
AVExpr * volume_pexpr
Definition: af_volume.h:74
void(* vector_fmul_scalar)(float *dst, const float *src, float mul, int len)
Multiply a vector of floats by a scalar float.
Definition: float_dsp.h:85
const char * name
Filter name.
Definition: avfilter.h:148
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_volume.c:322
static const AVOption volume_options[]
Definition: af_volume.c:67
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:394
static void scale_samples_s16_small(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
Definition: af_volume.c:206
#define flags(name, subs,...)
Definition: cbs_av1.c:564
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
internal math functions header
int
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1612
void ff_volume_init_x86(VolumeContext *vol)
static const AVFilterPad avfilter_af_volume_inputs[]
Definition: af_volume.c:466
common internal and external API header
enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt)
Get the packed alternative form of the given sample format.
Definition: samplefmt.c:75
signed 16 bits
Definition: samplefmt.h:61
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: af_volume.c:342
static int set_expr(AVExpr **pexpr, const char *expr, void *log_ctx)
Definition: af_volume.c:93
uint32_t album_peak
Same as track_peak, but for the whole album,.
Definition: replaygain.h:47
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:766
#define OFFSET(x)
Definition: af_volume.c:62
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:338
#define T
Definition: af_volume.c:65
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
#define av_freep(p)
signed 16 bits, planar
Definition: samplefmt.h:67
int32_t track_gain
Track replay gain in microbels (divide by 100000 to get the value in dB).
Definition: replaygain.h:34
formats
Definition: signature.h:48
ReplayGain information in the form of the AVReplayGain struct.
Definition: frame.h:76
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
ReplayGain information (see http://wiki.hydrogenaudio.org/index.php?title=ReplayGain_1.0_specification).
Definition: replaygain.h:29
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:361
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:557
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:654
void(* scale_samples)(uint8_t *dst, const uint8_t *src, int nb_samples, int volume)
Definition: af_volume.h:86
simple arithmetic expression evaluator
static int config_output(AVFilterLink *outlink)
Definition: af_volume.c:290