FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
af_afftdn.c File Reference
#include <float.h>
#include "libavutil/audio_fifo.h"
#include "libavutil/avstring.h"
#include "libavutil/channel_layout.h"
#include "libavutil/opt.h"
#include "libavcodec/avfft.h"
#include "avfilter.h"
#include "audio.h"
#include "formats.h"
#include "filters.h"

Go to the source code of this file.

Data Structures

struct  DeNoiseChannel
 
struct  AudioFFTDeNoiseContext
 
struct  ThreadData
 Used for passing data between threads. More...
 

Macros

#define C   (M_LN10 * 0.1)
 
#define RATIO   0.98
 
#define RRATIO   (1.0 - RATIO)
 
#define OFFSET(x)   offsetof(AudioFFTDeNoiseContext, x)
 
#define A   AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 

Enumerations

enum  OutModes {
  IN_MODE, OUT_MODE, NOISE_MODE, NB_MODES,
  IN_MODE, OUT_MODE, NOISE_MODE, NB_MODES,
  IN_MODE, OUT_MODE, ESS_MODE, NB_MODES
}
 
enum  NoiseType {
  WHITE_NOISE, VINYL_NOISE, SHELLAC_NOISE, CUSTOM_NOISE,
  NB_NOISE
}
 

Functions

 AVFILTER_DEFINE_CLASS (afftdn)
 
static int get_band_noise (AudioFFTDeNoiseContext *s, int band, double a, double b, double c)
 
static void factor (double *array, int size)
 
static void solve (double *matrix, double *vector, int size)
 
static int process_get_band_noise (AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, int band)
 
static void calculate_sfm (AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, int start, int end)
 
static double limit_gain (double a, double b)
 
static void process_frame (AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, FFTComplex *fft_data, double *prior, double *prior_band_excit, int track_noise)
 
static double freq2bark (double x)
 
static int get_band_centre (AudioFFTDeNoiseContext *s, int band)
 
static int get_band_edge (AudioFFTDeNoiseContext *s, int band)
 
static void set_band_parameters (AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch)
 
static void read_custom_noise (AudioFFTDeNoiseContext *s, int ch)
 
static void set_parameters (AudioFFTDeNoiseContext *s)
 
static int config_input (AVFilterLink *inlink)
 
static void preprocess (FFTComplex *in, int len)
 
static void postprocess (FFTComplex *in, int len)
 
static void init_sample_noise (DeNoiseChannel *dnch)
 
static void sample_noise_block (AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, AVFrame *in, int ch)
 
static void finish_sample_noise (AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, double *sample_noise)
 
static void set_noise_profile (AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, double *sample_noise, int new_profile)
 
