FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
af_firequalizer.c File Reference
#include "libavutil/channel_layout.h"
#include "libavutil/file_open.h"
#include "libavutil/opt.h"
#include "libavutil/eval.h"
#include "libavutil/avassert.h"
#include "libavutil/tx.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 TFLAGS   AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_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, WFUNC_KAISER,
  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 void fast_convolute (FIREqualizerContext *restrict s, const float *restrict kernel_buf, float *restrict conv_buf, OverlapIndex *restrict idx, float *restrict data, int nsamples)
 
static void fast_convolute_nonlinear (FIREqualizerContext *restrict s, const float *restrict kernel_buf, float *restrict conv_buf, OverlapIndex *restrict idx, float *restrict data, int nsamples)
 
static void fast_convolute2 (FIREqualizerContext *restrict s, const float *restrict kernel_buf, AVComplexFloat *restrict conv_buf, OverlapIndex *restrict idx, float *restrict data0, float *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 []
 
const AVFilter ff_af_firequalizer
 

Macro Definition Documentation

◆ RDFT_BITS_MIN

#define RDFT_BITS_MIN   4

Definition at line 31 of file af_firequalizer.c.

◆ RDFT_BITS_MAX

#define RDFT_BITS_MAX   16

Definition at line 32 of file af_firequalizer.c.

◆ NB_GAIN_ENTRY_MAX

#define NB_GAIN_ENTRY_MAX   4096

Definition at line 56 of file af_firequalizer.c.

◆ OFFSET

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

Definition at line 126 of file af_firequalizer.c.

◆ FLAGS

Definition at line 127 of file af_firequalizer.c.

◆ TFLAGS

Definition at line 128 of file af_firequalizer.c.

◆ SELECT_GAIN

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

Definition at line 722 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 723 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 
WFUNC_KAISER 
NB_WFUNC 

Definition at line 34 of file af_firequalizer.c.

◆ Scale

enum Scale
Enumerator
SCALE_LINLIN 
SCALE_LINLOG 
SCALE_LOGLIN 
SCALE_LOGLOG 
NB_SCALE 

Definition at line 48 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 528 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 163 of file af_firequalizer.c.

Referenced by config_input(), and uninit().

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 190 of file af_firequalizer.c.

◆ fast_convolute()

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

Definition at line 199 of file af_firequalizer.c.

Referenced by filter_frame().

◆ fast_convolute_nonlinear()

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

Definition at line 236 of file af_firequalizer.c.

Referenced by filter_frame().

◆ fast_convolute2()

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

Definition at line 275 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 338 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 397 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 426 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 438 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 473 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 538 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 581 of file af_firequalizer.c.

Referenced by config_input(), and process_command().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 725 of file af_firequalizer.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame frame 
)
static

Definition at line 831 of file af_firequalizer.c.

Referenced by request_frame().

◆ request_frame()

static int request_frame ( AVFilterLink outlink)
static

