FFmpeg
Data Structures | Macros | Functions | Variables
ebur128.c File Reference
#include "ebur128.h"
#include <float.h>
#include <limits.h>
#include <math.h>
#include "libavutil/error.h"
#include "libavutil/macros.h"
#include "libavutil/mem.h"
#include "libavutil/mem_internal.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 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...
 
static double ebur128_energy_to_loudness (double energy)
 
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...
 
static int ebur128_energy_in_interval (FFEBUR128State *st, size_t interval_frames, double *out)
 
int ff_ebur128_loudness_shortterm (FFEBUR128State *st, double *out)
 Get short-term loudness (last 3s) 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 56 of file ebur128.c.

◆ ALMOST_ZERO

#define ALMOST_ZERO   0.000001

Definition at line 62 of file ebur128.c.

◆ RELATIVE_GATE

#define RELATIVE_GATE   (-10.0)

Definition at line 64 of file ebur128.c.

◆ RELATIVE_GATE_FACTOR

#define RELATIVE_GATE_FACTOR   pow(10.0, RELATIVE_GATE / 10.0)

Definition at line 65 of file ebur128.c.

◆ MINUS_20DB

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

Definition at line 66 of file ebur128.c.

◆ EBUR128_FILTER

#define EBUR128_FILTER (   type,
  scaling_factor 
)

Definition at line 317 of file ebur128.c.

◆ EBUR128_ADD_FRAMES_PLANAR

#define EBUR128_ADD_FRAMES_PLANAR (   type)

Definition at line 460 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; \
ebur128_add_frames_planar_##type(st, buf, frames, st->channels); \
}

Definition at line 504 of file ebur128.c.

Function Documentation

◆ ebur128_init_filter()

static void ebur128_init_filter ( FFEBUR128State st)
static

Definition at line 106 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 156 of file ebur128.c.

Referenced by ff_ebur128_init().

◆ init_histogram()

static void init_histogram ( void  )
inlinestatic

Definition at line 204 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 219 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 304 of file ebur128.c.

Referenced by uninit().

◆ ebur128_energy_to_loudness()

static double ebur128_energy_to_loudness ( double  energy)
static

◆ 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 391 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 445 of file ebur128.c.

Referenced by config_input().

◆ ebur128_energy_shortterm()

static int ebur128_energy_shortterm ( FFEBUR128State st,
double out 
)
static

Definition at line 611 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 515 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 538 of file ebur128.c.

Referenced by ff_ebur128_loudness_global().

◆ 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 580 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 596 of file ebur128.c.

Referenced by filter_frame(), and uninit().

◆ ebur128_energy_in_interval()

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

Definition at line 601 of file ebur128.c.

Referenced by ebur128_energy_shortterm().

◆ 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 617 of file ebur128.c.

Referenced by filter_frame().

◆ 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 632 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 709 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 714 of file ebur128.c.

Referenced by filter_frame(), and uninit().

Variable Documentation

◆ histogram_init

AVOnce histogram_init = AV_ONCE_INIT
static

Definition at line 102 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
FFEBUR128StateInternal::data_ptrs
void ** data_ptrs
Data pointer array for interleaved data.
Definition: ebur128.c:99
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
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:269
FFEBUR128State
Contains information about the state of a loudness measurement.
Definition: ebur128.h:103
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418