FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
af_firequalizer.c File Reference
#include "libavutil/channel_layout.h"
#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 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, 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 *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 []
 
const AVFilter ff_af_firequalizer
 

Macro Definition Documentation

◆ RDFT_BITS_MIN

#define RDFT_BITS_MIN   4

Definition at line 30 of file af_firequalizer.c.

◆ RDFT_BITS_MAX

#define RDFT_BITS_MAX   16

Definition at line 31 of file af_firequalizer.c.

◆ NB_GAIN_ENTRY_MAX

#define NB_GAIN_ENTRY_MAX   4096

Definition at line 55 of file af_firequalizer.c.

◆ OFFSET

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

Definition at line 114 of file af_firequalizer.c.

◆ FLAGS

Definition at line 115 of file af_firequalizer.c.

◆ TFLAGS

Definition at line 116 of file af_firequalizer.c.

◆ SELECT_GAIN

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

Definition at line 726 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 727 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 33 of file af_firequalizer.c.

◆ Scale

enum Scale
Enumerator
SCALE_LINLIN 
SCALE_LINLOG 
SCALE_LOGLIN 
SCALE_LOGLOG 
NB_SCALE 

Definition at line 47 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 515 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 151 of file af_firequalizer.c.

Referenced by config_input(), and uninit().

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 174 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 183 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 221 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 261 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 325 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 384 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 413 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 425 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 460 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 525 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 573 of file af_firequalizer.c.

Referenced by config_input(), and process_command().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 729 of file af_firequalizer.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame frame 
)
static

Definition at line 816 of file af_firequalizer.c.

Referenced by request_frame().

◆ request_frame()

static int request_frame ( AVFilterLink outlink)
static

Definition at line 852 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 874 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, "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 118 of file af_firequalizer.c.

◆ var_names

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

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

◆ firequalizer_outputs

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

Definition at line 933 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 941 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:183
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition: af_firequalizer.c:816
SCALE_LOGLOG
@ SCALE_LOGLOG
Definition: af_firequalizer.c:51
FIREqualizerContext
Definition: af_firequalizer.c:66
WFUNC_RECTANGULAR
@ WFUNC_RECTANGULAR
Definition: af_firequalizer.c:34
WFUNC_BLACKMAN
@ WFUNC_BLACKMAN
Definition: af_firequalizer.c:37
firequalizer_outputs
static const AVFilterPad firequalizer_outputs[]
Definition: af_firequalizer.c:933
firequalizer_inputs
static const AVFilterPad firequalizer_inputs[]
Definition: af_firequalizer.c:923
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: af_firequalizer.c:852
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
WFUNC_NUTTALL
@ WFUNC_NUTTALL
Definition: af_firequalizer.c:40
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_firequalizer.c:174
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
WFUNC_NUTTALL3
@ WFUNC_NUTTALL3
Definition: af_firequalizer.c:38
WFUNC_BHARRIS
@ WFUNC_BHARRIS
Definition: af_firequalizer.c:42
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:190
SCALE_LINLIN
@ SCALE_LINLIN
Definition: af_firequalizer.c:48
NULL
#define NULL
Definition: coverity.c:32
FLAGS
#define FLAGS
Definition: af_firequalizer.c:115
WFUNC_HAMMING
@ WFUNC_HAMMING
Definition: af_firequalizer.c:36
OFFSET
#define OFFSET(x)
Definition: af_firequalizer.c:114
TFLAGS
#define TFLAGS
Definition: af_firequalizer.c:116
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
WFUNC_TUKEY
@ WFUNC_TUKEY
Definition: af_firequalizer.c:43
WFUNC_HANN
@ WFUNC_HANN
Definition: af_firequalizer.c:35
SCALE_LINLOG
@ SCALE_LINLOG
Definition: af_firequalizer.c:49
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:874
SCALE_LOGLIN
@ SCALE_LOGLIN
Definition: af_firequalizer.c:50
NB_WFUNC
@ NB_WFUNC
Definition: af_firequalizer.c:44
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
WFUNC_BNUTTALL
@ WFUNC_BNUTTALL
Definition: af_firequalizer.c:41
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:191
fixed
#define fixed(width, name, value)
Definition: cbs_av1.c:566
NB_SCALE
@ NB_SCALE
Definition: af_firequalizer.c:52
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_firequalizer.c:729
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
WFUNC_MNUTTALL3
@ WFUNC_MNUTTALL3
Definition: af_firequalizer.c:39
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:68