FFmpeg
Functions | Variables
ac3.c File Reference
#include "libavutil/error.h"
#include "libavutil/macros.h"
#include "ac3.h"
#include "ac3defs.h"

Go to the source code of this file.

Functions

static int calc_lowcomp1 (int a, int b0, int b1, int c)
 
static int calc_lowcomp (int a, int b0, int b1, int bin)
 
void ff_ac3_bit_alloc_calc_psd (int8_t *exp, int start, int end, int16_t *psd, int16_t *band_psd)
 Calculate the log power-spectral density of the input signal. More...
 
int ff_ac3_bit_alloc_calc_mask (AC3BitAllocParameters *s, int16_t *band_psd, int start, int end, int fast_gain, int is_lfe, int dba_mode, int dba_nsegs, uint8_t *dba_offsets, uint8_t *dba_lengths, uint8_t *dba_values, int16_t *mask)
 Calculate the masking curve. More...
 

Variables

const uint8_t ff_ac3_band_start_tab [AC3_CRITICAL_BANDS+1]
 Starting frequency coefficient bin for each critical band. More...
 
const uint8_t ff_ac3_bin_to_band_tab [253]
 Map each frequency coefficient bin to the critical band that contains it. More...
 
static const uint8_t ac3_log_add_tab [260]
 
static const uint16_t ac3_hearing_threshold_tab [AC3_CRITICAL_BANDS][3]
 

Detailed Description

Common code between the AC-3 encoder and decoder.

Definition in file ac3.c.

Function Documentation

◆ calc_lowcomp1()

static int calc_lowcomp1 ( int  a,
int  b0,
int  b1,
int  c 
)
inlinestatic

Definition at line 154 of file ac3.c.

Referenced by calc_lowcomp(), and ff_ac3_bit_alloc_calc_mask().

◆ calc_lowcomp()

static int calc_lowcomp ( int  a,
int  b0,
int  b1,
int  bin 
)
inlinestatic

Definition at line 164 of file ac3.c.

Referenced by ff_ac3_bit_alloc_calc_mask().

◆ ff_ac3_bit_alloc_calc_psd()

void ff_ac3_bit_alloc_calc_psd ( int8_t *  exp,
int  start,
int  end,
int16_t *  psd,
int16_t *  band_psd 
)

Calculate the log power-spectral density of the input signal.

This gives a rough estimate of signal power in the frequency domain by using the spectral envelope (exponents). The psd is also separately grouped into critical bands for use in the calculating the masking curve. 128 units in psd = -6 dB. The dbknee parameter in AC3BitAllocParameters determines the reference level.

Parameters
[in]expfrequency coefficient exponents
[in]startstarting bin location
[in]endending bin location
[out]psdsignal power for each frequency bin
[out]band_psdsignal power for each critical band

Definition at line 175 of file ac3.c.

Referenced by bit_alloc_masking(), and decode_audio_block().

◆ ff_ac3_bit_alloc_calc_mask()

int ff_ac3_bit_alloc_calc_mask ( AC3BitAllocParameters s,
int16_t *  band_psd,
int  start,
int  end,
int  fast_gain,
int  is_lfe,
int  dba_mode,
int  dba_nsegs,
uint8_t *  dba_offsets,
uint8_t *  dba_lengths,
uint8_t *  dba_values,
int16_t *  mask 
)

Calculate the masking curve.

First, the excitation is calculated using parameters in s and the signal power in each critical band. The excitation is compared with a predefined hearing threshold table to produce the masking curve. If delta bit allocation information is provided, it is used for adjusting the masking curve, usually to give a closer match to a better psychoacoustic model.

