FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
af_dynaudnorm.c File Reference

Dynamic Audio Normalizer. More...

#include <float.h>
#include "libavutil/avassert.h"
#include "libavutil/opt.h"
#include "libavfilter/bufferqueue.h"
#include "audio.h"
#include "avfilter.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  cqueue
 
struct  DynamicAudioNormalizerContext
 

Macros

#define FF_BUFQUEUE_SIZE   302
 
#define OFFSET(x)   offsetof(DynamicAudioNormalizerContext, x)
 
#define FLAGS   AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 

Functions

 AVFILTER_DEFINE_CLASS (dynaudnorm)
 
static av_cold int init (AVFilterContext *ctx)
 
static int query_formats (AVFilterContext *ctx)
 
static int frame_size (int sample_rate, int frame_len_msec)
 
static void precalculate_fade_factors (double *fade_factors[2], int frame_len)
 
static cqueuecqueue_create (int 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 init_gaussian_filter (DynamicAudioNormalizerContext *s)
 
static int config_input (AVFilterLink *inlink)
 
static int config_output (AVFilterLink *outlink)
 
static double fade (double prev, double next, int pos, double *fade_factors[2])
 
static double pow2 (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 double get_max_local_gain (DynamicAudioNormalizerContext *s, AVFrame *frame, int channel)
 
static double minimum_filter (cqueue *q)
 
static double gaussian_filter (DynamicAudioNormalizerContext *s, cqueue *q)
 
static void update_gain_history (DynamicAudioNormalizerContext *s, int channel, double current_gain_factor)
 
static double update_value (double new, double old, double aggressiveness)
 
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 void analyze_frame (DynamicAudioNormalizerContext *s, AVFrame *frame)
 
static void amplify_frame (DynamicAudioNormalizerContext *s, AVFrame *frame)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
static int flush_buffer (DynamicAudioNormalizerContext *s, AVFilterLink *inlink, AVFilterLink *outlink)
 
static int request_frame (AVFilterLink *outlink)
 
static av_cold void uninit (AVFilterContext *ctx)
 

Variables

static const AVOption dynaudnorm_options []
 
static const double s_pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
 
static const AVFilterPad avfilter_af_dynaudnorm_inputs []
 
static const AVFilterPad avfilter_af_dynaudnorm_outputs []
 
AVFilter ff_af_dynaudnorm
 

Detailed Description

Dynamic Audio Normalizer.

Definition in file af_dynaudnorm.c.

Macro Definition Documentation

#define FF_BUFQUEUE_SIZE   302

Definition at line 32 of file af_dynaudnorm.c.

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

Definition at line 76 of file af_dynaudnorm.c.

Definition at line 77 of file af_dynaudnorm.c.

Function Documentation

AVFILTER_DEFINE_CLASS ( dynaudnorm  )
static av_cold int init ( AVFilterContext ctx)
static

Definition at line 94 of file af_dynaudnorm.c.

static int query_formats ( AVFilterContext ctx)
static

Definition at line 106 of file af_dynaudnorm.c.

static int frame_size ( int  sample_rate,
int  frame_len_msec 
)
inlinestatic

Definition at line 136 of file af_dynaudnorm.c.

Referenced by config_input().

static void precalculate_fade_factors ( double *  fade_factors[2],
int  frame_len 
)
static

Definition at line 142 of file af_dynaudnorm.c.

Referenced by config_input().

static cqueue* cqueue_create ( int  size)
static

Definition at line 153 of file af_dynaudnorm.c.

Referenced by config_input().

static void cqueue_free ( cqueue q)
static

Definition at line 174 of file af_dynaudnorm.c.

Referenced by uninit().

static int cqueue_size ( cqueue q)
static

Definition at line 180 of file af_dynaudnorm.c.

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

static int cqueue_empty ( cqueue q)
static
static int cqueue_enqueue ( cqueue q,
double  element 
)
static

Definition at line 190 of file af_dynaudnorm.c.

Referenced by update_gain_history().

static double cqueue_peek ( cqueue q,
int  index 
)
static

Definition at line 203 of file af_dynaudnorm.c.

Referenced by gaussian_filter(), and minimum_filter().

static int cqueue_dequeue ( cqueue q,
double *  element 
)
static

Definition at line 209 of file af_dynaudnorm.c.

Referenced by amplify_frame().

static int cqueue_pop ( cqueue q)
static

Definition at line 220 of file af_dynaudnorm.c.

Referenced by update_gain_history().

static void init_gaussian_filter ( DynamicAudioNormalizerContext s)
static

Definition at line 232 of file af_dynaudnorm.c.

Referenced by config_input().

static int config_input ( AVFilterLink inlink)
static

Definition at line 259 of file af_dynaudnorm.c.

static int config_output ( AVFilterLink outlink)
static

Definition at line 308 of file af_dynaudnorm.c.

static double fade ( double  prev,
double  next,
int  pos,
double *  fade_factors[2] 
)
inlinestatic

Definition at line 314 of file af_dynaudnorm.c.

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

static double pow2 ( const double  value)
inlinestatic

Definition at line 320 of file af_dynaudnorm.c.

Referenced by compute_frame_rms(), and compute_frame_std_dev().

static double bound ( const double  threshold,
const double  val 
)
inlinestatic
static double find_peak_magnitude ( AVFrame frame,
int  channel 
)
static

Definition at line 331 of file af_dynaudnorm.c.

Referenced by get_max_local_gain().

static double compute_frame_rms ( AVFrame frame,
int  channel 
)
static

Definition at line 353 of file af_dynaudnorm.c.

Referenced by get_max_local_gain().

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

Definition at line 380 of file af_dynaudnorm.c.

Referenced by analyze_frame().

static double minimum_filter ( cqueue q)
static

Definition at line 388 of file af_dynaudnorm.c.

Referenced by update_gain_history().

static double gaussian_filter ( DynamicAudioNormalizerContext s,
cqueue q 
)
static

Definition at line 400 of file af_dynaudnorm.c.

Referenced by update_gain_history().

static void update_gain_history ( DynamicAudioNormalizerContext s,
int  channel,
double  current_gain_factor 
)
static

Definition at line 412 of file af_dynaudnorm.c.

Referenced by analyze_frame().

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

Definition at line 453 of file af_dynaudnorm.c.

Referenced by perform_compression(), and perform_dc_correction().

static void perform_dc_correction ( DynamicAudioNormalizerContext s,
AVFrame frame 
)
static

Definition at line 459 of file af_dynaudnorm.c.

Referenced by analyze_frame().

static double setup_compress_thresh ( double  threshold)
static

Definition at line 482 of file af_dynaudnorm.c.

Referenced by perform_compression().

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

Definition at line 503 of file af_dynaudnorm.c.

Referenced by perform_compression().

static void perform_compression ( DynamicAudioNormalizerContext s,
AVFrame frame 
)
static

Definition at line 530 of file af_dynaudnorm.c.

Referenced by analyze_frame().

static void analyze_frame ( DynamicAudioNormalizerContext s,
AVFrame frame 
)
static

Definition at line 575 of file af_dynaudnorm.c.

Referenced by filter_frame().

static void amplify_frame ( DynamicAudioNormalizerContext s,
AVFrame frame 
)
static

Definition at line 599 of file af_dynaudnorm.c.

Referenced by filter_frame().

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 624 of file af_dynaudnorm.c.

Referenced by flush_buffer().

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

Definition at line 644 of file af_dynaudnorm.c.

Referenced by request_frame().

static int request_frame ( AVFilterLink outlink)
static

Definition at line 669 of file af_dynaudnorm.c.

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 683 of file af_dynaudnorm.c.

Variable Documentation

const AVOption dynaudnorm_options[]
static
Initial value:
= {
{ "f", "set the frame length in msec", OFFSET(frame_len_msec), AV_OPT_TYPE_INT, {.i64 = 500}, 10, 8000, FLAGS },
{ "g", "set the filter size", OFFSET(filter_size), AV_OPT_TYPE_INT, {.i64 = 31}, 3, 301, FLAGS },
{ "p", "set the peak value", OFFSET(peak_value), AV_OPT_TYPE_DOUBLE, {.dbl = 0.95}, 0.0, 1.0, FLAGS },
{ "m", "set the max amplification", OFFSET(max_amplification), AV_OPT_TYPE_DOUBLE, {.dbl = 10.0}, 1.0, 100.0, FLAGS },
{ "r", "set the target RMS", OFFSET(target_rms), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 1.0, FLAGS },
{ "n", "enable channel coupling", OFFSET(channels_coupled), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, FLAGS },
{ "c", "enable DC correction", OFFSET(dc_correction), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },
{ "b", "enable alternative boundary mode", OFFSET(alt_boundary_mode), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },
{ "s", "set the compress factor", OFFSET(compress_factor), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 30.0, FLAGS },
{ NULL }
}
#define FLAGS
Definition: af_dynaudnorm.c:77
#define NULL
Definition: coverity.c:32
#define OFFSET(x)
Definition: af_dynaudnorm.c:76

Definition at line 79 of file af_dynaudnorm.c.

const double s_pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
static

Definition at line 230 of file af_dynaudnorm.c.

Referenced by init_gaussian_filter().

const AVFilterPad avfilter_af_dynaudnorm_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_input,
.needs_writable = 1,
},
{ NULL }
}
#define NULL
Definition: coverity.c:32
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int config_input(AVFilterLink *inlink)

Definition at line 709 of file af_dynaudnorm.c.

const AVFilterPad avfilter_af_dynaudnorm_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_output,
.request_frame = request_frame,
},
{ NULL }
}
#define NULL
Definition: coverity.c:32
static int request_frame(AVFilterLink *outlink)
static int config_output(AVFilterLink *outlink)

Definition at line 720 of file af_dynaudnorm.c.

AVFilter ff_af_dynaudnorm
Initial value:
= {
.name = "dynaudnorm",
.description = NULL_IF_CONFIG_SMALL("Dynamic Audio Normalizer."),
.query_formats = query_formats,
.priv_size = sizeof(DynamicAudioNormalizerContext),
.init = init,
.priv_class = &dynaudnorm_class,
}
static const AVFilterPad avfilter_af_dynaudnorm_inputs[]
static const AVFilterPad avfilter_af_dynaudnorm_outputs[]
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
static av_cold void uninit(AVFilterContext *ctx)
static int query_formats(AVFilterContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
static av_cold int init(AVFilterContext *ctx)
Definition: af_dynaudnorm.c:94
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239

Definition at line 730 of file af_dynaudnorm.c.