FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
af_firequalizer.c File Reference
#include "libavutil/channel_layout.h"
#include "libavutil/file_open.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/eval.h"
#include "libavutil/avassert.h"
#include "libavutil/tx.h"
#include "avfilter.h"
#include "filters.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 32 of file af_firequalizer.c.

◆ RDFT_BITS_MAX

#define RDFT_BITS_MAX   16

Definition at line 33 of file af_firequalizer.c.

◆ NB_GAIN_ENTRY_MAX

#define NB_GAIN_ENTRY_MAX   4096

Definition at line 57 of file af_firequalizer.c.

◆ OFFSET

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

Definition at line 127 of file af_firequalizer.c.

◆ FLAGS

Definition at line 128 of file af_firequalizer.c.

◆ TFLAGS

Definition at line 129 of file af_firequalizer.c.

◆ SELECT_GAIN

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

Definition at line 723 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 724 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 35 of file af_firequalizer.c.

◆ Scale

enum Scale
Enumerator
SCALE_LINLIN 
SCALE_LINLOG 
SCALE_LOGLIN 
SCALE_LOGLOG 
NB_SCALE 

Definition at line 49 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 529 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 164 of file af_firequalizer.c.

Referenced by config_input(), and uninit().

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 191 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 200 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 237 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 276 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 339 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 398 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 427 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 439 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 474 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 539 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 582 of file af_firequalizer.c.

Referenced by config_input(), and process_command().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 726 of file af_firequalizer.c.

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame frame 
)
static

Definition at line 833 of file af_firequalizer.c.

Referenced by request_frame().

◆ request_frame()

static int request_frame ( AVFilterLink outlink)
static

Definition at line 869 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 891 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 131 of file af_firequalizer.c.

◆ var_names

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

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

◆ firequalizer_outputs

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

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

AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
Definition: af_firequalizer.c:833
SCALE_LOGLOG
@ SCALE_LOGLOG
Definition: af_firequalizer.c:53
FIREqualizerContext
Definition: af_firequalizer.c:68
WFUNC_RECTANGULAR
@ WFUNC_RECTANGULAR
Definition: af_firequalizer.c:36
WFUNC_BLACKMAN
@ WFUNC_BLACKMAN
Definition: af_firequalizer.c:39
firequalizer_outputs
static const AVFilterPad firequalizer_outputs[]
Definition: af_firequalizer.c:950
firequalizer_inputs
static const AVFilterPad firequalizer_inputs[]
Definition: af_firequalizer.c:940
request_frame
static int request_frame(AVFilterLink *outlink)
Definition: af_firequalizer.c:869
WFUNC_NUTTALL
@ WFUNC_NUTTALL
Definition: af_firequalizer.c:42
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_firequalizer.c:191
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition: opt.h:267
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
WFUNC_NUTTALL3
@ WFUNC_NUTTALL3
Definition: af_firequalizer.c:40
WFUNC_BHARRIS
@ WFUNC_BHARRIS
Definition: af_firequalizer.c:44
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
SCALE_LINLIN
@ SCALE_LINLIN
Definition: af_firequalizer.c:50
NULL
#define NULL
Definition: coverity.c:32
FLAGS
#define FLAGS
Definition: af_firequalizer.c:128
WFUNC_HAMMING
@ WFUNC_HAMMING
Definition: af_firequalizer.c:38
OFFSET
#define OFFSET(x)
Definition: af_firequalizer.c:127
AVFILTERPAD_FLAG_NEEDS_WRITABLE
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.
Definition: filters.h:57
FILTER_SINGLE_SAMPLEFMT
#define FILTER_SINGLE_SAMPLEFMT(sample_fmt_)
Definition: filters.h:255
TFLAGS
#define TFLAGS
Definition: af_firequalizer.c:129
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:94
WFUNC_TUKEY
@ WFUNC_TUKEY
Definition: af_firequalizer.c:45
WFUNC_HANN
@ WFUNC_HANN
Definition: af_firequalizer.c:37
SCALE_LINLOG
@ SCALE_LINLOG
Definition: af_firequalizer.c:51
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:891
SCALE_LOGLIN
@ SCALE_LOGLIN
Definition: af_firequalizer.c:52
NB_WFUNC
@ NB_WFUNC
Definition: af_firequalizer.c:46
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
WFUNC_BNUTTALL
@ WFUNC_BNUTTALL
Definition: af_firequalizer.c:43
scale
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition: intra.c:291
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
fixed
#define fixed(width, name, value)
Definition: cbs_av1.c:487
NB_SCALE
@ NB_SCALE
Definition: af_firequalizer.c:54
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_firequalizer.c:726
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
WFUNC_MNUTTALL3
@ WFUNC_MNUTTALL3
Definition: af_firequalizer.c:41