Parameters
[in]sadjustable bit allocation parameters
[in]band_psdsignal power for each critical band
[in]startstarting bin location
[in]endending bin location
[in]fast_gainfast gain (estimated signal-to-mask ratio)
[in]is_lfewhether or not the channel being processed is the LFE
[in]dba_modedelta bit allocation mode (none, reuse, or new)
[in]dba_nsegsnumber of delta segments
[in]dba_offsetslocation offsets for each segment
[in]dba_lengthslength of each segment
[in]dba_valuesdelta bit allocation for each segment
[out]maskcalculated masking curve
Returns
returns 0 for success, non-zero for error

Definition at line 201 of file ac3.c.

Referenced by bit_alloc_masking(), and decode_audio_block().

Variable Documentation

◆ ff_ac3_band_start_tab

const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1]
Initial value:
= {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 31,
34, 37, 40, 43, 46, 49, 55, 61, 67, 73,
79, 85, 97, 109, 121, 133, 157, 181, 205, 229, 253
}

Starting frequency coefficient bin for each critical band.

Definition at line 36 of file ac3.c.

Referenced by ac3_bit_alloc_calc_bap_c(), and ff_ac3_bit_alloc_calc_psd().

◆ ff_ac3_bin_to_band_tab

const uint8_t ff_ac3_bin_to_band_tab[253]
Initial value:
= {
0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 28, 28, 29, 29, 29, 30, 30, 30,
31, 31, 31, 32, 32, 32, 33, 33, 33, 34, 34, 34,
35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36,
37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38,
39, 39, 39, 39, 39, 39, 40, 40, 40, 40, 40, 40,
41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42,
43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46,
47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49,
49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49
}

Map each frequency coefficient bin to the critical band that contains it.

Definition at line 47 of file ac3.c.

Referenced by ac3_bit_alloc_calc_bap_c(), ff_ac3_bit_alloc_calc_mask(), and ff_ac3_bit_alloc_calc_psd().

◆ ac3_log_add_tab

const uint8_t ac3_log_add_tab[260]
static
Initial value:
= {
0x40,0x3f,0x3e,0x3d,0x3c,0x3b,0x3a,0x39,0x38,0x37,
0x36,0x35,0x34,0x34,0x33,0x32,0x31,0x30,0x2f,0x2f,
0x2e,0x2d,0x2c,0x2c,0x2b,0x2a,0x29,0x29,0x28,0x27,
0x26,0x26,0x25,0x24,0x24,0x23,0x23,0x22,0x21,0x21,
0x20,0x20,0x1f,0x1e,0x1e,0x1d,0x1d,0x1c,0x1c,0x1b,
0x1b,0x1a,0x1a,0x19,0x19,0x18,0x18,0x17,0x17,0x16,
0x16,0x15,0x15,0x15,0x14,0x14,0x13,0x13,0x13,0x12,
0x12,0x12,0x11,0x11,0x11,0x10,0x10,0x10,0x0f,0x0f,
0x0f,0x0e,0x0e,0x0e,0x0d,0x0d,0x0d,0x0d,0x0c,0x0c,
0x0c,0x0c,0x0b,0x0b,0x0b,0x0b,0x0a,0x0a,0x0a,0x0a,
0x0a,0x09,0x09,0x09,0x09,0x09,0x08,0x08,0x08,0x08,
0x08,0x08,0x07,0x07,0x07,0x07,0x07,0x07,0x06,0x06,
0x06,0x06,0x06,0x06,0x06,0x06,0x05,0x05,0x05,0x05,
0x05,0x05,0x05,0x05,0x04,0x04,0x04,0x04,0x04,0x04,
0x04,0x04,0x04,0x04,0x04,0x03,0x03,0x03,0x03,0x03,
0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x02,
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
}

Definition at line 72 of file ac3.c.

Referenced by ff_ac3_bit_alloc_calc_psd().

◆ ac3_hearing_threshold_tab

const uint16_t ac3_hearing_threshold_tab[AC3_CRITICAL_BANDS][3]
static

Definition at line 101 of file ac3.c.

Referenced by ff_ac3_bit_alloc_calc_mask().