FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
af_firequalizer.c File Reference
#include "libavutil/opt.h"
#include "libavutil/eval.h"
#include "libavutil/avassert.h"
#include "libavcodec/avfft.h"
#include "avfilter.h"
#include "internal.h"
#include "audio.h"

Go to the source code of this file.

Data Structures

struct  GainEntry
 
struct  OverlapIndex
 
struct  FIREqualizerContext
 

Macros

#define RDFT_BITS_MIN   4
 
#define RDFT_BITS_MAX   16
 
#define NB_GAIN_ENTRY_MAX   4096
 
#define OFFSET(x)   offsetof(FIREqualizerContext, x)
 
#define FLAGS   AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 
#define SELECT_GAIN(s)   (s->gain_cmd ? s->gain_cmd : s->gain)
 
#define SELECT_GAIN_ENTRY(s)   (s->gain_entry_cmd ? s->gain_entry_cmd : s->gain_entry)
 

Enumerations

enum  WindowFunc {
  WFUNC_RECTANGULAR, WFUNC_HANN, WFUNC_HAMMING, WFUNC_BLACKMAN,
  WFUNC_NUTTALL3, WFUNC_MNUTTALL3, WFUNC_NUTTALL, WFUNC_BNUTTALL,
  WFUNC_BHARRIS, WFUNC_TUKEY, NB_WFUNC, WFUNC_RECT,
  WFUNC_HANNING, WFUNC_HAMMING, WFUNC_BLACKMAN, WFUNC_BARTLETT,
  WFUNC_WELCH, WFUNC_FLATTOP, WFUNC_BHARRIS, WFUNC_BNUTTALL,
  WFUNC_SINE, WFUNC_NUTTALL, WFUNC_BHANN, WFUNC_LANCZOS,
  WFUNC_GAUSS, WFUNC_TUKEY, WFUNC_DOLPH, WFUNC_CAUCHY,
  WFUNC_PARZEN, WFUNC_POISSON, WFUNC_BOHMAN, NB_WFUNC
}
 
enum  Scale {
  SCALE_LINLIN, SCALE_LINLOG, SCALE_LOGLIN, SCALE_LOGLOG,
  NB_SCALE
}
 
enum  VarOffset {
  VAR_F, VAR_SR, VAR_CH, VAR_CHID,
  VAR_CHS, VAR_CHLAYOUT, VAR_NB
}
 

Functions

 AVFILTER_DEFINE_CLASS (firequalizer)
 
static void common_uninit (FIREqualizerContext *s)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int query_formats (AVFilterContext *ctx)
 
static void fast_convolute (FIREqualizerContext *av_restrict s, const float *av_restrict kernel_buf, float *av_restrict conv_buf, OverlapIndex *av_restrict idx, float *av_restrict data, int nsamples)
 
static void fast_convolute_nonlinear (FIREqualizerContext *av_restrict s, const float *av_restrict kernel_buf, float *av_restrict conv_buf, OverlapIndex *av_restrict idx, float *av_restrict data, int nsamples)
 
static void fast_convolute2 (FIREqualizerContext *av_restrict s, const float *av_restrict kernel_buf, FFTComplex *av_restrict conv_buf, OverlapIndex *av_restrict idx, float *av_restrict data0, float *av_restrict data1, int nsamples)
 
static void dump_fir (AVFilterContext *ctx, FILE *fp, int ch)
 
static double entry_func (void *p, double freq, double gain)
 
static int gain_entry_compare (const void *key, const void *memb)
 
static double gain_interpolate_func (void *p, double freq)
 
static double cubic_interpolate_func (void *p, double freq)
 
static void generate_min_phase_kernel (FIREqualizerContext *s, float *rdft_buf)
 
static int generate_kernel (AVFilterContext *ctx, const char *gain, const char *gain_entry)
 
static int config_input (AVFilterLink *inlink)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *frame)
 
static int request_frame (AVFilterLink *outlink)
 
