FFmpeg
Data Structures | Macros | Functions | Variables
ebur128.c File Reference
#include "ebur128.h"
#include <float.h>
#include <limits.h>
#include <math.h>
#include "libavutil/common.h"
#include "libavutil/mem.h"
#include "libavutil/thread.h"

Go to the source code of this file.

Data Structures

struct  FFEBUR128StateInternal
 

Macros

#define CHECK_ERROR(condition, errorcode, goto_point)
 
#define ALMOST_ZERO   0.000001
 
#define RELATIVE_GATE   (-10.0)
 
#define RELATIVE_GATE_FACTOR   pow(10.0, RELATIVE_GATE / 10.0)
 
#define MINUS_20DB   pow(10.0, -20.0 / 10.0)
 
#define EBUR128_FILTER(type, scaling_factor)
 
#define FF_EBUR128_ADD_FRAMES_PLANAR(type)
 
#define FF_EBUR128_ADD_FRAMES(type)
 

Functions

static void ebur128_init_filter (FFEBUR128State *st)
 
static int ebur128_init_channel_map (FFEBUR128State *st)
 
static void init_histogram (void)
 
FFEBUR128Stateff_ebur128_init (unsigned int channels, unsigned long samplerate, unsigned long window, int mode)
 Initialize library state. More...
 
void ff_ebur128_destroy (FFEBUR128State **st)
 Destroy library state. More...
 
 EBUR128_FILTER (short, -(double) SHRT_MIN)
 
static size_t find_histogram_index (double energy)
 
static void ebur128_calc_gating_block (FFEBUR128State *st, size_t frames_per_block, double *optional_output)
 
int ff_ebur128_set_channel (FFEBUR128State *st, unsigned int channel_number, int value)
 Set channel type. More...
 
static int ebur128_energy_shortterm (FFEBUR128State *st, double *out)
 
static int ebur128_calc_relative_threshold (FFEBUR128State **sts, size_t size, double *relative_threshold)
 
static int ebur128_gated_loudness (FFEBUR128State **sts, size_t size, double *out)
 
int ff_ebur128_relative_threshold (FFEBUR128State *st, double *out)
 Get relative threshold in LUFS. More...
 
int ff_ebur128_loudness_global (FFEBUR128State *st, double *out)
 Get global integrated loudness in LUFS. More...
 
int ff_ebur128_loudness_global_multiple (FFEBUR128State **sts, size_t size, double *out)
 Get global integrated loudness in LUFS across multiple instances. More...
 
static int ebur128_energy_in_interval (FFEBUR128State *st, size_t interval_frames, double *out)
 
int ff_ebur128_loudness_momentary (FFEBUR128State *st, double *out)
 Get momentary loudness (last 400ms) in LUFS. More...
 
int ff_ebur128_loudness_shortterm (FFEBUR128State *st, double *out)
 Get short-term loudness (last 3s) in LUFS. More...
 
int ff_ebur128_loudness_window (FFEBUR128State *st, unsigned long window, double *out)
 Get loudness of the specified window in LUFS. More...
 
int ff_ebur128_loudness_range_multiple (FFEBUR128State **sts, size_t size, double *out)
 Get loudness range (LRA) in LU across multiple instances. More...
 
int ff_ebur128_loudness_range (FFEBUR128State *st, double *out)
 Get loudness range (LRA) of programme in LU. More...
 
int ff_ebur128_sample_peak (FFEBUR128State *st, unsigned int channel_number, double *out)
 Get maximum sample peak of selected channel in float format. More...
 

Variables

static AVOnce histogram_init = AV_ONCE_INIT
 
static double histogram_energies [1000]
 
static double histogram_energy_boundaries [1001]
 

Macro Definition Documentation

◆ CHECK_ERROR

#define CHECK_ERROR (   condition,
  errorcode,
  goto_point 
)
Value:
if ((condition)) { \
errcode = (errorcode); \
goto goto_point; \
}

Definition at line 54 of file ebur128.c.

◆ ALMOST_ZERO

#define ALMOST_ZERO   0.000001

Definition at line 60 of file ebur128.c.

◆ RELATIVE_GATE

#define RELATIVE_GATE   (-10.0)

Definition at line 62 of file ebur128.c.

◆ RELATIVE_GATE_FACTOR

#define RELATIVE_GATE_FACTOR   pow(10.0, RELATIVE_GATE / 10.0)

Definition at line 63 of file ebur128.c.

◆ MINUS_20DB

#define MINUS_20DB   pow(10.0, -20.0 / 10.0)

Definition at line 64 of file ebur128.c.

◆ EBUR128_FILTER

#define EBUR128_FILTER (   type,
  scaling_factor 
)

Definition at line 315 of file ebur128.c.

◆ FF_EBUR128_ADD_FRAMES_PLANAR

#define FF_EBUR128_ADD_FRAMES_PLANAR (   type)

