FFmpeg
Data Structures | Macros | Functions | Variables
af_mcompand.c File Reference
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/ffmath.h"
#include "libavutil/opt.h"
#include "libavutil/samplefmt.h"
#include "audio.h"
#include "avfilter.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  CompandSegment
 
struct  CompandT
 
struct  PrevCrossover
 
struct  Crossover
 
struct  CompBand
 
struct  MCompandContext
 

Macros

#define N   4
 
#define OFFSET(x)   offsetof(MCompandContext, x)
 
#define A   AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 
#define S(x)   s->segments[2 * ((x) + 1)]
 
#define S(x)   s->segments[2 * (x)]
 
#define L(x)   s->segments[i - (x)]
 
#define CONVOLVE   _ _ _ _
 
#define _
 
#define _
 

Functions

 AVFILTER_DEFINE_CLASS (mcompand)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int query_formats (AVFilterContext *ctx)
 
static void count_items (char *item_str, int *nb_items, char delimiter)
 
static void update_volume (CompBand *cb, double in, int ch)
 
static double get_volume (CompandT *s, double in_lin)
 
static int parse_points (char *points, int nb_points, double radius, CompandT *s, AVFilterContext *ctx)
 
static void square_quadratic (double const *x, double *y)
 
static int crossover_setup (AVFilterLink *outlink, Crossover *p, double frequency)
 
static int config_output (AVFilterLink *outlink)
 
static void crossover (int ch, Crossover *p, double *ibuf, double *obuf_low, double *obuf_high, size_t len)
 
static int mcompand_channel (MCompandContext *c, CompBand *l, double *ibuf, double *obuf, int len, int ch)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
static int request_frame (AVFilterLink *outlink)
 

Variables

static const AVOption mcompand_options []
 
static const AVFilterPad mcompand_inputs []
 
static const AVFilterPad mcompand_outputs []
 
AVFilter ff_af_mcompand
 

Detailed Description

audio multiband compand filter

Definition in file af_mcompand.c.

Macro Definition Documentation

◆ N

#define N   4

Definition at line 54 of file af_mcompand.c.

◆ OFFSET

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

Definition at line 94 of file af_mcompand.c.

◆ A

Definition at line 95 of file af_mcompand.c.

◆ S [1/2]

#define S (   x)    s->segments[2 * ((x) + 1)]

◆ S [2/2]

#define S (   x)    s->segments[2 * (x)]

◆ L

#define L (   x)    s->segments[i - (x)]

◆ CONVOLVE

#define CONVOLVE   _ _ _ _

Definition at line 507 of file af_mcompand.c.

◆ _ [1/2]

#define _
Value:
out_low += p->coefs[j] * p->previous[ch][p->pos + j].in \
- p->coefs[2*N+2 + j] * p->previous[ch][p->pos + j].out_low, j++;

◆ _ [2/2]

#define _
Value:
out_high += p->coefs[j+N+1] * p->previous[ch][p->pos + j].in \
- p->coefs[2*N+2 + j] * p->previous[ch][p->pos + j].out_high, j++;

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( mcompand  )

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 104 of file af_mcompand.c.

Referenced by config_output().

◆ query_formats()

static int query_formats ( AVFilterContext ctx)
static

Definition at line 126 of file af_mcompand.c.

◆ count_items()

static void count_items ( char *  item_str,
int nb_items,
char  delimiter 
)
static

Definition at line 156 of file af_mcompand.c.

Referenced by config_output().

◆ update_volume()

static void update_volume ( CompBand cb,
double  in,
int  ch 
)
static

Definition at line 167 of file af_mcompand.c.

Referenced by mcompand_channel().

◆ get_volume()

static double get_volume ( CompandT s,
double  in_lin 
)
static

Definition at line 177 of file af_mcompand.c.

Referenced by mcompand_channel().

◆ parse_points()

static int parse_points ( char *  points,
int  nb_points,
double  radius,
CompandT s,
AVFilterContext ctx 
)
static

Definition at line 198 of file af_mcompand.c.

Referenced by config_output().

◆ square_quadratic()

static void square_quadratic ( double const *  x,
double *  y 
)
static

Definition at line 300 of file af_mcompand.c.

Referenced by crossover_setup().

◆ crossover_setup()

static int crossover_setup ( AVFilterLink outlink,
Crossover p,
double  frequency 
)
static

Definition at line 309 of file af_mcompand.c.

Referenced by config_output().

◆ config_output()

static int config_output ( AVFilterLink outlink)
static

Definition at line 343 of file af_mcompand.c.

◆ crossover()

static void crossover ( int  ch,
Crossover p,
double *  ibuf,
double *  obuf_low,
double *  obuf_high,
size_t  len 
)
static

Definition at line 509 of file af_mcompand.c.

Referenced by filter_frame().

◆ mcompand_channel()

static int mcompand_channel ( MCompandContext c,
CompBand l,
double *  ibuf,
double *  obuf,
int  len,
int  ch 
)
static

Definition at line 540 of file af_mcompand.c.

Referenced by filter_frame().

◆ filter_frame()

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 593 of file af_mcompand.c.

◆ request_frame()

static int request_frame ( AVFilterLink outlink)
static

Definition at line 649 of file af_mcompand.c.

Variable Documentation

◆ mcompand_options

const AVOption mcompand_options[]
static
Initial value:
= {
{ "args", "set parameters for each band", OFFSET(args), AV_OPT_TYPE_STRING, { .str = "0.005,0.1 6 -47/-40,-34/-34,-17/-33 100 | 0.003,0.05 6 -47/-40,-34/-34,-17/-33 400 | 0.000625,0.0125 6 -47/-40,-34/-34,-15/-33 1600 | 0.0001,0.025 6 -47/-40,-34/-34,-31/-31,-0/-30 6400 | 0,0.025 6 -38/-31,-28/-28,-0/-25 22000" }, 0, 0, A },
{ NULL }
}

Definition at line 97 of file af_mcompand.c.

◆ mcompand_inputs

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

Definition at line 659 of file af_mcompand.c.

◆ mcompand_outputs

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

Definition at line 668 of file af_mcompand.c.

◆ ff_af_mcompand

AVFilter ff_af_mcompand
Initial value:
= {
.name = "mcompand",
.description = NULL_IF_CONFIG_SMALL(
"Multiband Compress or expand audio dynamic range."),
.query_formats = query_formats,
.priv_size = sizeof(MCompandContext),
.priv_class = &mcompand_class,
}

Definition at line 679 of file af_mcompand.c.

request_frame
static int request_frame(AVFilterLink *outlink)
Definition: af_mcompand.c:649
mcompand_outputs
static const AVFilterPad mcompand_outputs[]
Definition: af_mcompand.c:668
ch
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_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NC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
OFFSET
#define OFFSET(x)
Definition: af_mcompand.c:94
mcompand_inputs
static const AVFilterPad mcompand_inputs[]
Definition: af_mcompand.c:659
config_output
static int config_output(AVFilterLink *outlink)
Definition: af_mcompand.c:343
MCompandContext
Definition: af_mcompand.c:82
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
NULL
#define NULL
Definition: coverity.c:32
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_mcompand.c:126
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
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
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_mcompand.c:593
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_mcompand.c:104
N
#define N
Definition: af_mcompand.c:54
args
const char AVS_Value args
Definition: avisynth_c.h:873
A
#define A
Definition: af_mcompand.c:95
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:227