FFmpeg  4.0
Data Structures | Functions | Variables
ac3dec.c File Reference
#include <stdio.h>
#include <stddef.h>
#include <math.h>
#include <string.h>
#include "libavutil/channel_layout.h"
#include "libavutil/crc.h"
#include "libavutil/downmix_info.h"
#include "libavutil/opt.h"
#include "bswapdsp.h"
#include "internal.h"
#include "aac_ac3_parser.h"
#include "ac3_parser_internal.h"
#include "ac3dec.h"
#include "ac3dec_data.h"
#include "kbdwin.h"

Go to the source code of this file.

Data Structures

struct  mant_groups
 Grouped mantissas for 3-level 5-level and 11-level quantization. More...
 

Functions

static int symmetric_dequant (int code, int levels)
 Symmetrical Dequantization reference: Section 7.3.3 Expansion of Mantissas for Symmetrical Quantization Tables 7.19 to 7.23. More...
 
static av_cold void ac3_tables_init (void)
 
static av_cold int ac3_decode_init (AVCodecContext *avctx)
 AVCodec initialization. More...
 
static int ac3_parse_header (AC3DecodeContext *s)
 Parse the 'sync info' and 'bit stream info' from the AC-3 bitstream. More...
 
static int parse_frame_header (AC3DecodeContext *s)
 Common function to parse AC-3 or E-AC-3 frame header. More...
 
static int set_downmix_coeffs (AC3DecodeContext *s)
 Set stereo downmixing coefficients based on frame header info. More...
 
static int decode_exponents (AC3DecodeContext *s, GetBitContext *gbc, int exp_strategy, int ngrps, uint8_t absexp, int8_t *dexps)
 Decode the grouped exponents according to exponent strategy. More...
 
static void calc_transform_coeffs_cpl (AC3DecodeContext *s)
 Generate transform coefficients for each coupled channel in the coupling range using the coupling coefficients and coupling coordinates. More...
 
static void ac3_decode_transform_coeffs_ch (AC3DecodeContext *s, int ch_index, mant_groups *m)
 Decode the transform coefficients for a particular channel reference: Section 7.3 Quantization and Decoding of Mantissas. More...
 
static void remove_dithering (AC3DecodeContext *s)
 Remove random dithering from coupling range coefficients with zero-bit mantissas for coupled channels which do not use dithering. More...
 
static void decode_transform_coeffs_ch (AC3DecodeContext *s, int blk, int ch, mant_groups *m)
 
static void decode_transform_coeffs (AC3DecodeContext *s, int blk)
 Decode the transform coefficients. More...
 
static void do_rematrixing (AC3DecodeContext *s)
 Stereo rematrixing. More...
 
static void do_imdct (AC3DecodeContext *s, int channels, int offset)
 Inverse MDCT Transform. More...
 
static void ac3_upmix_delay (AC3DecodeContext *s)
 Upmix delay samples from stereo to original channel layout. More...
 
static void decode_band_structure (GetBitContext *gbc, int blk, int eac3, int ecpl, int start_subband, int end_subband, const uint8_t *default_band_struct, int *num_bands, uint8_t *band_sizes, uint8_t *band_struct, int band_struct_size)
 Decode band structure for coupling, spectral extension, or enhanced coupling. More...
 
static int spx_strategy (AC3DecodeContext *s, int blk)
 
static void spx_coordinates (AC3DecodeContext *s)
 
static int coupling_strategy (AC3DecodeContext *s, int blk, uint8_t *bit_alloc_stages)
 
static int coupling_coordinates (AC3DecodeContext *s, int blk)
 
static int decode_audio_block (AC3DecodeContext *s, int blk, int offset)
 Decode a single audio block from the AC-3 bitstream. More...
 
