FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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

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

Definition at line 54 of file ebur128.c.

Referenced by ff_ebur128_init().

#define ALMOST_ZERO   0.000001

Definition at line 60 of file ebur128.c.

#define RELATIVE_GATE   (-10.0)

Definition at line 62 of file ebur128.c.

#define RELATIVE_GATE_FACTOR   pow(10.0, RELATIVE_GATE / 10.0)

Definition at line 63 of file ebur128.c.

Referenced by ebur128_calc_relative_threshold().

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

Definition at line 64 of file ebur128.c.

Referenced by ff_ebur128_loudness_range_multiple().

#define EBUR128_FILTER (   type,
  scaling_factor 
)

Definition at line 315 of file ebur128.c.

#define FF_EBUR128_ADD_FRAMES_PLANAR (   type)

Definition at line 461 of file ebur128.c.

#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); \
}
#define src
Definition: vp8dsp.c:254
void ** data_ptrs
Data pointer array for interleaved data.
Definition: ebur128.c:97
struct FFEBUR128StateInternal * d
Internal state.
Definition: ebur128.h:107
Contains information about the state of a loudness measurement.
Definition: ebur128.h:103
int frames
Definition: movenc.c:65
void * buf
Definition: avisynth_c.h:690
GLint GLenum type
Definition: opengl_enc.c:105
unsigned int channels
The number of channels.
Definition: ebur128.h:105
int
for(j=16;j >0;--j)

Definition at line 508 of file ebur128.c.

Function Documentation

static void ebur128_init_filter ( FFEBUR128State st)
static

Definition at line 104 of file ebur128.c.

Referenced by ff_ebur128_init().

static int ebur128_init_channel_map ( FFEBUR128State st)
static

Definition at line 154 of file ebur128.c.

Referenced by ff_ebur128_init().

static void init_histogram ( void  )
inlinestatic

Definition at line 202 of file ebur128.c.

Referenced by 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().

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 ( short  ,
(double) SHRT_MIN 
)

Definition at line 364 of file ebur128.c.

static size_t find_histogram_index ( double  energy)
static
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().

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().

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

Definition at line 624 of file ebur128.c.

Referenced by ff_ebur128_loudness_shortterm().

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().

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().

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().

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().

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.

static int ebur128_energy_in_interval ( FFEBUR128State st,
size_t  interval_frames,
double *  out 
)
static
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.

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().

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.

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().

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().

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

AVOnce histogram_init = AV_ONCE_INIT
static

Definition at line 100 of file ebur128.c.

Referenced by ff_ebur128_init().

double histogram_energies[1000]
static
double histogram_energy_boundaries[1001]
static