FFmpeg
Data Structures | Macros | Functions | Variables
af_dynaudnorm.c File Reference
#include <float.h>
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/opt.h"
#include "libavfilter/bufferqueue.h"
#include "audio.h"
#include "avfilter.h"
#include "filters.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  local_gain
 
struct  cqueue
 
struct  DynamicAudioNormalizerContext
 

Macros

#define MIN_FILTER_SIZE   3
 
#define MAX_FILTER_SIZE   301
 
#define FF_BUFQUEUE_SIZE   (MAX_FILTER_SIZE + 1)
 
#define OFFSET(x)   offsetof(DynamicAudioNormalizerContext, x)
 
#define FLAGS   AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
 

Functions

 AVFILTER_DEFINE_CLASS (dynaudnorm)
 
static av_cold int init (AVFilterContext *ctx)
 
static int frame_size (int sample_rate, int frame_len_msec)
 
static cqueuecqueue_create (int size, int max_size)
 
static void cqueue_free (cqueue *q)
 
static int cqueue_size (cqueue *q)
 
static int cqueue_empty (cqueue *q)
 
static int cqueue_enqueue (cqueue *q, double element)
 
static double cqueue_peek (cqueue *q, int index)
 
static int cqueue_dequeue (cqueue *q, double *element)
 
static int cqueue_pop (cqueue *q)
 
static void cqueue_resize (cqueue *q, int new_size)
 
static void init_gaussian_filter (DynamicAudioNormalizerContext *s)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int config_input (AVFilterLink *inlink)
 
static double fade (double prev, double next, int pos, int length)
 
static double pow_2 (const double value)
 
static double bound (const double threshold, const double val)
 
static double find_peak_magnitude (AVFrame *frame, int channel)
 
static double compute_frame_rms (AVFrame *frame, int channel)
 
static local_gain get_max_local_gain (DynamicAudioNormalizerContext *s, AVFrame *frame, int channel)
 
static double minimum_filter (cqueue *q)
 
static double gaussian_filter (DynamicAudioNormalizerContext *s, cqueue *q, cqueue *tq)
 
static void update_gain_history (DynamicAudioNormalizerContext *s, int channel, local_gain gain)
 
static double update_value (double new, double old, double aggressiveness)
 
static int bypass_channel (DynamicAudioNormalizerContext *s, AVFrame *frame, int ch)
 
static void perform_dc_correction (DynamicAudioNormalizerContext *s, AVFrame *frame)
 
static double setup_compress_thresh (double threshold)
 
static double compute_frame_std_dev (DynamicAudioNormalizerContext *s, AVFrame *frame, int channel)
 
static void perform_compression (DynamicAudioNormalizerContext *s, AVFrame *frame)
 
static int analyze_frame (DynamicAudioNormalizerContext *s, AVFilterLink *outlink, AVFrame **frame)
 
static void amplify_frame (DynamicAudioNormalizerContext *s, AVFrame *in, AVFrame *frame, int enabled)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
static int flush_buffer (DynamicAudioNormalizerContext *s, AVFilterLink *inlink, AVFilterLink *outlink)
 
static int flush (AVFilterLink *outlink)
 
static int activate (AVFilterContext *ctx)
 
