FFmpeg
af_adrc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 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 <float.h>
22 
23 #include "libavutil/eval.h"
24 #include "libavutil/ffmath.h"
25 #include "libavutil/mem.h"
26 #include "libavutil/opt.h"
27 #include "libavutil/tx.h"
28 #include "audio.h"
29 #include "avfilter.h"
30 #include "filters.h"
31 
32 static const char * const var_names[] = {
33  "ch", ///< the value of the current channel
34  "sn", ///< number of samples
35  "nb_channels",
36  "t", ///< timestamp expressed in seconds
37  "sr", ///< sample rate
38  "p", ///< input power in dB for frequency bin
39  "f", ///< frequency in Hz
40  NULL
41 };
42 
43 enum var_name {
52 };
53 
54 typedef struct AudioDRCContext {
55  const AVClass *class;
56 
57  double attack_ms;
58  double release_ms;
59  char *expr_str;
60 
61  double attack;
62  double release;
63 
64  int fft_size;
65  int overlap;
66  int channels;
67 
68  float fx;
69  float *window;
70 
82 
85 
90 
94 
95 #define OFFSET(x) offsetof(AudioDRCContext, x)
96 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_RUNTIME_PARAM
97 
98 static const AVOption adrc_options[] = {
99  { "transfer", "set the transfer expression", OFFSET(expr_str), AV_OPT_TYPE_STRING, {.str="p"}, 0, 0, FLAGS },
100  { "attack", "set the attack", OFFSET(attack_ms), AV_OPT_TYPE_DOUBLE, {.dbl=50.}, 1, 1000, FLAGS },
101  { "release", "set the release", OFFSET(release_ms), AV_OPT_TYPE_DOUBLE, {.dbl=100.}, 5, 2000, FLAGS },
102  { "channels", "set channels to filter",OFFSET(channels_to_filter),AV_OPT_TYPE_STRING,{.str="all"},0, 0, FLAGS },
103  {NULL}
104 };
105 
107 
108 static void generate_hann_window(float *window, int size)
109 {
110  for (int i = 0; i < size; i++) {
111  float value = 0.5f * (1.f - cosf(2.f * M_PI * i / size));
112 
113  window[i] = value;
114  }
115 }
116 
118 {
119  AVFilterContext *ctx = inlink->dst;
120  AudioDRCContext *s = ctx->priv;
121  float scale;
122  int ret;
123 
124  s->fft_size = inlink->sample_rate > 100000 ? 1024 : inlink->sample_rate > 50000 ? 512 : 256;
125  s->fx = inlink->sample_rate * 0.5f / (s->fft_size / 2 + 1);
126  s->overlap = s->fft_size / 4;
127 
128  s->window = av_calloc(s->fft_size, sizeof(*s->window));
129  if (!s->window)
130  return AVERROR(ENOMEM);
131 
132  s->drc_frame = ff_get_audio_buffer(inlink, s->fft_size * 2);
133  s->energy = ff_get_audio_buffer(inlink, s->fft_size / 2 + 1);
134  s->envelope = ff_get_audio_buffer(inlink, s->fft_size / 2 + 1);
135  s->factors = ff_get_audio_buffer(inlink, s->fft_size / 2 + 1);
136  s->in_buffer = ff_get_audio_buffer(inlink, s->fft_size * 2);
137  s->in_frame = ff_get_audio_buffer(inlink, s->fft_size * 2);
138  s->out_dist_frame = ff_get_audio_buffer(inlink, s->fft_size * 2);
139  s->spectrum_buf = ff_get_audio_buffer(inlink, s->fft_size * 2);
140  s->target_gain = ff_get_audio_buffer(inlink, s->fft_size / 2 + 1);
141  s->windowed_frame = ff_get_audio_buffer(inlink, s->fft_size * 2);
142  if (!s->in_buffer || !s->in_frame || !s->target_gain ||
143  !s->out_dist_frame || !s->windowed_frame || !s->envelope ||
144  !s->drc_frame || !s->spectrum_buf || !s->energy || !s->factors)
145  return AVERROR(ENOMEM);
146 
147  generate_hann_window(s->window, s->fft_size);
148 
149  s->channels = inlink->ch_layout.nb_channels;
150 
151  s->tx_ctx = av_calloc(s->channels, sizeof(*s->tx_ctx));
152  s->itx_ctx = av_calloc(s->channels, sizeof(*s->itx_ctx));
153  if (!s->tx_ctx || !s->itx_ctx)
154  return AVERROR(ENOMEM);
155 
156  for (int ch = 0; ch < s->channels; ch++) {
157  scale = 1.f / s->fft_size;
158  ret = av_tx_init(&s->tx_ctx[ch], &s->tx_fn, AV_TX_FLOAT_RDFT, 0, s->fft_size, &scale, 0);
159  if (ret < 0)
160  return ret;
161 
162  scale = 1.f;
163  ret = av_tx_init(&s->itx_ctx[ch], &s->itx_fn, AV_TX_FLOAT_RDFT, 1, s->fft_size, &scale, 0);
164  if (ret < 0)
165  return ret;
166  }
167 
168  s->var_values[VAR_SR] = inlink->sample_rate;
169  s->var_values[VAR_NB_CHANNELS] = s->channels;
170 
171  return av_expr_parse(&s->expr, s->expr_str, var_names, NULL, NULL,
172  NULL, NULL, 0, ctx);
173 }
174 
176  const float *in_frame, float *out_frame, const int add_to_out_frame)
177 {
178  const float *window = s->window;
179  const int fft_size = s->fft_size;
180 
181  if (add_to_out_frame) {
182  for (int i = 0; i < fft_size; i++)
183  out_frame[i] += in_frame[i] * window[i];
184  } else {
185  for (int i = 0; i < fft_size; i++)
186  out_frame[i] = in_frame[i] * window[i];
187  }
188 }
189 
190 static float sqrf(float x)
191 {
192  return x * x;
193 }
194 
196  int len,
197  float *energy,
198  const float *spectral)
199 {
200  for (int n = 0; n < len; n++) {
201  energy[n] = 10.f * log10f(sqrf(spectral[2 * n]) + sqrf(spectral[2 * n + 1]));
202  if (!isnormal(energy[n]))
203  energy[n] = -351.f;
204  }
205 }
206 
208  int len,
209  float *gain,
210  const float *energy,
211  double *var_values,
212  float fx, int bypass)
213 {
214  AudioDRCContext *s = ctx->priv;
215 
216  if (bypass) {
217  memcpy(gain, energy, sizeof(*gain) * len);
218  return;
219  }
220 
221  for (int n = 0; n < len; n++) {
222  const float Xg = energy[n];
223 
224  var_values[VAR_P] = Xg;
225  var_values[VAR_F] = n * fx;
226 
227  gain[n] = av_expr_eval(s->expr, var_values, s);
228  }
229 }
230 
232  int len,
233  float *envelope,
234  const float *energy,
235  const float *gain)
236 {
237  AudioDRCContext *s = ctx->priv;
238  const float release = s->release;
239  const float attack = s->attack;
240 
241  for (int n = 0; n < len; n++) {
242  const float Bg = gain[n] - energy[n];
243  const float Vg = envelope[n];
244 
245  if (Bg > Vg) {
246  envelope[n] = attack * Vg + (1.f - attack) * Bg;
247  } else if (Bg <= Vg) {
248  envelope[n] = release * Vg + (1.f - release) * Bg;
249  } else {
250  envelope[n] = 0.f;
251  }
252  }
253 }
254 
256  int len,
257  float *factors,
258  const float *envelope)
259 {
260  for (int n = 0; n < len; n++)
261  factors[n] = sqrtf(ff_exp10f(envelope[n] / 10.f));
262 }
263 
265  int len,
266  float *spectrum,
267  const float *factors)
268 {
269  for (int n = 0; n < len; n++) {
270  spectrum[2*n+0] *= factors[n];
271  spectrum[2*n+1] *= factors[n];
272  }
273 }
274 
275 static void feed(AVFilterContext *ctx, int ch,
276  const float *in_samples, float *out_samples,
277  float *in_frame, float *out_dist_frame,
278  float *windowed_frame, float *drc_frame,
279  float *spectrum_buf, float *energy,
280  float *target_gain, float *envelope,
281  float *factors)
282 {
283  AudioDRCContext *s = ctx->priv;
284  double var_values[VAR_VARS_NB];
285  const int fft_size = s->fft_size;
286  const int nb_coeffs = s->fft_size / 2 + 1;
287  const int overlap = s->overlap;
288  enum AVChannel channel = av_channel_layout_channel_from_index(&ctx->inputs[0]->ch_layout, ch);
289  const int bypass = av_channel_layout_index_from_channel(&s->ch_layout, channel) < 0;
290 
291  memcpy(var_values, s->var_values, sizeof(var_values));
292 
293  var_values[VAR_CH] = ch;
294 
295  // shift in/out buffers
296  memmove(in_frame, in_frame + overlap, (fft_size - overlap) * sizeof(*in_frame));
297  memmove(out_dist_frame, out_dist_frame + overlap, (fft_size - overlap) * sizeof(*out_dist_frame));
298 
299  memcpy(in_frame + fft_size - overlap, in_samples, sizeof(*in_frame) * overlap);
300  memset(out_dist_frame + fft_size - overlap, 0, sizeof(*out_dist_frame) * overlap);
301 
302  apply_window(s, in_frame, windowed_frame, 0);
303  s->tx_fn(s->tx_ctx[ch], spectrum_buf, windowed_frame, sizeof(float));
304 
305  get_energy(ctx, nb_coeffs, energy, spectrum_buf);
306  get_target_gain(ctx, nb_coeffs, target_gain, energy, var_values, s->fx, bypass);
307  get_envelope(ctx, nb_coeffs, envelope, energy, target_gain);
308  get_factors(ctx, nb_coeffs, factors, envelope);
309  apply_factors(ctx, nb_coeffs, spectrum_buf, factors);
310 
311  s->itx_fn(s->itx_ctx[ch], drc_frame, spectrum_buf, sizeof(AVComplexFloat));
312 
313  apply_window(s, drc_frame, out_dist_frame, 1);
314 
315  // 4 times overlap with squared hanning window results in 1.5 time increase in amplitude
316  if (!ctx->is_disabled) {
317  for (int i = 0; i < overlap; i++)
318  out_samples[i] = out_dist_frame[i] / 1.5f;
319  } else {
320  memcpy(out_samples, in_frame, sizeof(*out_samples) * overlap);
321  }
322 }
323 
324 static int drc_channel(AVFilterContext *ctx, AVFrame *in, AVFrame *out, int ch)
325 {
326  AudioDRCContext *s = ctx->priv;
327  const float *src = (const float *)in->extended_data[ch];
328  float *in_buffer = (float *)s->in_buffer->extended_data[ch];
329  float *dst = (float *)out->extended_data[ch];
330 
331  memcpy(in_buffer, src, sizeof(*in_buffer) * s->overlap);
332 
333  feed(ctx, ch, in_buffer, dst,
334  (float *)(s->in_frame->extended_data[ch]),
335  (float *)(s->out_dist_frame->extended_data[ch]),
336  (float *)(s->windowed_frame->extended_data[ch]),
337  (float *)(s->drc_frame->extended_data[ch]),
338  (float *)(s->spectrum_buf->extended_data[ch]),
339  (float *)(s->energy->extended_data[ch]),
340  (float *)(s->target_gain->extended_data[ch]),
341  (float *)(s->envelope->extended_data[ch]),
342  (float *)(s->factors->extended_data[ch]));
343 
344  return 0;
345 }
346 
347 static int drc_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
348 {
349  AudioDRCContext *s = ctx->priv;
350  AVFrame *in = s->in;
351  AVFrame *out = arg;
352  const int start = (out->ch_layout.nb_channels * jobnr) / nb_jobs;
353  const int end = (out->ch_layout.nb_channels * (jobnr+1)) / nb_jobs;
354 
355  for (int ch = start; ch < end; ch++)
356  drc_channel(ctx, in, out, ch);
357 
358  return 0;
359 }
360 
362 {
363  AVFilterContext *ctx = inlink->dst;
364  AVFilterLink *outlink = ctx->outputs[0];
365  FilterLink *outl = ff_filter_link(outlink);
366  AudioDRCContext *s = ctx->priv;
367  AVFrame *out;
368  int ret;
369 
370  out = ff_get_audio_buffer(outlink, s->overlap);
371  if (!out) {
372  ret = AVERROR(ENOMEM);
373  goto fail;
374  }
375 
376  s->var_values[VAR_SN] = outl->sample_count_in;
377  s->var_values[VAR_T] = s->var_values[VAR_SN] * (double)1/outlink->sample_rate;
378 
379  s->in = in;
383 
384  out->pts = in->pts;
385  out->nb_samples = in->nb_samples;
386  ret = ff_filter_frame(outlink, out);
387 fail:
388  av_frame_free(&in);
389  s->in = NULL;
390  return ret < 0 ? ret : 0;
391 }
392 
394 {
395  AVFilterLink *inlink = ctx->inputs[0];
396  AVFilterLink *outlink = ctx->outputs[0];
397  AudioDRCContext *s = ctx->priv;
398  AVFrame *in = NULL;
399  int ret = 0, status;
400  int64_t pts;
401 
402  ret = av_channel_layout_copy(&s->ch_layout, &inlink->ch_layout);
403  if (ret < 0)
404  return ret;
405  if (strcmp(s->channels_to_filter, "all"))
406  av_channel_layout_from_string(&s->ch_layout, s->channels_to_filter);
407 
409 
410  ret = ff_inlink_consume_samples(inlink, s->overlap, s->overlap, &in);
411  if (ret < 0)
412  return ret;
413 
414  if (ret > 0) {
415  s->attack = expf(-1.f / (s->attack_ms * inlink->sample_rate / 1000.f));
416  s->release = expf(-1.f / (s->release_ms * inlink->sample_rate / 1000.f));
417 
418  return filter_frame(inlink, in);
419  } else if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
420  ff_outlink_set_status(outlink, status, pts);
421  return 0;
422  } else {
423  if (ff_inlink_queued_samples(inlink) >= s->overlap) {
425  } else if (ff_outlink_frame_wanted(outlink)) {
427  }
428  return 0;
429  }
430 }
431 
433 {
434  AudioDRCContext *s = ctx->priv;
435 
436  av_channel_layout_uninit(&s->ch_layout);
437 
438  av_expr_free(s->expr);
439  s->expr = NULL;
440 
441  av_freep(&s->window);
442 
443  av_frame_free(&s->drc_frame);
444  av_frame_free(&s->energy);
445  av_frame_free(&s->envelope);
446  av_frame_free(&s->factors);
447  av_frame_free(&s->in_buffer);
448  av_frame_free(&s->in_frame);
449  av_frame_free(&s->out_dist_frame);
450  av_frame_free(&s->spectrum_buf);
451  av_frame_free(&s->target_gain);
452  av_frame_free(&s->windowed_frame);
453 
454  for (int ch = 0; ch < s->channels; ch++) {
455  if (s->tx_ctx)
456  av_tx_uninit(&s->tx_ctx[ch]);
457  if (s->itx_ctx)
458  av_tx_uninit(&s->itx_ctx[ch]);
459  }
460 
461  av_freep(&s->tx_ctx);
462  av_freep(&s->itx_ctx);
463 }
464 
465 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
466  char *res, int res_len, int flags)
467 {
468  AudioDRCContext *s = ctx->priv;
469  char *old_expr_str = av_strdup(s->expr_str);
470  int ret;
471 
472  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
473  if (ret >= 0 && strcmp(old_expr_str, s->expr_str)) {
474  ret = av_expr_parse(&s->expr, s->expr_str, var_names, NULL, NULL,
475  NULL, NULL, 0, ctx);
476  }
477  av_free(old_expr_str);
478  return ret;
479 }
480 
481 static const AVFilterPad inputs[] = {
482  {
483  .name = "default",
484  .type = AVMEDIA_TYPE_AUDIO,
485  .config_props = config_input,
486  },
487 };
488 
490  .name = "adrc",
491  .description = NULL_IF_CONFIG_SMALL("Audio Spectral Dynamic Range Controller."),
492  .priv_size = sizeof(AudioDRCContext),
493  .priv_class = &adrc_class,
494  .uninit = uninit,
500  .activate = activate,
501  .process_command = process_command,
502 };
AudioDRCContext::expr
AVExpr * expr
Definition: af_adrc.c:91
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:98
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
AudioDRCContext::fx
float fx
Definition: af_adrc.c:68
AudioDRCContext::ch_layout
AVChannelLayout ch_layout
Definition: af_adrc.c:84
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
var_name
var_name
Definition: noise.c:47
out
FILE * out
Definition: movenc.c:55
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1062
AudioDRCContext::itx_fn
av_tx_fn itx_fn
Definition: af_adrc.c:89
AVTXContext
Definition: tx_priv.h:235
int64_t
long long int64_t
Definition: coverity.c:34
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:162
feed
static void feed(AVFilterContext *ctx, int ch, const float *in_samples, float *out_samples, float *in_frame, float *out_dist_frame, float *windowed_frame, float *drc_frame, float *spectrum_buf, float *energy, float *target_gain, float *envelope, float *factors)
Definition: af_adrc.c:275
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:501
av_channel_layout_channel_from_index
enum AVChannel av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx)
Get the channel with the given index in a channel layout.
Definition: channel_layout.c:668
AVOption
AVOption.
Definition: opt.h:429
expf
#define expf(x)
Definition: libm.h:283
generate_hann_window
static void generate_hann_window(float *window, int size)
Definition: af_adrc.c:108
adrc_options
static const AVOption adrc_options[]
Definition: af_adrc.c:98
float.h
AVComplexFloat
Definition: tx.h:27
AudioDRCContext::release
double release
Definition: af_adrc.c:62
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:321
FF_FILTER_FORWARD_STATUS_BACK
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition: filters.h:434
activate
static int activate(AVFilterContext *ctx)
Definition: af_adrc.c:393
AudioDRCContext::attack
double attack
Definition: af_adrc.c:61
av_tx_init
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
Definition: tx.c:903
VAR_F
@ VAR_F
Definition: af_adrc.c:50
av_expr_parse
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:710
window
static SDL_Window * window
Definition: ffplay.c:361
cosf
#define cosf(x)
Definition: libm.h:78
fail
#define fail()
Definition: checkasm.h:188
log10f
#define log10f(x)
Definition: libm.h:414
AudioDRCContext
Definition: af_adrc.c:54
pts
static int64_t pts
Definition: transcode_aac.c:644
av_expr_free
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:358
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
VAR_CH
@ VAR_CH
Definition: af_adrc.c:44
AudioDRCContext::var_values
double var_values[VAR_VARS_NB]
Definition: af_adrc.c:92
av_cold
#define av_cold
Definition: attributes.h:90
AudioDRCContext::in_frame
AVFrame * in_frame
Definition: af_adrc.c:77
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:151
AudioDRCContext::channels
int channels
Definition: af_adrc.c:66
ff_outlink_set_status
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:424
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1594
VAR_SN
@ VAR_SN
Definition: af_adrc.c:45
s
#define s(width, name)
Definition: cbs_vp9.c:198
FLAGS
#define FLAGS
Definition: af_adrc.c:96
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition: opt.h:267
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
filters.h
ctx
AVFormatContext * ctx
Definition: movenc.c:49
apply_window
static void apply_window(AudioDRCContext *s, const float *in_frame, float *out_frame, const int add_to_out_frame)
Definition: af_adrc.c:175
av_expr_eval
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:792
AVExpr
Definition: eval.c:158
AudioDRCContext::windowed_frame
AVFrame * windowed_frame
Definition: af_adrc.c:81
AudioDRCContext::tx_fn
av_tx_fn tx_fn
Definition: af_adrc.c:87
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
arg
const char * arg
Definition: jacosubdec.c:67
get_envelope
static void get_envelope(AVFilterContext *ctx, int len, float *envelope, const float *energy, const float *gain)
Definition: af_adrc.c:231
VAR_SR
@ VAR_SR
Definition: af_adrc.c:48
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
ff_inlink_consume_samples
int ff_inlink_consume_samples(AVFilterLink *link, unsigned min, unsigned max, AVFrame **rframe)
Take samples from the link's FIFO and update the link's stats.
Definition: avfilter.c:1511
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:713
AudioDRCContext::fft_size
int fft_size
Definition: af_adrc.c:64
VAR_T
@ VAR_T
Definition: af_adrc.c:47
inputs
static const AVFilterPad inputs[]
Definition: af_adrc.c:481
ff_audio_default_filterpad
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
Definition: audio.c:34
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
double
double
Definition: af_crystalizer.c:132
AudioDRCContext::out_dist_frame
AVFrame * out_dist_frame
Definition: af_adrc.c:78
AudioDRCContext::factors
AVFrame * factors
Definition: af_adrc.c:74
get_energy
static void get_energy(AVFilterContext *ctx, int len, float *energy, const float *spectral)
Definition: af_adrc.c:195
ff_inlink_acknowledge_status
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:1438
ff_filter_link
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition: filters.h:197
AudioDRCContext::window
float * window
Definition: af_adrc.c:69
eval.h
FILTER_SINGLE_SAMPLEFMT
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
Definition: filters.h:255
f
f
Definition: af_crystalizer.c:122
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:94
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:311
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
ff_af_adrc
const AVFilter ff_af_adrc
Definition: af_adrc.c:489
size
int size
Definition: twinvq_data.h:10344
drc_channels
static int drc_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: af_adrc.c:347
OFFSET
#define OFFSET(x)
Definition: af_adrc.c:95
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:901
AudioDRCContext::target_gain
AVFrame * target_gain
Definition: af_adrc.c:80
AudioDRCContext::expr_str
char * expr_str
Definition: af_adrc.c:59
AudioDRCContext::itx_ctx
AVTXContext ** itx_ctx
Definition: af_adrc.c:88
M_PI
#define M_PI
Definition: mathematics.h:67
av_tx_uninit
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition: tx.c:295
AudioDRCContext::envelope
AVFrame * envelope
Definition: af_adrc.c:73
get_target_gain
static void get_target_gain(AVFilterContext *ctx, int len, float *gain, const float *energy, double *var_values, float fx, int bypass)
Definition: af_adrc.c:207
AVChannel
AVChannel
Definition: channel_layout.h:47
av_channel_layout_from_string
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
Definition: channel_layout.c:307
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:469
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_adrc.c:465
get_factors
static void get_factors(AVFilterContext *ctx, int len, float *factors, const float *envelope)
Definition: af_adrc.c:255
envelope
static float envelope(const float x)
Definition: vf_monochrome.c:45
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:450
AudioDRCContext::energy
AVFrame * energy
Definition: af_adrc.c:72
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:841
AudioDRCContext::release_ms
double release_ms
Definition: af_adrc.c:58
value
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 default value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AudioDRCContext::in
AVFrame * in
Definition: af_adrc.c:75
len
int len
Definition: vorbis_enc_data.h:426
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
ff_inlink_queued_samples
int ff_inlink_queued_samples(AVFilterLink *link)
Definition: avfilter.c:1466
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
AudioDRCContext::in_buffer
AVFrame * in_buffer
Definition: af_adrc.c:76
var_names
static const char *const var_names[]
Definition: af_adrc.c:32
VAR_NB_CHANNELS
@ VAR_NB_CHANNELS
Definition: af_adrc.c:46
AVFilter
Filter definition.
Definition: avfilter.h:201
AudioDRCContext::tx_ctx
AVTXContext ** tx_ctx
Definition: af_adrc.c:86
ret
ret
Definition: filter_design.txt:187
AV_TX_FLOAT_RDFT
@ AV_TX_FLOAT_RDFT
Real to complex and complex to real DFTs.
Definition: tx.h:90
VAR_VARS_NB
@ VAR_VARS_NB
Definition: af_adrc.c:51
status
ov_status_e status
Definition: dnn_backend_openvino.c:100
ff_filter_execute
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: avfilter.c:1667
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_adrc.c:432
av_channel_layout_index_from_channel
int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, enum AVChannel channel)
Get the index of a given channel in a channel layout.
Definition: channel_layout.c:708
AudioDRCContext::drc_frame
AVFrame * drc_frame
Definition: af_adrc.c:71
avfilter.h
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:437
ffmath.h
VAR_P
@ VAR_P
Definition: af_adrc.c:49
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(adrc)
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:444
drc_channel
static int drc_channel(AVFilterContext *ctx, AVFrame *in, AVFrame *out, int ch)
Definition: af_adrc.c:324
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:152
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
AudioDRCContext::spectrum_buf
AVFrame * spectrum_buf
Definition: af_adrc.c:79
mem.h
audio.h
AudioDRCContext::attack_ms
double attack_ms
Definition: af_adrc.c:57
AudioDRCContext::overlap
int overlap
Definition: af_adrc.c:65
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:190
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
ff_exp10f
static av_always_inline float ff_exp10f(float x)
Definition: ffmath.h:47
apply_factors
static void apply_factors(AVFilterContext *ctx, int len, float *spectrum, const float *factors)
Definition: af_adrc.c:264
ff_outlink_frame_wanted
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_adrc.c:361
src
#define src
Definition: vp8dsp.c:248
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_adrc.c:117
channel
channel
Definition: ebur128.h:39
ff_filter_set_ready
void ff_filter_set_ready(AVFilterContext *filter, unsigned priority)
Mark a filter ready and schedule it for activation.
Definition: avfilter.c:239
tx.h
sqrf
static float sqrf(float x)
Definition: af_adrc.c:190
AudioDRCContext::channels_to_filter
char * channels_to_filter
Definition: af_adrc.c:83