Definition at line 867 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 889 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, TFLAGS },
{ "gain_entry", "set gain entry", OFFSET(gain_entry), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, TFLAGS },
{ "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, .unit = "wfunc" },
{ "rectangular", "rectangular window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_RECTANGULAR }, 0, 0, FLAGS, .unit = "wfunc" },
{ "hann", "hann window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_HANN }, 0, 0, FLAGS, .unit = "wfunc" },
{ "hamming", "hamming window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_HAMMING }, 0, 0, FLAGS, .unit = "wfunc" },
{ "blackman", "blackman window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_BLACKMAN }, 0, 0, FLAGS, .unit = "wfunc" },
{ "nuttall3", "3-term nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_NUTTALL3 }, 0, 0, FLAGS, .unit = "wfunc" },
{ "mnuttall3", "minimum 3-term nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_MNUTTALL3 }, 0, 0, FLAGS, .unit = "wfunc" },
{ "nuttall", "nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_NUTTALL }, 0, 0, FLAGS, .unit = "wfunc" },
{ "bnuttall", "blackman-nuttall window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_BNUTTALL }, 0, 0, FLAGS, .unit = "wfunc" },
{ "bharris", "blackman-harris window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_BHARRIS }, 0, 0, FLAGS, .unit = "wfunc" },
{ "tukey", "tukey window", 0, AV_OPT_TYPE_CONST, { .i64 = WFUNC_TUKEY }, 0, 0, FLAGS, .unit = "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, .unit = "scale" },
{ "linlin", "linear-freq linear-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LINLIN }, 0, 0, FLAGS, .unit = "scale" },
{ "linlog", "linear-freq logarithmic-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LINLOG }, 0, 0, FLAGS, .unit = "scale" },
{ "loglin", "logarithmic-freq linear-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LOGLIN }, 0, 0, FLAGS, .unit = "scale" },
{ "loglog", "logarithmic-freq logarithmic-gain", 0, AV_OPT_TYPE_CONST, { .i64 = SCALE_LOGLOG }, 0, 0, FLAGS, .unit = "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, .unit = "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 130 of file af_firequalizer.c.

◆ var_names

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

Definition at line 518 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,
},
}

Definition at line 938 of file af_firequalizer.c.

◆ firequalizer_outputs

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

Definition at line 948 of file af_firequalizer.c.

◆ ff_af_firequalizer

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

Definition at line 956 of file af_firequalizer.c.

AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
FILTER_SINGLE_SAMPLEFMT
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
Definition: internal.h:175
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition: af_firequalizer.c:831
SCALE_LOGLOG
@ SCALE_LOGLOG
Definition: af_firequalizer.c:52
FIREqualizerContext
Definition: af_firequalizer.c:67
WFUNC_RECTANGULAR
@ WFUNC_RECTANGULAR
Definition: af_firequalizer.c:35
WFUNC_BLACKMAN
@ WFUNC_BLACKMAN
Definition: af_firequalizer.c:38
firequalizer_outputs
static const AVFilterPad firequalizer_outputs[]
Definition: af_firequalizer.c:948
firequalizer_inputs
static const AVFilterPad firequalizer_inputs[]
Definition: af_firequalizer.c:938
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: af_firequalizer.c:867
WFUNC_NUTTALL
@ WFUNC_NUTTALL
Definition: af_firequalizer.c:41
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_firequalizer.c:190
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:237
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
WFUNC_NUTTALL3
@ WFUNC_NUTTALL3
Definition: af_firequalizer.c:39
WFUNC_BHARRIS
@ WFUNC_BHARRIS
Definition: af_firequalizer.c:43
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:182
SCALE_LINLIN
@ SCALE_LINLIN
Definition: af_firequalizer.c:49
NULL
#define NULL
Definition: coverity.c:32
FLAGS
#define FLAGS
Definition: af_firequalizer.c:127
WFUNC_HAMMING
@ WFUNC_HAMMING
Definition: af_firequalizer.c:37
OFFSET
#define OFFSET(x)
Definition: af_firequalizer.c:126
TFLAGS
#define TFLAGS
Definition: af_firequalizer.c:128
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: vvc_intra.c:291
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:106
WFUNC_TUKEY
@ WFUNC_TUKEY
Definition: af_firequalizer.c:44
WFUNC_HANN
@ WFUNC_HANN
Definition: af_firequalizer.c:36
SCALE_LINLOG
@ SCALE_LINLOG
Definition: af_firequalizer.c:50
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:889
SCALE_LOGLIN
@ SCALE_LOGLIN
Definition: af_firequalizer.c:51
NB_WFUNC
@ NB_WFUNC
Definition: af_firequalizer.c:45
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
WFUNC_BNUTTALL
@ WFUNC_BNUTTALL
Definition: af_firequalizer.c:42
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:251
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
fixed
#define fixed(width, name, value)
Definition: cbs_av1.c:487
NB_SCALE
@ NB_SCALE
Definition: af_firequalizer.c:53
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_firequalizer.c:725
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:239
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244
WFUNC_MNUTTALL3
@ WFUNC_MNUTTALL3
Definition: af_firequalizer.c:40
AVFILTERPAD_FLAG_NEEDS_WRITABLE
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
Definition: internal.h:52