Definition at line 461 of file ebur128.c.

◆ FF_EBUR128_ADD_FRAMES

#define FF_EBUR128_ADD_FRAMES (   type)
Value:
void ff_ebur128_add_frames_##type(FFEBUR128State* st, const type* src, \
size_t frames) { \
int i; \
const type **buf = (const type**)st->d->data_ptrs; \
for (i = 0; i < st->channels; i++) \
buf[i] = src + i; \
ff_ebur128_add_frames_planar_##type(st, buf, frames, st->channels); \
}

Definition at line 508 of file ebur128.c.

Function Documentation

◆ ebur128_init_filter()

static void ebur128_init_filter ( FFEBUR128State st)
static

Definition at line 104 of file ebur128.c.

Referenced by ff_ebur128_init().

◆ ebur128_init_channel_map()

static int ebur128_init_channel_map ( FFEBUR128State st)
static

Definition at line 154 of file ebur128.c.

Referenced by ff_ebur128_init().

◆ init_histogram()

static void init_histogram ( void  )
inlinestatic

Definition at line 202 of file ebur128.c.

Referenced by ff_ebur128_init().

◆ ff_ebur128_init()

FFEBUR128State* ff_ebur128_init ( unsigned int  channels,
unsigned long  samplerate,
unsigned long  window,
int  mode 
)

Initialize library state.

Parameters
channelsthe number of channels.
sampleratethe sample rate.
windowset the maximum window size in ms, set to 0 for auto.
modesee the mode enum for possible values.
Returns
an initialized library state.

Definition at line 217 of file ebur128.c.

Referenced by config_input().

◆ ff_ebur128_destroy()

void ff_ebur128_destroy ( FFEBUR128State **  st)

Destroy library state.

Parameters
stpointer to a library state.

Definition at line 302 of file ebur128.c.

Referenced by uninit().

◆ EBUR128_FILTER()

EBUR128_FILTER ( short  ,
(double) SHRT_MIN 
)

Definition at line 364 of file ebur128.c.

◆ find_histogram_index()

static size_t find_histogram_index ( double  energy)
static

◆ ebur128_calc_gating_block()

static void ebur128_calc_gating_block ( FFEBUR128State st,
size_t  frames_per_block,
double *  optional_output 
)
static

Definition at line 392 of file ebur128.c.

Referenced by ebur128_energy_in_interval().

◆ ff_ebur128_set_channel()

int ff_ebur128_set_channel ( FFEBUR128State st,
unsigned int  channel_number,
int  value 
)

Set channel type.

The default is:

  • 0 -> FF_EBUR128_LEFT
  • 1 -> FF_EBUR128_RIGHT
  • 2 -> FF_EBUR128_CENTER
  • 3 -> FF_EBUR128_UNUSED
  • 4 -> FF_EBUR128_LEFT_SURROUND
  • 5 -> FF_EBUR128_RIGHT_SURROUND
Parameters
stlibrary state.
channel_numberzero based channel index.
valuechannel type from the "channel" enum.
Returns

Definition at line 446 of file ebur128.c.

Referenced by config_input().

◆ ebur128_energy_shortterm()

static int ebur128_energy_shortterm ( FFEBUR128State st,
double *  out 
)
static

Definition at line 624 of file ebur128.c.

Referenced by ff_ebur128_loudness_shortterm().

◆ ebur128_calc_relative_threshold()

static int ebur128_calc_relative_threshold ( FFEBUR128State **  sts,
size_t  size,
double *  relative_threshold 
)
static

Definition at line 522 of file ebur128.c.

Referenced by ebur128_gated_loudness(), and ff_ebur128_relative_threshold().

◆ ebur128_gated_loudness()

static int ebur128_gated_loudness ( FFEBUR128State **  sts,
size_t  size,
double *  out 
)
static

Definition at line 545 of file ebur128.c.

Referenced by ff_ebur128_loudness_global(), and ff_ebur128_loudness_global_multiple().

◆ ff_ebur128_relative_threshold()

int ff_ebur128_relative_threshold ( FFEBUR128State st,
double *  out 
)

Get relative threshold in LUFS.

Parameters
stlibrary state
outrelative threshold in LUFS.
Returns
  • 0 on success.
  • AVERROR(EINVAL) if mode "FF_EBUR128_MODE_I" has not been set.

Definition at line 587 of file ebur128.c.

Referenced by filter_frame(), and uninit().

◆ ff_ebur128_loudness_global()

int ff_ebur128_loudness_global ( FFEBUR128State st,
double *  out 
)

Get global integrated loudness in LUFS.

Parameters
stlibrary state.
outintegrated loudness in LUFS. -HUGE_VAL if result is negative infinity.
Returns
  • 0 on success.
  • AVERROR(EINVAL) if mode "FF_EBUR128_MODE_I" has not been set.

Definition at line 603 of file ebur128.c.

Referenced by filter_frame(), and uninit().