static int process_command (AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
 

Variables

static const AVOption dynaudnorm_options []
 
static const AVFilterPad avfilter_af_dynaudnorm_inputs []
 
static const AVFilterPad avfilter_af_dynaudnorm_outputs []
 
const AVFilter ff_af_dynaudnorm
 

Detailed Description

Dynamic Audio Normalizer

Definition in file af_dynaudnorm.c.

Macro Definition Documentation

◆ MIN_FILTER_SIZE

#define MIN_FILTER_SIZE   3

Definition at line 33 of file af_dynaudnorm.c.

◆ MAX_FILTER_SIZE

#define MAX_FILTER_SIZE   301

Definition at line 34 of file af_dynaudnorm.c.

◆ FF_BUFQUEUE_SIZE

#define FF_BUFQUEUE_SIZE   (MAX_FILTER_SIZE + 1)

Definition at line 36 of file af_dynaudnorm.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(DynamicAudioNormalizerContext, x)

Definition at line 96 of file af_dynaudnorm.c.

◆ FLAGS

Definition at line 97 of file af_dynaudnorm.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( dynaudnorm  )

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 129 of file af_dynaudnorm.c.

◆ frame_size()

static int frame_size ( int  sample_rate,
int  frame_len_msec 
)
inlinestatic

Definition at line 141 of file af_dynaudnorm.c.

Referenced by config_input(), and process_command().

◆ cqueue_create()

static cqueue* cqueue_create ( int  size,
int  max_size 
)
static

Definition at line 147 of file af_dynaudnorm.c.

Referenced by config_input(), create_exec_ctx(), and ff_vk_create_exec_ctx().

◆ cqueue_free()

static void cqueue_free ( cqueue q)
static

Definition at line 171 of file af_dynaudnorm.c.

Referenced by uninit().

◆ cqueue_size()

static int cqueue_size ( cqueue q)
static

Definition at line 178 of file af_dynaudnorm.c.

Referenced by gaussian_filter(), minimum_filter(), and update_gain_history().

◆ cqueue_empty()

static int cqueue_empty ( cqueue q)
static

◆ cqueue_enqueue()

static int cqueue_enqueue ( cqueue q,
double  element 
)
static

Definition at line 188 of file af_dynaudnorm.c.

Referenced by filter_frame(), and update_gain_history().

◆ cqueue_peek()

static double cqueue_peek ( cqueue q,
int  index 
)
static

Definition at line 198 of file af_dynaudnorm.c.

Referenced by gaussian_filter(), minimum_filter(), and update_gain_history().

◆ cqueue_dequeue()

static int cqueue_dequeue ( cqueue q,
double element 
)
static

Definition at line 204 of file af_dynaudnorm.c.

Referenced by amplify_frame(), and filter_frame().

◆ cqueue_pop()

static int cqueue_pop ( cqueue q)
static

Definition at line 215 of file af_dynaudnorm.c.

Referenced by cqueue_resize(), and update_gain_history().

◆ cqueue_resize()

static void cqueue_resize ( cqueue q,
int  new_size 
)
static

Definition at line 225 of file af_dynaudnorm.c.

Referenced by process_command().

◆ init_gaussian_filter()

static void init_gaussian_filter ( DynamicAudioNormalizerContext s)
static

Definition at line 247 of file af_dynaudnorm.c.

Referenced by config_input(), and process_command().

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 273 of file af_dynaudnorm.c.

Referenced by config_input().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 309 of file af_dynaudnorm.c.

◆ fade()

static double fade ( double  prev,
double  next,
int  pos,
int  length 
)
inlinestatic

Definition at line 359 of file af_dynaudnorm.c.

Referenced by amplify_frame(), perform_compression(), and perform_dc_correction().

◆ pow_2()

static double pow_2 ( const double  value)
inlinestatic

Definition at line 367 of file af_dynaudnorm.c.

Referenced by compute_frame_rms(), and compute_frame_std_dev().

◆ bound()

static double bound ( const double  threshold,
const double  val 
)
inlinestatic

◆ find_peak_magnitude()

static double find_peak_magnitude ( AVFrame frame,
int  channel 
)
static

Definition at line 378 of file af_dynaudnorm.c.

Referenced by get_max_local_gain().

◆ compute_frame_rms()

static double compute_frame_rms ( AVFrame frame,
int  channel 
)
static

Definition at line 399 of file af_dynaudnorm.c.

Referenced by get_max_local_gain().

◆ get_max_local_gain()

static local_gain get_max_local_gain ( DynamicAudioNormalizerContext s,
AVFrame frame,
int  channel 
)
static

Definition at line 425 of file af_dynaudnorm.c.

Referenced by analyze_frame().

◆ minimum_filter()

static double minimum_filter ( cqueue q)
static

Definition at line 439 of file af_dynaudnorm.c.

Referenced by update_gain_history().

◆ gaussian_filter()

static double gaussian_filter ( DynamicAudioNormalizerContext s,
cqueue q,
cqueue tq 
)
static

Definition at line 450 of file af_dynaudnorm.c.

Referenced by update_gain_history().

◆ update_gain_history()

static void update_gain_history ( DynamicAudioNormalizerContext s,
int  channel,
local_gain  gain 
)
static

Definition at line 469 of file af_dynaudnorm.c.

Referenced by analyze_frame().

◆ update_value()

static double update_value ( double  new,
double  old,
double  aggressiveness 
)
inlinestatic

Definition at line 524 of file af_dynaudnorm.c.

Referenced by perform_compression(), and perform_dc_correction().

◆ bypass_channel()

static int bypass_channel ( DynamicAudioNormalizerContext s,
AVFrame frame,
int  ch 
)
inlinestatic

Definition at line 530 of file af_dynaudnorm.c.

Referenced by amplify_frame(), perform_compression(), and perform_dc_correction().

◆ perform_dc_correction()

static void perform_dc_correction ( DynamicAudioNormalizerContext s,
AVFrame frame 
)
static

Definition at line 537 of file af_dynaudnorm.c.

Referenced by analyze_frame().

◆ setup_compress_thresh()

static double setup_compress_thresh ( double  threshold)
static

Definition at line 560 of file af_dynaudnorm.c.

Referenced by perform_compression().

◆ compute_frame_std_dev()

static double compute_frame_std_dev ( DynamicAudioNormalizerContext s,
AVFrame frame,
int  channel 
)
static

Definition at line 582 of file af_dynaudnorm.c.

Referenced by perform_compression().

◆ perform_compression()

static void perform_compression ( DynamicAudioNormalizerContext s,
AVFrame frame 
)
static

Definition at line 608 of file af_dynaudnorm.c.

Referenced by analyze_frame().

◆ analyze_frame()

static int analyze_frame ( DynamicAudioNormalizerContext s,
AVFilterLink outlink,
AVFrame **  frame 
)
static

Definition at line 658 of file af_dynaudnorm.c.

Referenced by filter_frame().

◆ amplify_frame()

static void amplify_frame ( DynamicAudioNormalizerContext s,
AVFrame in,
AVFrame frame,
int  enabled 
)
static

Definition at line 726 of file af_dynaudnorm.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 749 of file af_dynaudnorm.c.

Referenced by activate(), and flush_buffer().

◆ flush_buffer()

static int flush_buffer ( DynamicAudioNormalizerContext s,
AVFilterLink inlink,
AVFilterLink outlink 
)
static

Definition at line 799 of file af_dynaudnorm.c.

Referenced by flush().

◆ flush()

static int flush ( AVFilterLink outlink)
static

Definition at line 822 of file af_dynaudnorm.c.

Referenced by activate().

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 842 of file af_dynaudnorm.c.

◆ process_command()

static int process_command ( AVFilterContext ctx,
const char *  cmd,
const char *  args,
char *  res,
int  res_len,
int  flags 
)
static

Definition at line 894 of file af_dynaudnorm.c.

Variable Documentation

◆ dynaudnorm_options

const AVOption dynaudnorm_options[]
static
Initial value:
= {
{ "framelen", "set the frame length in msec", OFFSET(frame_len_msec), AV_OPT_TYPE_INT, {.i64 = 500}, 10, 8000, FLAGS },
{ "f", "set the frame length in msec", OFFSET(frame_len_msec), AV_OPT_TYPE_INT, {.i64 = 500}, 10, 8000, FLAGS },
{ "gausssize", "set the filter size", OFFSET(filter_size), AV_OPT_TYPE_INT, {.i64 = 31}, 3, 301, FLAGS },
{ "g", "set the filter size", OFFSET(filter_size), AV_OPT_TYPE_INT, {.i64 = 31}, 3, 301, FLAGS },
{ "peak", "set the peak value", OFFSET(peak_value), AV_OPT_TYPE_DOUBLE, {.dbl = 0.95}, 0.0, 1.0, FLAGS },
{ "p", "set the peak value", OFFSET(peak_value), AV_OPT_TYPE_DOUBLE, {.dbl = 0.95}, 0.0, 1.0, FLAGS },
{ "maxgain", "set the max amplification", OFFSET(max_amplification), AV_OPT_TYPE_DOUBLE, {.dbl = 10.0}, 1.0, 100.0, FLAGS },
{ "m", "set the max amplification", OFFSET(max_amplification), AV_OPT_TYPE_DOUBLE, {.dbl = 10.0}, 1.0, 100.0, FLAGS },
{ "targetrms", "set the target RMS", OFFSET(target_rms), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 1.0, FLAGS },
{ "r", "set the target RMS", OFFSET(target_rms), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 1.0, FLAGS },
{ "coupling", "set channel coupling", OFFSET(channels_coupled), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
{ "n", "set channel coupling", OFFSET(channels_coupled), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS },
{ "correctdc", "set DC correction", OFFSET(dc_correction), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
{ "c", "set DC correction", OFFSET(dc_correction), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
{ "altboundary", "set alternative boundary mode", OFFSET(alt_boundary_mode), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
{ "b", "set alternative boundary mode", OFFSET(alt_boundary_mode), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
{ "compress", "set the compress factor", OFFSET(compress_factor), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 30.0, FLAGS },
{ "s", "set the compress factor", OFFSET(compress_factor), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 30.0, FLAGS },
{ "threshold", "set the threshold value", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 1.0, FLAGS },
{ "t", "set the threshold value", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 1.0, FLAGS },
{ "channels", "set channels to filter", OFFSET(channels_to_filter),AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS },
{ "h", "set channels to filter", OFFSET(channels_to_filter),AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS },
{ "overlap", "set the frame overlap", OFFSET(overlap), AV_OPT_TYPE_DOUBLE, {.dbl=.0}, 0.0, 1.0, FLAGS },
{ "o", "set the frame overlap", OFFSET(overlap), AV_OPT_TYPE_DOUBLE, {.dbl=.0}, 0.0, 1.0, FLAGS },
{ NULL }
}

Definition at line 99 of file af_dynaudnorm.c.

◆ avfilter_af_dynaudnorm_inputs

const AVFilterPad avfilter_af_dynaudnorm_inputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_input,
},
}

Definition at line 923 of file af_dynaudnorm.c.

◆ avfilter_af_dynaudnorm_outputs

const AVFilterPad avfilter_af_dynaudnorm_outputs[]
static
Initial value:
= {
{
.name = "default",
},
}

Definition at line 931 of file af_dynaudnorm.c.

◆ ff_af_dynaudnorm

const AVFilter ff_af_dynaudnorm
Initial value:
= {
.name = "dynaudnorm",
.description = NULL_IF_CONFIG_SMALL("Dynamic Audio Normalizer."),
.priv_size = sizeof(DynamicAudioNormalizerContext),
.init = init,
.priv_class = &dynaudnorm_class,
.process_command = process_command,
}

Definition at line 938 of file af_dynaudnorm.c.

config_input
static int config_input(AVFilterLink *inlink)
Definition: af_dynaudnorm.c:309
OFFSET
#define OFFSET(x)
Definition: af_dynaudnorm.c:96
FILTER_SINGLE_SAMPLEFMT
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
Definition: internal.h:183
init
static av_cold int init(AVFilterContext *ctx)
Definition: af_dynaudnorm.c:129
avfilter_af_dynaudnorm_inputs
static const AVFilterPad avfilter_af_dynaudnorm_inputs[]
Definition: af_dynaudnorm.c:923
DynamicAudioNormalizerContext
Definition: af_dynaudnorm.c:56
activate
static int activate(AVFilterContext *ctx)
Definition: af_dynaudnorm.c:842
avfilter_af_dynaudnorm_outputs
static const AVFilterPad avfilter_af_dynaudnorm_outputs[]
Definition: af_dynaudnorm.c:931
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_dynaudnorm.c:273
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:190
FLAGS
#define FLAGS
Definition: af_dynaudnorm.c:97
NULL
#define NULL
Definition: coverity.c:32
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
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_dynaudnorm.c:894
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
AV_SAMPLE_FMT_DBLP
@ AV_SAMPLE_FMT_DBLP
double, planar
Definition: samplefmt.h:67
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:191
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:160
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229