static int ac3_decode_frame (AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
 Decode a single AC-3 frame. More...
 
static av_cold int ac3_decode_end (AVCodecContext *avctx)
 Uninitialize the AC-3 decoder. More...
 

Variables

static uint8_t ungroup_3_in_7_bits_tab [128][3]
 table for ungrouping 3 values in 7 bits. More...
 
static int b1_mantissas [32][3]
 tables for ungrouping mantissas More...
 
static int b2_mantissas [128][3]
 
static int b3_mantissas [8]
 
static int b4_mantissas [128][2]
 
static int b5_mantissas [16]
 
static const uint8_t quantization_tab [16]
 Quantization table: levels for symmetric. More...
 
static float dynamic_range_tab [256]
 dynamic range table. More...
 
float ff_ac3_heavy_dynamic_range_tab [256]
 
static const float gain_levels [9]
 Adjustments in dB gain. More...
 
static const float gain_levels_lfe [32]
 Adjustments in dB gain (LFE, +10 to -21 dB) More...
 
static const uint8_t ac3_default_coeffs [8][5][2]
 Table for default stereo downmixing coefficients reference: Section 7.8.2 Downmixing Into Two Channels. More...
 
static const uint64_t custom_channel_map_locations [16][2]
 

Function Documentation

◆ symmetric_dequant()

static int symmetric_dequant ( int  code,
int  levels 
)
inlinestatic

Symmetrical Dequantization reference: Section 7.3.3 Expansion of Mantissas for Symmetrical Quantization Tables 7.19 to 7.23.

Definition at line 134 of file ac3dec.c.

Referenced by ac3_tables_init().

◆ ac3_tables_init()

static av_cold void ac3_tables_init ( void  )
static

Definition at line 142 of file ac3dec.c.

Referenced by ac3_decode_init().

◆ ac3_decode_init()

static av_cold int ac3_decode_init ( AVCodecContext avctx)
static

AVCodec initialization.

Definition at line 203 of file ac3dec.c.

◆ ac3_parse_header()

static int ac3_parse_header ( AC3DecodeContext *  s)
static

Parse the 'sync info' and 'bit stream info' from the AC-3 bitstream.

GetBitContext within AC3DecodeContext must point to the start of the synchronized AC-3 bitstream.

Definition at line 253 of file ac3dec.c.

Referenced by parse_frame_header().

◆ parse_frame_header()

static int parse_frame_header ( AC3DecodeContext *  s)
static

Common function to parse AC-3 or E-AC-3 frame header.

Definition at line 317 of file ac3dec.c.

Referenced by ac3_decode_frame().

◆ set_downmix_coeffs()

static int set_downmix_coeffs ( AC3DecodeContext *  s)
static

Set stereo downmixing coefficients based on frame header info.

reference: Section 7.8.2 Downmixing Into Two Channels

Definition at line 385 of file ac3dec.c.

Referenced by ac3_decode_frame().

◆ decode_exponents()

static int decode_exponents ( AC3DecodeContext *  s,
GetBitContext gbc,
int  exp_strategy,
int  ngrps,
uint8_t  absexp,
int8_t *  dexps 
)
static

Decode the grouped exponents according to exponent strategy.

reference: Section 7.1.3 Exponent Decoding

Definition at line 447 of file ac3dec.c.

Referenced by decode_audio_block().

◆ calc_transform_coeffs_cpl()

static void calc_transform_coeffs_cpl ( AC3DecodeContext *  s)
static

Generate transform coefficients for each coupled channel in the coupling range using the coupling coefficients and coupling coordinates.

reference: Section 7.4.3 Coupling Coordinate Format

Definition at line 491 of file ac3dec.c.

Referenced by decode_transform_coeffs().

◆ ac3_decode_transform_coeffs_ch()

static void ac3_decode_transform_coeffs_ch ( AC3DecodeContext *  s,
int  ch_index,
mant_groups m 
)
static

Decode the transform coefficients for a particular channel reference: Section 7.3 Quantization and Decoding of Mantissas.

Definition at line 532 of file ac3dec.c.

Referenced by decode_transform_coeffs_ch().

◆ remove_dithering()

static void remove_dithering ( AC3DecodeContext *  s)
static

Remove random dithering from coupling range coefficients with zero-bit mantissas for coupled channels which do not use dithering.

reference: Section 7.3.4 Dither for Zero Bit Mantissas (bap=0)

Definition at line 613 of file ac3dec.c.

Referenced by decode_transform_coeffs().

◆ decode_transform_coeffs_ch()

static void decode_transform_coeffs_ch ( AC3DecodeContext *  s,
int  blk,
int  ch,
mant_groups m 
)
inlinestatic

Definition at line 626 of file ac3dec.c.

Referenced by decode_transform_coeffs().

◆ decode_transform_coeffs()

static void decode_transform_coeffs ( AC3DecodeContext *  s,
int  blk 
)
inlinestatic

Decode the transform coefficients.

Definition at line 646 of file ac3dec.c.

Referenced by decode_audio_block().

◆ do_rematrixing()

static void do_rematrixing ( AC3DecodeContext *  s)
static

Stereo rematrixing.

reference: Section 7.5.4 Rematrixing : Decoding Technique

Definition at line 682 of file ac3dec.c.

Referenced by decode_audio_block().

◆ do_imdct()

static void do_imdct ( AC3DecodeContext *  s,
int  channels,
int  offset 
)
inlinestatic

Inverse MDCT Transform.

Convert frequency domain coefficients to time-domain audio samples. reference: Section 7.9.4 Transformation Equations

Definition at line 706 of file ac3dec.c.

Referenced by decode_audio_block().

◆ ac3_upmix_delay()

static void ac3_upmix_delay ( AC3DecodeContext *  s)
static

Upmix delay samples from stereo to original channel layout.

Definition at line 744 of file ac3dec.c.

Referenced by decode_audio_block().

◆ decode_band_structure()

static void decode_band_structure ( GetBitContext gbc,
int  blk,
int  eac3,
int  ecpl,
int  start_subband,
int  end_subband,
const uint8_t default_band_struct,
int num_bands,
uint8_t band_sizes,
uint8_t band_struct,
int  band_struct_size 
)
static

Decode band structure for coupling, spectral extension, or enhanced coupling.

The band structure defines how many subbands are in each band. For each subband in the range, 1 means it is combined with the previous band, and 0 means that it starts a new band.

Parameters
[in]gbcbit reader context
[in]blkblock number
[in]eac3flag to indicate E-AC-3
[in]ecplflag to indicate enhanced coupling
[in]start_subbandsubband number for start of range
[in]end_subbandsubband number for end of range
[in]default_band_structdefault band structure table
[out]num_bandsnumber of bands (optionally NULL)
[out]band_sizesarray containing the number of bins in each band (optionally NULL)
[in,out]band_structcurrent band structure

Definition at line 786 of file ac3dec.c.

Referenced by coupling_strategy(), and spx_strategy().

◆ spx_strategy()

static int spx_strategy ( AC3DecodeContext *  s,
int  blk 
)
inlinestatic

Definition at line 835 of file ac3dec.c.

Referenced by decode_audio_block().

◆ spx_coordinates()

static void spx_coordinates ( AC3DecodeContext *  s)
inlinestatic

Definition at line 892 of file ac3dec.c.

Referenced by decode_audio_block().

◆ coupling_strategy()

static int coupling_strategy ( AC3DecodeContext *  s,
int  blk,
uint8_t bit_alloc_stages 
)
inlinestatic

Definition at line 970 of file ac3dec.c.

Referenced by decode_audio_block().

◆ coupling_coordinates()

static int coupling_coordinates ( AC3DecodeContext *  s,
int  blk 
)
inlinestatic

Definition at line 1040 of file ac3dec.c.

Referenced by decode_audio_block().

◆ decode_audio_block()

static int decode_audio_block ( AC3DecodeContext *  s,
int  blk,
int  offset 
)
static

Decode a single audio block from the AC-3 bitstream.

Definition at line 1086 of file ac3dec.c.

Referenced by ac3_decode_frame().

◆ ac3_decode_frame()

static int ac3_decode_frame ( AVCodecContext avctx,
void data,
int got_frame_ptr,
AVPacket avpkt 
)
static

Decode a single AC-3 frame.

Definition at line 1481 of file ac3dec.c.

◆ ac3_decode_end()

static av_cold int ac3_decode_end ( AVCodecContext avctx)
static

Uninitialize the AC-3 decoder.

Definition at line 1809 of file ac3dec.c.

Variable Documentation

◆ ungroup_3_in_7_bits_tab

uint8_t ungroup_3_in_7_bits_tab[128][3]
static

table for ungrouping 3 values in 7 bits.

used for exponents and bap=2 mantissas

Definition at line 48 of file ac3dec.c.

Referenced by ac3_tables_init(), and decode_exponents().

◆ b1_mantissas

int b1_mantissas[32][3]
static

tables for ungrouping mantissas

Definition at line 51 of file ac3dec.c.

Referenced by ac3_decode_transform_coeffs_ch(), and ac3_tables_init().

◆ b2_mantissas

int b2_mantissas[128][3]
static

Definition at line 52 of file ac3dec.c.

Referenced by ac3_decode_transform_coeffs_ch(), and ac3_tables_init().

◆ b3_mantissas

int b3_mantissas[8]
static

Definition at line 53 of file ac3dec.c.

Referenced by ac3_decode_transform_coeffs_ch(), and ac3_tables_init().

◆ b4_mantissas

int b4_mantissas[128][2]
static

Definition at line 54 of file ac3dec.c.

Referenced by ac3_decode_transform_coeffs_ch(), and ac3_tables_init().

◆ b5_mantissas

int b5_mantissas[16]
static

Definition at line 55 of file ac3dec.c.

Referenced by ac3_decode_transform_coeffs_ch(), and ac3_tables_init().

◆ quantization_tab

const uint8_t quantization_tab[16]
static
Initial value:
= {
0, 3, 5, 7, 11, 15,
5, 6, 7, 8, 9, 10, 11, 12, 14, 16
}

Quantization table: levels for symmetric.

bits for asymmetric. reference: Table 7.18 Mapping of bap to Quantizer

Definition at line 61 of file ac3dec.c.

Referenced by ac3_decode_transform_coeffs_ch().

◆ dynamic_range_tab

float dynamic_range_tab[256]
static

dynamic range table.

converts codes to scale factors.

Definition at line 68 of file ac3dec.c.

Referenced by ac3_tables_init().

◆ ff_ac3_heavy_dynamic_range_tab

float ff_ac3_heavy_dynamic_range_tab[256]

Definition at line 69 of file ac3dec.c.

Referenced by ac3_tables_init().

◆ gain_levels

const float gain_levels[9]
static
Initial value:
= {
}
#define LEVEL_PLUS_1POINT5DB
Definition: ac3.h:105
#define LEVEL_MINUS_1POINT5DB
Definition: ac3.h:106
#define LEVEL_MINUS_9DB
Definition: ac3.h:110
#define LEVEL_MINUS_3DB
Definition: ac3.h:107
#define LEVEL_MINUS_4POINT5DB
Definition: ac3.h:108
#define LEVEL_ZERO
Definition: ac3.h:111
#define LEVEL_ONE
Definition: ac3.h:112
#define LEVEL_PLUS_3DB
Definition: ac3.h:104
#define LEVEL_MINUS_6DB
Definition: ac3.h:109

Adjustments in dB gain.

Definition at line 73 of file ac3dec.c.

Referenced by ac3_decode_frame(), and set_downmix_coeffs().

◆ gain_levels_lfe

const float gain_levels_lfe[32]
static
Initial value:
= {
3.162275, 2.818382, 2.511886, 2.238719, 1.995261, 1.778278, 1.584893,
1.412536, 1.258924, 1.122018, 1.000000, 0.891251, 0.794328, 0.707946,
0.630957, 0.562341, 0.501187, 0.446683, 0.398107, 0.354813, 0.316227,
0.281838, 0.251188, 0.223872, 0.199526, 0.177828, 0.158489, 0.141253,
0.125892, 0.112201, 0.100000, 0.089125
}

Adjustments in dB gain (LFE, +10 to -21 dB)

Definition at line 86 of file ac3dec.c.

Referenced by ac3_decode_frame().

◆ ac3_default_coeffs

const uint8_t ac3_default_coeffs[8][5][2]
static
Initial value:
= {
{ { 2, 7 }, { 7, 2 }, },
{ { 4, 4 }, },
{ { 2, 7 }, { 7, 2 }, },
{ { 2, 7 }, { 5, 5 }, { 7, 2 }, },
{ { 2, 7 }, { 7, 2 }, { 6, 6 }, },
{ { 2, 7 }, { 5, 5 }, { 7, 2 }, { 8, 8 }, },
{ { 2, 7 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, },
{ { 2, 7 }, { 5, 5 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, },
}

Table for default stereo downmixing coefficients reference: Section 7.8.2 Downmixing Into Two Channels.

Definition at line 98 of file ac3dec.c.

Referenced by set_downmix_coeffs().

◆ custom_channel_map_locations

const uint64_t custom_channel_map_locations[16][2]
static
Initial value:
= {
}
#define AV_CH_TOP_FRONT_RIGHT
#define AV_CH_TOP_FRONT_LEFT
#define AV_CH_TOP_FRONT_CENTER
#define AV_CH_LOW_FREQUENCY_2
#define AV_CH_SURROUND_DIRECT_RIGHT
#define AV_CH_WIDE_LEFT
#define AV_CH_TOP_BACK_LEFT
#define AV_CH_WIDE_RIGHT
#define AV_CH_LOW_FREQUENCY
#define AV_CH_BACK_LEFT
#define AV_CH_TOP_CENTER
#define AV_CH_FRONT_LEFT_OF_CENTER
#define AV_CH_FRONT_CENTER
#define AV_CH_FRONT_RIGHT_OF_CENTER
#define AV_CH_FRONT_LEFT
#define AV_CH_TOP_BACK_RIGHT
#define AV_CH_BACK_CENTER
#define AV_CH_SIDE_RIGHT
#define AV_CH_SURROUND_DIRECT_LEFT
#define AV_CH_FRONT_RIGHT
#define AV_CH_SIDE_LEFT
#define AV_CH_BACK_RIGHT

Definition at line 109 of file ac3dec.c.

Referenced by ac3_decode_frame().