static int process_command (AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
 

Variables

static const AVOption firequalizer_options []
 
static const char *const var_names []
 
static const AVFilterPad firequalizer_inputs []
 
static const AVFilterPad firequalizer_outputs []
 
AVFilter ff_af_firequalizer
 

Macro Definition Documentation

◆ RDFT_BITS_MIN

#define RDFT_BITS_MIN   4

Definition at line 29 of file af_firequalizer.c.

◆ RDFT_BITS_MAX

#define RDFT_BITS_MAX   16

Definition at line 30 of file af_firequalizer.c.

◆ NB_GAIN_ENTRY_MAX

#define NB_GAIN_ENTRY_MAX   4096

Definition at line 54 of file af_firequalizer.c.

◆ OFFSET

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

Definition at line 113 of file af_firequalizer.c.

◆ FLAGS

Definition at line 114 of file af_firequalizer.c.

◆ SELECT_GAIN

#define SELECT_GAIN (   s)    (s->gain_cmd ? s->gain_cmd : s->gain)

Definition at line 753 of file af_firequalizer.c.

◆ SELECT_GAIN_ENTRY

#define SELECT_GAIN_ENTRY (   s)    (s->gain_entry_cmd ? s->gain_entry_cmd : s->gain_entry)

Definition at line 754 of file af_firequalizer.c.

Enumeration Type Documentation

◆ WindowFunc

enum WindowFunc
Enumerator
WFUNC_RECTANGULAR 
WFUNC_HANN 
WFUNC_HAMMING 
WFUNC_BLACKMAN 
WFUNC_NUTTALL3 
WFUNC_MNUTTALL3 
WFUNC_NUTTALL 
WFUNC_BNUTTALL 
WFUNC_BHARRIS 
WFUNC_TUKEY 
NB_WFUNC 
WFUNC_RECT 
WFUNC_HANNING 
WFUNC_HAMMING 
WFUNC_BLACKMAN 
WFUNC_BARTLETT 
WFUNC_WELCH 
WFUNC_FLATTOP 
WFUNC_BHARRIS 
WFUNC_BNUTTALL 
WFUNC_SINE 
WFUNC_NUTTALL 
WFUNC_BHANN 
WFUNC_LANCZOS 
WFUNC_GAUSS 
WFUNC_TUKEY 
WFUNC_DOLPH 
WFUNC_CAUCHY 
WFUNC_PARZEN 
WFUNC_POISSON 
WFUNC_BOHMAN 
NB_WFUNC 

Definition at line 32 of file af_firequalizer.c.

◆ Scale

enum Scale
Enumerator
SCALE_LINLIN 
SCALE_LINLOG 
SCALE_LOGLIN 
SCALE_LOGLOG 
NB_SCALE 

Definition at line 46 of file af_firequalizer.c.

◆ VarOffset

enum VarOffset
Enumerator
VAR_F 
VAR_SR 
VAR_CH 
VAR_CHID 
VAR_CHS 
VAR_CHLAYOUT 
VAR_NB 

Definition at line 543 of file af_firequalizer.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( firequalizer  )

◆ common_uninit()

static void common_uninit ( FIREqualizerContext s)
static

Definition at line 149 of file af_firequalizer.c.

Referenced by config_input(), and uninit().

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 172 of file af_firequalizer.c.

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 181 of file af_firequalizer.c.

◆ fast_convolute()

static void fast_convolute ( FIREqualizerContext *av_restrict  s,
const float *av_restrict  kernel_buf,
float *av_restrict  conv_buf,
OverlapIndex *av_restrict  idx,
float *av_restrict  data,
int  nsamples 
)
static

Definition at line 211 of file af_firequalizer.c.

Referenced by filter_frame().

◆ fast_convolute_nonlinear()

static void fast_convolute_nonlinear ( FIREqualizerContext *av_restrict  s,
const float *av_restrict  kernel_buf,
float *av_restrict  conv_buf,
OverlapIndex *av_restrict  idx,
float *av_restrict  data,
int  nsamples 
)
static

Definition at line 249 of file af_firequalizer.c.

Referenced by filter_frame().

◆ fast_convolute2()

static void fast_convolute2 ( FIREqualizerContext *av_restrict  s,
const float *av_restrict  kernel_buf,
FFTComplex *av_restrict  conv_buf,
OverlapIndex *av_restrict  idx,
float *av_restrict  data0,
float *av_restrict  data1,
int  nsamples 
)
static

Definition at line 289 of file af_firequalizer.c.

Referenced by filter_frame().

◆ dump_fir()

static void dump_fir ( AVFilterContext ctx,
FILE *  fp,
int  ch 
)
static

Definition at line 353 of file af_firequalizer.c.

Referenced by generate_kernel().

◆ entry_func()

static double entry_func ( void *  p,
double  freq,
double  gain 
)
static

Definition at line 412 of file af_firequalizer.c.

Referenced by generate_kernel().

◆ gain_entry_compare()

static int gain_entry_compare ( const void *  key,
const void *  memb 
)
static

Definition at line 441 of file af_firequalizer.c.

Referenced by cubic_interpolate_func(), and gain_interpolate_func().

◆ gain_interpolate_func()

static double gain_interpolate_func ( void *  p,
double  freq 
)
static

Definition at line 453 of file af_firequalizer.c.

Referenced by generate_kernel().

◆ cubic_interpolate_func()

static double cubic_interpolate_func ( void *  p,
double  freq 
)
static

Definition at line 488 of file af_firequalizer.c.

Referenced by generate_kernel().

◆ generate_min_phase_kernel()

static void generate_min_phase_kernel ( FIREqualizerContext s,
float *  rdft_buf 
)
static

Definition at line 553 of file af_firequalizer.c.

Referenced by generate_kernel().

◆ generate_kernel()

static int generate_kernel ( AVFilterContext ctx,
const char *  gain,
const char *  gain_entry 
)
static

Definition at line 601 of file af_firequalizer.c.

Referenced by config_input(), and process_command().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 756 of file af_firequalizer.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame frame 
)
static

