FFmpeg
af_aemphasis.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2010 Krzysztof Foltman, Markus Schmidt, Thor Harald Johansen, Damien Zammit and others
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/opt.h"
22 #include "avfilter.h"
23 #include "internal.h"
24 #include "audio.h"
25 
26 typedef struct BiquadCoeffs {
27  double a0, a1, a2, b1, b2;
28 } BiquadCoeffs;
29 
30 typedef struct RIAACurve {
34 } RIAACurve;
35 
36 typedef struct AudioEmphasisContext {
37  const AVClass *class;
38  int mode, type;
40 
42 
45 
46 #define OFFSET(x) offsetof(AudioEmphasisContext, x)
47 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
48 
49 static const AVOption aemphasis_options[] = {
50  { "level_in", "set input gain", OFFSET(level_in), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 64, FLAGS },
51  { "level_out", "set output gain", OFFSET(level_out), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 64, FLAGS },
52  { "mode", "set filter mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "mode" },
53  { "reproduction", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "mode" },
54  { "production", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "mode" },
55  { "type", "set filter type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=4}, 0, 8, FLAGS, "type" },
56  { "col", "Columbia", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "type" },
57  { "emi", "EMI", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "type" },
58  { "bsi", "BSI (78RPM)", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "type" },
59  { "riaa", "RIAA", 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, FLAGS, "type" },
60  { "cd", "Compact Disc (CD)", 0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, FLAGS, "type" },
61  { "50fm", "50µs (FM)", 0, AV_OPT_TYPE_CONST, {.i64=5}, 0, 0, FLAGS, "type" },
62  { "75fm", "75µs (FM)", 0, AV_OPT_TYPE_CONST, {.i64=6}, 0, 0, FLAGS, "type" },
63  { "50kf", "50µs (FM-KF)", 0, AV_OPT_TYPE_CONST, {.i64=7}, 0, 0, FLAGS, "type" },
64  { "75kf", "75µs (FM-KF)", 0, AV_OPT_TYPE_CONST, {.i64=8}, 0, 0, FLAGS, "type" },
65  { NULL }
66 };
67 
68 AVFILTER_DEFINE_CLASS(aemphasis);
69 
70 static inline void biquad_process(BiquadCoeffs *bq, double *dst, const double *src, int nb_samples,
71  double *w, double level_in, double level_out)
72 {
73  const double a0 = bq->a0;
74  const double a1 = bq->a1;
75  const double a2 = bq->a2;
76  const double b1 = bq->b1;
77  const double b2 = bq->b2;
78  double w1 = w[0];
79  double w2 = w[1];
80 
81  for (int i = 0; i < nb_samples; i++) {
82  double n = src[i] * level_in;
83  double tmp = n - w1 * b1 - w2 * b2;
84  double out = tmp * a0 + w1 * a1 + w2 * a2;
85 
86  w2 = w1;
87  w1 = tmp;
88 
89  dst[i] = out * level_out;
90  }
91 
92  w[0] = w1;
93  w[1] = w2;
94 }
95 
96 typedef struct ThreadData {
97  AVFrame *in, *out;
98 } ThreadData;
99 
100 static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
101 {
102  AudioEmphasisContext *s = ctx->priv;
103  const double level_out = s->level_out;
104  const double level_in = s->level_in;
105  ThreadData *td = arg;
106  AVFrame *out = td->out;
107  AVFrame *in = td->in;
108  const int start = (in->channels * jobnr) / nb_jobs;
109  const int end = (in->channels * (jobnr+1)) / nb_jobs;
110 
111  for (int ch = start; ch < end; ch++) {
112  const double *src = (const double *)in->extended_data[ch];
113  double *w = (double *)s->w->extended_data[ch];
114  double *dst = (double *)out->extended_data[ch];
115 
116  if (s->rc.use_brickw) {
117  biquad_process(&s->rc.brickw, dst, src, in->nb_samples, w + 2, level_in, 1.);
118  biquad_process(&s->rc.r1, dst, dst, in->nb_samples, w, 1., level_out);
119  } else {
120  biquad_process(&s->rc.r1, dst, src, in->nb_samples, w, level_in, level_out);
121  }
122  }
123 
124  return 0;
125 }
126 
128 {
129  AVFilterContext *ctx = inlink->dst;
130  AVFilterLink *outlink = ctx->outputs[0];
131  ThreadData td;
132  AVFrame *out;
133 
134  if (av_frame_is_writable(in)) {
135  out = in;
136  } else {
137  out = ff_get_audio_buffer(outlink, in->nb_samples);
138  if (!out) {
139  av_frame_free(&in);
140  return AVERROR(ENOMEM);
141  }
143  }
144 
145  td.in = in; td.out = out;
146  ctx->internal->execute(ctx, filter_channels, &td, NULL, FFMIN(inlink->channels,
148 
149  if (in != out)
150  av_frame_free(&in);
151  return ff_filter_frame(outlink, out);
152 }
153 
155 {
158  static const enum AVSampleFormat sample_fmts[] = {
161  };
162  int ret;
163 
165  if (!layouts)
166  return AVERROR(ENOMEM);
168  if (ret < 0)
169  return ret;
170 
172  if (!formats)
173  return AVERROR(ENOMEM);
175  if (ret < 0)
176  return ret;
177 
179  if (!formats)
180  return AVERROR(ENOMEM);
182 }
183 
184 static inline void set_highshelf_rbj(BiquadCoeffs *bq, double freq, double q, double peak, double sr)
185 {
186  double A = sqrt(peak);
187  double w0 = freq * 2 * M_PI / sr;
188  double alpha = sin(w0) / (2 * q);
189  double cw0 = cos(w0);
190  double tmp = 2 * sqrt(A) * alpha;
191  double b0 = 0, ib0 = 0;
192 
193  bq->a0 = A*( (A+1) + (A-1)*cw0 + tmp);
194  bq->a1 = -2*A*( (A-1) + (A+1)*cw0);
195  bq->a2 = A*( (A+1) + (A-1)*cw0 - tmp);
196  b0 = (A+1) - (A-1)*cw0 + tmp;
197  bq->b1 = 2*( (A-1) - (A+1)*cw0);
198  bq->b2 = (A+1) - (A-1)*cw0 - tmp;
199 
200  ib0 = 1 / b0;
201  bq->b1 *= ib0;
202  bq->b2 *= ib0;
203  bq->a0 *= ib0;
204  bq->a1 *= ib0;
205  bq->a2 *= ib0;
206 }
207 
208 static inline void set_lp_rbj(BiquadCoeffs *bq, double fc, double q, double sr, double gain)
209 {
210  double omega = 2.0 * M_PI * fc / sr;
211  double sn = sin(omega);
212  double cs = cos(omega);
213  double alpha = sn/(2 * q);
214  double inv = 1.0/(1.0 + alpha);
215 
216  bq->a2 = bq->a0 = gain * inv * (1.0 - cs) * 0.5;
217  bq->a1 = bq->a0 + bq->a0;
218  bq->b1 = (-2.0 * cs * inv);
219  bq->b2 = ((1.0 - alpha) * inv);
220 }
221 
222 static double freq_gain(BiquadCoeffs *c, double freq, double sr)
223 {
224  double zr, zi;
225 
226  freq *= 2.0 * M_PI / sr;
227  zr = cos(freq);
228  zi = -sin(freq);
229 
230  /* |(a0 + a1*z + a2*z^2)/(1 + b1*z + b2*z^2)| */
231  return hypot(c->a0 + c->a1*zr + c->a2*(zr*zr-zi*zi), c->a1*zi + 2*c->a2*zr*zi) /
232  hypot(1 + c->b1*zr + c->b2*(zr*zr-zi*zi), c->b1*zi + 2*c->b2*zr*zi);
233 }
234 
236 {
237  double i, j, k, g, t, a0, a1, a2, b1, b2, tau1, tau2, tau3;
238  double cutfreq, gain1kHz, gc, sr = inlink->sample_rate;
239  AVFilterContext *ctx = inlink->dst;
240  AudioEmphasisContext *s = ctx->priv;
241  BiquadCoeffs coeffs;
242 
243  if (!s->w)
244  s->w = ff_get_audio_buffer(inlink, 4);
245  if (!s->w)
246  return AVERROR(ENOMEM);
247 
248  switch (s->type) {
249  case 0: //"Columbia"
250  i = 100.;
251  j = 500.;
252  k = 1590.;
253  break;
254  case 1: //"EMI"
255  i = 70.;
256  j = 500.;
257  k = 2500.;
258  break;
259  case 2: //"BSI(78rpm)"
260  i = 50.;
261  j = 353.;
262  k = 3180.;
263  break;
264  case 3: //"RIAA"
265  default:
266  tau1 = 0.003180;
267  tau2 = 0.000318;
268  tau3 = 0.000075;
269  i = 1. / (2. * M_PI * tau1);
270  j = 1. / (2. * M_PI * tau2);
271  k = 1. / (2. * M_PI * tau3);
272  break;
273  case 4: //"CD Mastering"
274  tau1 = 0.000050;
275  tau2 = 0.000015;
276  tau3 = 0.0000001;// 1.6MHz out of audible range for null impact
277  i = 1. / (2. * M_PI * tau1);
278  j = 1. / (2. * M_PI * tau2);
279  k = 1. / (2. * M_PI * tau3);
280  break;
281  case 5: //"50µs FM (Europe)"
282  tau1 = 0.000050;
283  tau2 = tau1 / 20;// not used
284  tau3 = tau1 / 50;//
285  i = 1. / (2. * M_PI * tau1);
286  j = 1. / (2. * M_PI * tau2);
287  k = 1. / (2. * M_PI * tau3);
288  break;
289  case 6: //"75µs FM (US)"
290  tau1 = 0.000075;
291  tau2 = tau1 / 20;// not used
292  tau3 = tau1 / 50;//
293  i = 1. / (2. * M_PI * tau1);
294  j = 1. / (2. * M_PI * tau2);
295  k = 1. / (2. * M_PI * tau3);
296  break;
297  }
298 
299  i *= 2 * M_PI;
300  j *= 2 * M_PI;
301  k *= 2 * M_PI;
302 
303  t = 1. / sr;
304 
305  //swap a1 b1, a2 b2
306  if (s->type == 7 || s->type == 8) {
307  double tau = (s->type == 7 ? 0.000050 : 0.000075);
308  double f = 1.0 / (2 * M_PI * tau);
309  double nyq = sr * 0.5;
310  double gain = sqrt(1.0 + nyq * nyq / (f * f)); // gain at Nyquist
311  double cfreq = sqrt((gain - 1.0) * f * f); // frequency
312  double q = 1.0;
313 
314  if (s->type == 8)
315  q = pow((sr / 3269.0) + 19.5, -0.25); // somewhat poor curve-fit
316  if (s->type == 7)
317  q = pow((sr / 4750.0) + 19.5, -0.25);
318  if (s->mode == 0)
319  set_highshelf_rbj(&s->rc.r1, cfreq, q, 1. / gain, sr);
320  else
321  set_highshelf_rbj(&s->rc.r1, cfreq, q, gain, sr);
322  s->rc.use_brickw = 0;
323  } else {
324  s->rc.use_brickw = 1;
325  if (s->mode == 0) { // Reproduction
326  g = 1. / (4.+2.*i*t+2.*k*t+i*k*t*t);
327  a0 = (2.*t+j*t*t)*g;
328  a1 = (2.*j*t*t)*g;
329  a2 = (-2.*t+j*t*t)*g;
330  b1 = (-8.+2.*i*k*t*t)*g;
331  b2 = (4.-2.*i*t-2.*k*t+i*k*t*t)*g;
332  } else { // Production
333  g = 1. / (2.*t+j*t*t);
334  a0 = (4.+2.*i*t+2.*k*t+i*k*t*t)*g;
335  a1 = (-8.+2.*i*k*t*t)*g;
336  a2 = (4.-2.*i*t-2.*k*t+i*k*t*t)*g;
337  b1 = (2.*j*t*t)*g;
338  b2 = (-2.*t+j*t*t)*g;
339  }
340 
341  coeffs.a0 = a0;
342  coeffs.a1 = a1;
343  coeffs.a2 = a2;
344  coeffs.b1 = b1;
345  coeffs.b2 = b2;
346 
347  // the coeffs above give non-normalized value, so it should be normalized to produce 0dB at 1 kHz
348  // find actual gain
349  // Note: for FM emphasis, use 100 Hz for normalization instead
350  gain1kHz = freq_gain(&coeffs, 1000.0, sr);
351  // divide one filter's x[n-m] coefficients by that value
352  gc = 1.0 / gain1kHz;
353  s->rc.r1.a0 = coeffs.a0 * gc;
354  s->rc.r1.a1 = coeffs.a1 * gc;
355  s->rc.r1.a2 = coeffs.a2 * gc;
356  s->rc.r1.b1 = coeffs.b1;
357  s->rc.r1.b2 = coeffs.b2;
358  }
359 
360  cutfreq = FFMIN(0.45 * sr, 21000.);
361  set_lp_rbj(&s->rc.brickw, cutfreq, 0.707, sr, 1.);
362 
363  return 0;
364 }
365 
366 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
367  char *res, int res_len, int flags)
368 {
369  int ret;
370 
371  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
372  if (ret < 0)
373  return ret;
374 
375  return config_input(ctx->inputs[0]);
376 }
377 
379 {
380  AudioEmphasisContext *s = ctx->priv;
381 
382  av_frame_free(&s->w);
383 }
384 
386  {
387  .name = "default",
388  .type = AVMEDIA_TYPE_AUDIO,
389  .config_props = config_input,
390  .filter_frame = filter_frame,
391  },
392  { NULL }
393 };
394 
396  {
397  .name = "default",
398  .type = AVMEDIA_TYPE_AUDIO,
399  },
400  { NULL }
401 };
402 
404  .name = "aemphasis",
405  .description = NULL_IF_CONFIG_SMALL("Audio emphasis."),
406  .priv_size = sizeof(AudioEmphasisContext),
407  .priv_class = &aemphasis_class,
408  .uninit = uninit,
415 };
formats
formats
Definition: signature.h:48
biquad_process
static void biquad_process(BiquadCoeffs *bq, double *dst, const double *src, int nb_samples, double *w, double level_in, double level_out)
Definition: af_aemphasis.c:70
ff_get_audio_buffer
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:86
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:86
td
#define td
Definition: regdef.h:70
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
out
FILE * out
Definition: movenc.c:54
freq_gain
static double freq_gain(BiquadCoeffs *c, double freq, double sr)
Definition: af_aemphasis.c:222
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1096
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:925
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
OFFSET
#define OFFSET(x)
Definition: af_aemphasis.c:46
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
ff_all_channel_counts
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition.
Definition: formats.c:436
AudioConvert::channels
int channels
Definition: audio_convert.c:54
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:27
w
uint8_t w
Definition: llviddspenc.c:39
AVOption
AVOption.
Definition: opt.h:248
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_aemphasis.c:127
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(aemphasis)
fc
#define fc(width, name, range_min, range_max)
Definition: cbs_av1.c:551
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:149
ThreadData::out
AVFrame * out
Definition: af_adeclick.c:502
AVFormatContext::internal
AVFormatInternal * internal
An opaque field for libavformat internal usage.
Definition: avformat.h:1699
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:65
BiquadCoeffs::a1
double a1
Definition: af_aemphasis.c:27
A
#define A(x)
Definition: vp56_arith.h:28
BiquadCoeffs
Definition: af_acrossover.c:48
b1
static double b1(void *priv, double x, double y)
Definition: vf_xfade.c:1665
BiquadCoeffs::a2
double a2
Definition: af_aemphasis.c:27
AudioEmphasisContext::type
int type
Definition: af_aemphasis.c:38
AudioEmphasisContext::mode
int mode
Definition: af_aemphasis.c:38
BiquadCoeffs::b2
double b2
Definition: af_aemphasis.c:27
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
a1
#define a1
Definition: regdef.h:47
av_cold
#define av_cold
Definition: attributes.h:90
ff_set_common_formats
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:587
aemphasis_options
static const AVOption aemphasis_options[]
Definition: af_aemphasis.c:49
s
#define s(width, name)
Definition: cbs_vp9.c:257
g
const char * g
Definition: vf_curves.c:117
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_aemphasis.c:366
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
avfilter_af_aemphasis_inputs
static const AVFilterPad avfilter_af_aemphasis_inputs[]
Definition: af_aemphasis.c:385
ctx
AVFormatContext * ctx
Definition: movenc.c:48
f
#define f(width, name)
Definition: cbs_vp9.c:255
arg
const char * arg
Definition: jacosubdec.c:66
if
if(ret)
Definition: filter_design.txt:179
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
AudioEmphasisContext::w
AVFrame * w
Definition: af_aemphasis.c:43
ff_af_aemphasis
AVFilter ff_af_aemphasis
Definition: af_aemphasis.c:403
src
#define src
Definition: vp8dsp.c:255
avfilter_af_aemphasis_outputs
static const AVFilterPad avfilter_af_aemphasis_outputs[]
Definition: af_aemphasis.c:395
inputs
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
Definition: filter_design.txt:243
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
filter_channels
static int filter_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: af_aemphasis.c:100
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_aemphasis.c:154
AudioEmphasisContext::level_in
double level_in
Definition: af_aemphasis.c:39
set_lp_rbj
static void set_lp_rbj(BiquadCoeffs *bq, double fc, double q, double sr, double gain)
Definition: af_aemphasis.c:208
RIAACurve::use_brickw
int use_brickw
Definition: af_aemphasis.c:33
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
hypot
static av_const double hypot(double x, double y)
Definition: libm.h:366
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
ff_filter_process_command
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition: avfilter.c:882
b2
static double b2(void *priv, double x, double y)
Definition: vf_xfade.c:1666
FFMIN
#define FFMIN(a, b)
Definition: common.h:105
AudioEmphasisContext
Definition: af_aemphasis.c:36
a0
#define a0
Definition: regdef.h:46
M_PI
#define M_PI
Definition: mathematics.h:52
internal.h
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#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:126
in
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
Definition: audio_convert.c:326
i
int i
Definition: input.c:407
set_highshelf_rbj
static void set_highshelf_rbj(BiquadCoeffs *bq, double freq, double q, double peak, double sr)
Definition: af_aemphasis.c:184
a2
#define a2
Definition: regdef.h:48
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:802
AudioEmphasisContext::rc
RIAACurve rc
Definition: af_aemphasis.c:41
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
ThreadData
Used for passing data between threads.
Definition: dsddec.c:67
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
FLAGS
#define FLAGS
Definition: af_aemphasis.c:47
BiquadCoeffs::b1
double b1
Definition: af_aemphasis.c:27
AVFilter
Filter definition.
Definition: avfilter.h:145
ret
ret
Definition: filter_design.txt:187
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:421
mode
mode
Definition: ebur128.h:83
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:70
RIAACurve::brickw
BiquadCoeffs brickw
Definition: af_aemphasis.c:32
AVFilterContext
An instance of a filter.
Definition: avfilter.h:341
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
audio.h
RIAACurve::r1
BiquadCoeffs r1
Definition: af_aemphasis.c:31
ThreadData::in
AVFrame * in
Definition: af_adenorm.c:223
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
RIAACurve
Definition: af_aemphasis.c:30
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_aemphasis.c:235
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_aemphasis.c:378
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
ff_set_common_samplerates
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:575
b0
static double b0(void *priv, double x, double y)
Definition: vf_xfade.c:1664
AudioEmphasisContext::level_out
double level_out
Definition: af_aemphasis.c:39
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
BiquadCoeffs::a0
double a0
Definition: af_aemphasis.c:27
ff_set_common_channel_layouts
int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *channel_layouts)
A helper for query_formats() which sets all links to the same list of channel layouts/sample rates.
Definition: formats.c:568