static int filter_channel (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static void get_auto_noise_levels (AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, double *levels)
 
static int output_frame (AVFilterLink *inlink)
 
static int activate (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int query_formats (AVFilterContext *ctx)
 
static int process_command (AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
 

Variables

static const AVOption afftdn_options []
 
static const AVFilterPad inputs []
 
static const AVFilterPad outputs []
 
AVFilter ff_af_afftdn
 

Macro Definition Documentation

◆ C

#define C   (M_LN10 * 0.1)

Definition at line 33 of file af_afftdn.c.

◆ RATIO

#define RATIO   0.98

Definition at line 34 of file af_afftdn.c.

◆ RRATIO

#define RRATIO   (1.0 - RATIO)

Definition at line 35 of file af_afftdn.c.

◆ OFFSET

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

Definition at line 143 of file af_afftdn.c.

◆ A

Definition at line 144 of file af_afftdn.c.

Enumeration Type Documentation

◆ OutModes

enum OutModes
Enumerator
IN_MODE 
OUT_MODE 
NOISE_MODE 
NB_MODES 
IN_MODE 
OUT_MODE 
NOISE_MODE 
NB_MODES 
IN_MODE 
OUT_MODE 
ESS_MODE 
NB_MODES 

Definition at line 37 of file af_afftdn.c.

◆ NoiseType

enum NoiseType
Enumerator
WHITE_NOISE 
VINYL_NOISE 
SHELLAC_NOISE 
CUSTOM_NOISE 
NB_NOISE 

Definition at line 44 of file af_afftdn.c.

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( afftdn  )

◆ get_band_noise()

static int get_band_noise ( AudioFFTDeNoiseContext s,
int  band,
double  a,
double  b,
double  c 
)
static

Definition at line 167 of file af_afftdn.c.

Referenced by config_input().

◆ factor()

static void factor ( double *  array,
int  size 
)
static

Definition at line 183 of file af_afftdn.c.

Referenced by config_input().

◆ solve()

static void solve ( double *  matrix,
double *  vector,
int  size 
)
static

Definition at line 197 of file af_afftdn.c.

Referenced by process_get_band_noise(), and set_noise_profile().

◆ process_get_band_noise()

static int process_get_band_noise ( AudioFFTDeNoiseContext s,
DeNoiseChannel dnch,
int  band 
)
static

Definition at line 216 of file af_afftdn.c.

Referenced by set_band_parameters().

◆ calculate_sfm()

static void calculate_sfm ( AudioFFTDeNoiseContext s,
DeNoiseChannel dnch,
int  start,
int  end 
)
static

Definition at line 246 of file af_afftdn.c.

Referenced by process_frame().

◆ limit_gain()

static double limit_gain ( double  a,
double  b 
)
static

Definition at line 282 of file af_afftdn.c.

Referenced by process_frame().

◆ process_frame()

static void process_frame ( AudioFFTDeNoiseContext s,
DeNoiseChannel dnch,
FFTComplex fft_data,
double *  prior,
double *  prior_band_excit,
int  track_noise 
)
static

Definition at line 291 of file af_afftdn.c.

Referenced by filter_channel().

◆ freq2bark()

static double freq2bark ( double  x)
static

Definition at line 484 of file af_afftdn.c.

Referenced by config_input().

◆ get_band_centre()

static int get_band_centre ( AudioFFTDeNoiseContext s,
int  band 
)
static

Definition at line 491 of file af_afftdn.c.

Referenced by set_band_parameters().

◆ get_band_edge()

static int get_band_edge ( AudioFFTDeNoiseContext s,
int  band 
)
static

Definition at line 499 of file af_afftdn.c.

Referenced by config_input().

◆ set_band_parameters()

static void set_band_parameters ( AudioFFTDeNoiseContext s,
DeNoiseChannel dnch 
)
static

Definition at line 512 of file af_afftdn.c.

Referenced by output_frame(), and set_parameters().

◆ read_custom_noise()

static void read_custom_noise ( AudioFFTDeNoiseContext s,
int  ch 
)
static

Definition at line 548 of file af_afftdn.c.

Referenced by config_input().

◆ set_parameters()

static void set_parameters ( AudioFFTDeNoiseContext s)
static

Definition at line 580 of file af_afftdn.c.

Referenced by config_input(), output_frame(), and process_command().

◆ config_input()

static int config_input ( AVFilterLink inlink)
static

Definition at line 609 of file af_afftdn.c.

◆ preprocess()

static void preprocess ( FFTComplex in,
int  len 
)
static

Definition at line 857 of file af_afftdn.c.

Referenced by filter_channel(), and sample_noise_block().

◆ postprocess()

static void postprocess ( FFTComplex in,
int  len 
)
static

Definition at line 890 of file af_afftdn.c.

Referenced by filter_channel().

◆ init_sample_noise()

static void init_sample_noise ( DeNoiseChannel dnch)
static

Definition at line 921 of file af_afftdn.c.

Referenced by output_frame().

◆ sample_noise_block()

static void sample_noise_block ( AudioFFTDeNoiseContext s,
DeNoiseChannel dnch,
AVFrame in,
int  ch 
)
static

Definition at line 931 of file af_afftdn.c.

Referenced by output_frame().

◆ finish_sample_noise()

static void finish_sample_noise ( AudioFFTDeNoiseContext s,
DeNoiseChannel dnch,
double *  sample_noise 
)
static

Definition at line 999 of file af_afftdn.c.

Referenced by output_frame().

◆ set_noise_profile()

static void set_noise_profile ( AudioFFTDeNoiseContext s,
DeNoiseChannel dnch,
double *  sample_noise,
int  new_profile 
)
static

Definition at line 1018 of file af_afftdn.c.

Referenced by output_frame().

◆ filter_channel()

static int filter_channel ( AVFilterContext ctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Definition at line 1085 of file af_afftdn.c.

Referenced by output_frame().

◆ get_auto_noise_levels()

static void get_auto_noise_levels ( AudioFFTDeNoiseContext s,
DeNoiseChannel dnch,
double *  levels 
)
static

Definition at line 1138 of file af_afftdn.c.

Referenced by output_frame().

◆ output_frame()

static int output_frame ( AVFilterLink inlink)
static

Definition at line 1157 of file af_afftdn.c.

Referenced by activate().

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 1270 of file af_afftdn.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 1307 of file af_afftdn.c.

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 1344 of file af_afftdn.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 1373 of file af_afftdn.c.

Variable Documentation

◆ afftdn_options

const AVOption afftdn_options[]
static
Initial value:
= {
{ "nr", "set the noise reduction", OFFSET(noise_reduction), AV_OPT_TYPE_FLOAT, {.dbl = 12}, .01, 97, A },
{ "nf", "set the noise floor", OFFSET(noise_floor), AV_OPT_TYPE_FLOAT, {.dbl =-50}, -80,-20, A },
{ "nt", "set the noise type", OFFSET(noise_type), AV_OPT_TYPE_INT, {.i64 = WHITE_NOISE}, WHITE_NOISE, NB_NOISE-1, A, "type" },
{ "w", "white noise", 0, AV_OPT_TYPE_CONST, {.i64 = WHITE_NOISE}, 0, 0, A, "type" },
{ "v", "vinyl noise", 0, AV_OPT_TYPE_CONST, {.i64 = VINYL_NOISE}, 0, 0, A, "type" },
{ "s", "shellac noise", 0, AV_OPT_TYPE_CONST, {.i64 = SHELLAC_NOISE}, 0, 0, A, "type" },
{ "c", "custom noise", 0, AV_OPT_TYPE_CONST, {.i64 = CUSTOM_NOISE}, 0, 0, A, "type" },
{ "bn", "set the custom bands noise", OFFSET(band_noise_str), AV_OPT_TYPE_STRING, {.str = 0}, 0, 0, A },
{ "rf", "set the residual floor", OFFSET(residual_floor), AV_OPT_TYPE_FLOAT, {.dbl =-38}, -80,-20, A },
{ "tn", "track noise", OFFSET(track_noise), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, A },
{ "tr", "track residual", OFFSET(track_residual), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, A },
{ "om", "set output mode", OFFSET(output_mode), AV_OPT_TYPE_INT, {.i64 = OUT_MODE}, 0, NB_MODES-1, A, "mode" },
{ "i", "input", 0, AV_OPT_TYPE_CONST, {.i64 = IN_MODE}, 0, 0, A, "mode" },
{ "o", "output", 0, AV_OPT_TYPE_CONST, {.i64 = OUT_MODE}, 0, 0, A, "mode" },
{ "n", "noise", 0, AV_OPT_TYPE_CONST, {.i64 = NOISE_MODE}, 0, 0, A, "mode" },
{ NULL }
}

Definition at line 146 of file af_afftdn.c.

◆ inputs

const AVFilterPad inputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_input,
},
{ NULL }
}

Definition at line 1422 of file af_afftdn.c.

◆ outputs

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

Definition at line 1431 of file af_afftdn.c.

◆ ff_af_afftdn

AVFilter ff_af_afftdn
Initial value:
= {
.name = "afftdn",
.description = NULL_IF_CONFIG_SMALL("Denoise audio samples using FFT."),
.query_formats = query_formats,
.priv_size = sizeof(AudioFFTDeNoiseContext),
.priv_class = &afftdn_class,
}

Definition at line 1439 of file af_afftdn.c.

NB_MODES
@ NB_MODES
Definition: af_afftdn.c:41
activate
static int activate(AVFilterContext *ctx)
Definition: af_afftdn.c:1270
inputs
static const AVFilterPad inputs[]
Definition: af_afftdn.c:1422
OUT_MODE
@ OUT_MODE
Definition: af_afftdn.c:39
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_afftdn.c:609
OFFSET
#define OFFSET(x)
Definition: af_afftdn.c:143
NB_NOISE
@ NB_NOISE
Definition: af_afftdn.c:49
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AudioFFTDeNoiseContext
Definition: af_afftdn.c:84
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_afftdn.c:1344
NULL
#define NULL
Definition: coverity.c:32
WHITE_NOISE
@ WHITE_NOISE
Definition: af_afftdn.c:45
NOISE_MODE
@ NOISE_MODE
Definition: af_afftdn.c:40
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
outputs
static const AVFilterPad outputs[]
Definition: af_afftdn.c:1431
VINYL_NOISE
@ VINYL_NOISE
Definition: af_afftdn.c:46
A
#define A
Definition: af_afftdn.c:144
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_afftdn.c:1307
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:125
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:226
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: af_afftdn.c:1373
SHELLAC_NOISE
@ SHELLAC_NOISE
Definition: af_afftdn.c:47
CUSTOM_NOISE
@ CUSTOM_NOISE
Definition: af_afftdn.c:48
IN_MODE
@ IN_MODE
Definition: af_afftdn.c:38
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:116
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:240
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:227
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:232