Definition at line 843 of file af_firequalizer.c.

Referenced by request_frame().

◆ request_frame()

static int request_frame ( AVFilterLink outlink)
static

Definition at line 879 of file af_firequalizer.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 901 of file af_firequalizer.c.

Variable Documentation

◆ firequalizer_options

const AVOption firequalizer_options[]
static
Initial value:
= {
{ "gain", "set gain curve", OFFSET(gain), AV_OPT_TYPE_STRING, { .str = "gain_interpolate(f)" }, 0, 0, FLAGS },
{ "gain_entry", "set gain entry", OFFSET(gain_entry), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
{ "delay", "set delay", OFFSET(delay), AV_OPT_TYPE_DOUBLE, { .dbl = 0.01 }, 0.0, 1e10, FLAGS },
{ "accuracy", "set accuracy", OFFSET(accuracy), AV_OPT_TYPE_DOUBLE, { .dbl = 5.0 }, 0.0, 1e10, FLAGS },
{ "wfunc", "set window function", OFFSET(wfunc), AV_OPT_TYPE_INT, { .i64 = WFUNC_HANN }, 0, NB_WFUNC-1, FLAGS, "wfunc" },
{ "rectangular", "rectangular window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_RECTANGULAR }, 0, 0, FLAGS, "wfunc" },
{ "hann", "hann window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_HANN }, 0, 0, FLAGS, "wfunc" },
{ "hamming", "hamming window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_HAMMING }, 0, 0, FLAGS, "wfunc" },
{ "blackman", "blackman window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_BLACKMAN }, 0, 0, FLAGS, "wfunc" },
{ "nuttall3", "3-term nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_NUTTALL3 }, 0, 0, FLAGS, "wfunc" },
{ "mnuttall3", "minimum 3-term nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_MNUTTALL3 }, 0, 0, FLAGS, "wfunc" },
{ "nuttall", "nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_NUTTALL }, 0, 0, FLAGS, "wfunc" },
{ "bnuttall", "blackman-nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_BNUTTALL }, 0, 0, FLAGS, "wfunc" },
{ "bharris", "blackman-harris window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_BHARRIS }, 0, 0, FLAGS, "wfunc" },
{ "tukey", "tukey window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_TUKEY }, 0, 0, FLAGS, "wfunc" },
{ "fixed", "set fixed frame samples", OFFSET(fixed), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ "multi", "set multi channels mode", OFFSET(multi), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ "zero_phase", "set zero phase mode", OFFSET(zero_phase), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ "scale", "set gain scale", OFFSET(scale), AV_OPT_TYPE_INT, { .i64 = SCALE_LINLOG }, 0, NB_SCALE-1, FLAGS, "scale" },
{ "linlin", "linear-freq linear-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LINLIN }, 0, 0, FLAGS, "scale" },
{ "linlog", "linear-freq logarithmic-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LINLOG }, 0, 0, FLAGS, "scale" },
{ "loglin", "logarithmic-freq linear-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LOGLIN }, 0, 0, FLAGS, "scale" },
{ "loglog", "logarithmic-freq logarithmic-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LOGLOG }, 0, 0, FLAGS, "scale" },
{ "dumpfile", "set dump file", OFFSET(dumpfile), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, FLAGS },
{ "dumpscale", "set dump scale", OFFSET(dumpscale), AV_OPT_TYPE_INT, { .i64 = SCALE_LINLOG }, 0, NB_SCALE-1, FLAGS, "scale" },
{ "fft2", "set 2-channels fft", OFFSET(fft2), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ "min_phase", "set minimum phase mode", OFFSET(min_phase), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
{ NULL }
}

Definition at line 116 of file af_firequalizer.c.

◆ var_names

const char* const var_names[]
static
Initial value:
= {
"f",
"sr",
"ch",
"chid",
"chs",
"chlayout",
}

Definition at line 533 of file af_firequalizer.c.

Referenced by generate_kernel().

◆ firequalizer_inputs

const AVFilterPad firequalizer_inputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_input,
.filter_frame = filter_frame,
.needs_writable = 1,
},
{ NULL }
}

Definition at line 950 of file af_firequalizer.c.

◆ firequalizer_outputs

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

Definition at line 961 of file af_firequalizer.c.

◆ ff_af_firequalizer

AVFilter ff_af_firequalizer
Initial value:
= {
.name = "firequalizer",
.description = NULL_IF_CONFIG_SMALL("Finite Impulse Response Equalizer."),
.uninit = uninit,
.query_formats = query_formats,
.process_command = process_command,
.priv_size = sizeof(FIREqualizerContext),
.priv_class = &firequalizer_class,
}

Definition at line 970 of file af_firequalizer.c.

filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition: af_firequalizer.c:843
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_firequalizer.c:181
SCALE_LOGLOG
@ SCALE_LOGLOG
Definition: af_firequalizer.c:50
FIREqualizerContext
Definition: af_firequalizer.c:65
WFUNC_RECTANGULAR
@ WFUNC_RECTANGULAR
Definition: af_firequalizer.c:33
WFUNC_BLACKMAN
@ WFUNC_BLACKMAN
Definition: af_firequalizer.c:36
firequalizer_outputs
static const AVFilterPad firequalizer_outputs[]
Definition: af_firequalizer.c:961
firequalizer_inputs
static const AVFilterPad firequalizer_inputs[]
Definition: af_firequalizer.c:950
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: af_firequalizer.c:879
WFUNC_NUTTALL
@ WFUNC_NUTTALL
Definition: af_firequalizer.c:39
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_firequalizer.c:172
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:225
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
WFUNC_NUTTALL3
@ WFUNC_NUTTALL3
Definition: af_firequalizer.c:37
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
WFUNC_BHARRIS
@ WFUNC_BHARRIS
Definition: af_firequalizer.c:41
SCALE_LINLIN
@ SCALE_LINLIN
Definition: af_firequalizer.c:47
NULL
#define NULL
Definition: coverity.c:32
FLAGS
#define FLAGS
Definition: af_firequalizer.c:114
WFUNC_HAMMING
@ WFUNC_HAMMING
Definition: af_firequalizer.c:35
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
OFFSET
#define OFFSET(x)
Definition: af_firequalizer.c:113
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:188
WFUNC_TUKEY
@ WFUNC_TUKEY
Definition: af_firequalizer.c:42
WFUNC_HANN
@ WFUNC_HANN
Definition: af_firequalizer.c:34
SCALE_LINLOG
@ SCALE_LINLOG
Definition: af_firequalizer.c:48
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_firequalizer.c:901
SCALE_LOGLIN
@ SCALE_LOGLIN
Definition: af_firequalizer.c:49
NB_WFUNC
@ NB_WFUNC
Definition: af_firequalizer.c:43
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
WFUNC_BNUTTALL
@ WFUNC_BNUTTALL
Definition: af_firequalizer.c:40
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:240
fixed
#define fixed(width, name, value)
Definition: cbs_av1.c:570
NB_SCALE
@ NB_SCALE
Definition: af_firequalizer.c:51
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_firequalizer.c:756
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:227
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:232
WFUNC_MNUTTALL3
@ WFUNC_MNUTTALL3
Definition: af_firequalizer.c:38