◆ ff_ebur128_loudness_global_multiple()

int ff_ebur128_loudness_global_multiple ( FFEBUR128State **  sts,
size_t  size,
double *  out 
)

Get global integrated loudness in LUFS across multiple instances.

Parameters
stsarray of library states.
sizelength of sts
outintegrated loudness in LUFS. -HUGE_VAL if result is negative infinity.
Returns
  • 0 on success.
  • AVERROR(EINVAL) if mode "FF_EBUR128_MODE_I" has not been set.

Definition at line 608 of file ebur128.c.

◆ ebur128_energy_in_interval()

static int ebur128_energy_in_interval ( FFEBUR128State st,
size_t  interval_frames,
double *  out 
)
static

◆ ff_ebur128_loudness_momentary()

int ff_ebur128_loudness_momentary ( FFEBUR128State st,
double *  out 
)

Get momentary loudness (last 400ms) in LUFS.

Parameters
stlibrary state.
outmomentary loudness in LUFS. -HUGE_VAL if result is negative infinity.
Returns
  • 0 on success.

Definition at line 630 of file ebur128.c.

◆ ff_ebur128_loudness_shortterm()

int ff_ebur128_loudness_shortterm ( FFEBUR128State st,
double *  out 
)

Get short-term loudness (last 3s) in LUFS.

Parameters
stlibrary state.
outshort-term loudness in LUFS. -HUGE_VAL if result is negative infinity.
Returns
  • 0 on success.
  • AVERROR(EINVAL) if mode "FF_EBUR128_MODE_S" has not been set.

Definition at line 645 of file ebur128.c.

Referenced by filter_frame().

◆ ff_ebur128_loudness_window()

int ff_ebur128_loudness_window ( FFEBUR128State st,
unsigned long  window,
double *  out 
)

Get loudness of the specified window in LUFS.

window must not be larger than the current window set in st.

Parameters
stlibrary state.
windowwindow in ms to calculate loudness.
outloudness in LUFS. -HUGE_VAL if result is negative infinity.
Returns
  • 0 on success.
  • AVERROR(EINVAL) if window larger than current window in st.

Definition at line 659 of file ebur128.c.

◆ ff_ebur128_loudness_range_multiple()

int ff_ebur128_loudness_range_multiple ( FFEBUR128State **  sts,
size_t  size,
double *  out 
)

Get loudness range (LRA) in LU across multiple instances.

Calculates loudness range according to EBU 3342.

Parameters
stsarray of library states.
sizelength of sts
outloudness range (LRA) in LU. Will not be changed in case of error. AVERROR(EINVAL) will be returned in this case.
Returns
  • 0 on success.
  • AVERROR(EINVAL) if mode "FF_EBUR128_MODE_LRA" has not been set.

Definition at line 676 of file ebur128.c.

Referenced by ff_ebur128_loudness_range().

◆ ff_ebur128_loudness_range()

int ff_ebur128_loudness_range ( FFEBUR128State st,
double *  out 
)

Get loudness range (LRA) of programme in LU.

Calculates loudness range according to EBU 3342.

Parameters
stlibrary state.
outloudness range (LRA) in LU. Will not be changed in case of error. AVERROR(EINVAL) will be returned in this case.
Returns
  • 0 on success.
  • AVERROR(EINVAL) if mode "FF_EBUR128_MODE_LRA" has not been set.

Definition at line 753 of file ebur128.c.

Referenced by filter_frame(), and uninit().

◆ ff_ebur128_sample_peak()

int ff_ebur128_sample_peak ( FFEBUR128State st,
unsigned int  channel_number,
double *  out 
)

Get maximum sample peak of selected channel in float format.

Parameters
stlibrary state
channel_numberchannel to analyse
outmaximum sample peak in float format (1.0 is 0 dBFS)
Returns

Definition at line 758 of file ebur128.c.

Referenced by filter_frame(), and uninit().

Variable Documentation

◆ histogram_init

AVOnce histogram_init = AV_ONCE_INIT
static

Definition at line 100 of file ebur128.c.

Referenced by ff_ebur128_init().

◆ histogram_energies

double histogram_energies[1000]
static

◆ histogram_energy_boundaries

double histogram_energy_boundaries[1001]
static
FFEBUR128State::d
struct FFEBUR128StateInternal * d
Internal state.
Definition: ebur128.h:107
frames
if it could not because there are no more frames
Definition: filter_design.txt:266
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
src
#define src
Definition: vp8dsp.c:254
buf
void * buf
Definition: avisynth_c.h:766
FFEBUR128StateInternal::data_ptrs
void ** data_ptrs
Data pointer array for interleaved data.
Definition: ebur128.c:97
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
FFEBUR128State::channels
unsigned int channels
The number of channels.
Definition: ebur128.h:105
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
FFEBUR128State
Contains information about the state of a loudness measurement.
Definition: ebur128.h:103