#include <stdio.h>
#include <stddef.h>
#include <math.h>
#include <string.h>
#include "libavutil/crc.h"
#include "internal.h"
#include "aac_ac3_parser.h"
#include "ac3_parser.h"
#include "ac3dec.h"
#include "ac3dec_data.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... | |
Defines | |
#define | AC3_FRAME_BUFFER_SIZE 32768 |
Large enough for maximum possible frame size when the specification limit is ignored. | |
#define | LEVEL_PLUS_3DB 1.4142135623730950 |
Adjustments in dB gain. | |
#define | LEVEL_PLUS_1POINT5DB 1.1892071150027209 |
#define | LEVEL_MINUS_1POINT5DB 0.8408964152537145 |
#define | LEVEL_MINUS_3DB 0.7071067811865476 |
#define | LEVEL_MINUS_4POINT5DB 0.5946035575013605 |
#define | LEVEL_MINUS_6DB 0.5000000000000000 |
#define | LEVEL_MINUS_9DB 0.3535533905932738 |
#define | LEVEL_ZERO 0.0000000000000000 |
#define | LEVEL_ONE 1.0000000000000000 |
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. | |
static av_cold void | ac3_tables_init (void) |
static av_cold int | ac3_decode_init (AVCodecContext *avctx) |
AVCodec initialization. | |
static int | ac3_parse_header (AC3DecodeContext *s) |
Parse the 'sync info' and 'bit stream info' from the AC-3 bitstream. | |
static int | parse_frame_header (AC3DecodeContext *s) |
Common function to parse AC-3 or E-AC-3 frame header. | |
static void | set_downmix_coeffs (AC3DecodeContext *s) |
Set stereo downmixing coefficients based on frame header info. | |
static int | decode_exponents (GetBitContext *gbc, int exp_strategy, int ngrps, uint8_t absexp, int8_t *dexps) |
Decode the grouped exponents according to exponent strategy. | |
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. | |
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. | |
static void | remove_dithering (AC3DecodeContext *s) |
Remove random dithering from coefficients with zero-bit mantissas reference: Section 7.3.4 Dither for Zero Bit Mantissas (bap=0). | |
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. | |
static void | do_rematrixing (AC3DecodeContext *s) |
Stereo rematrixing. | |
static void | do_imdct (AC3DecodeContext *s, int channels) |
Inverse MDCT Transform. | |
void | ff_ac3_downmix_c (float(*samples)[256], float(*matrix)[2], int out_ch, int in_ch, int len) |
Downmix the output to mono or stereo. | |
static void | ac3_upmix_delay (AC3DecodeContext *s) |
Upmix delay samples from stereo to original channel layout. | |
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, uint8_t *band_struct, int *num_subbands, int *num_bands, uint8_t *band_sizes) |
Decode band structure for coupling, spectral extension, or enhanced coupling. | |
static int | decode_audio_block (AC3DecodeContext *s, int blk) |
Decode a single audio block from the AC-3 bitstream. | |
static int | ac3_decode_frame (AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) |
Decode a single AC-3 frame. | |
static av_cold int | ac3_decode_end (AVCodecContext *avctx) |
Uninitialize the AC-3 decoder. | |
Variables | |
static uint8_t | ungroup_3_in_7_bits_tab [128][3] |
table for ungrouping 3 values in 7 bits. | |
static int | b1_mantissas [32][3] |
tables for ungrouping mantissas | |
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. | |
static float | dynamic_range_tab [256] |
dynamic range table. | |
static const float | gain_levels [9] |
static const uint8_t | center_levels [4] = { 4, 5, 6, 5 } |
Table for center mix levels reference: Section 5.4.2.4 cmixlev. | |
static const uint8_t | surround_levels [4] = { 4, 6, 7, 6 } |
Table for surround mix levels reference: Section 5.4.2.5 surmixlev. | |
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. | |
AVCodec | ac3_decoder |
AVCodec | eac3_decoder |
#define AC3_FRAME_BUFFER_SIZE 32768 |
Large enough for maximum possible frame size when the specification limit is ignored.
Definition at line 40 of file ac3dec.c.
Referenced by ac3_decode_frame(), and ac3_decode_init().
#define LEVEL_MINUS_3DB 0.7071067811865476 |
#define LEVEL_PLUS_3DB 1.4142135623730950 |
static av_cold int ac3_decode_end | ( | AVCodecContext * | avctx | ) | [static] |
static int ac3_decode_frame | ( | AVCodecContext * | avctx, | |
void * | data, | |||
int * | data_size, | |||
const uint8_t * | buf, | |||
int | buf_size | |||
) | [static] |
static av_cold int ac3_decode_init | ( | AVCodecContext * | avctx | ) | [static] |
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 448 of file ac3dec.c.
Referenced by decode_transform_coeffs_ch().
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 231 of file ac3dec.c.
Referenced by parse_frame_header().
static av_cold void ac3_tables_init | ( | void | ) | [static] |
static void ac3_upmix_delay | ( | AC3DecodeContext * | s | ) | [static] |
Upmix delay samples from stereo to original channel layout.
Definition at line 690 of file ac3dec.c.
Referenced by decode_audio_block().
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 409 of file ac3dec.c.
Referenced by decode_transform_coeffs().
static int decode_audio_block | ( | AC3DecodeContext * | s, | |
int | blk | |||
) | [static] |
Decode a single audio block from the AC-3 bitstream.
Definition at line 781 of file ac3dec.c.
Referenced by ac3_decode_frame().
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, | |||
uint8_t * | band_struct, | |||
int * | num_subbands, | |||
int * | num_bands, | |||
uint8_t * | band_sizes | |||
) | [static] |
Decode band structure for coupling, spectral extension, or enhanced coupling.
[in] | gbc | bit reader context |
[in] | blk | block number |
[in] | eac3 | flag to indicate E-AC-3 |
[in] | ecpl | flag to indicate enhanced coupling |
[in] | start_subband | subband number for start of range |
[in] | end_subband | subband number for end of range |
[in] | default_band_struct | default band structure table |
[out] | band_struct | decoded band structure |
[out] | num_subbands | number of subbands (optionally NULL) |
[out] | num_bands | number of bands (optionally NULL) |
[out] | band_sizes | array containing the number of bins in each band (optionally NULL) |
Definition at line 729 of file ac3dec.c.
Referenced by decode_audio_block().
static int decode_exponents | ( | 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 372 of file ac3dec.c.
Referenced by decode_audio_block().
static void decode_transform_coeffs | ( | AC3DecodeContext * | s, | |
int | blk | |||
) | [static] |
Decode the transform coefficients.
Definition at line 572 of file ac3dec.c.
Referenced by decode_audio_block().
static void decode_transform_coeffs_ch | ( | AC3DecodeContext * | s, | |
int | blk, | |||
int | ch, | |||
mant_groups * | m | |||
) | [static] |
static void do_imdct | ( | AC3DecodeContext * | s, | |
int | channels | |||
) | [inline, static] |
Inverse MDCT Transform.
Convert frequency domain coefficients to time-domain audio samples. reference: Section 7.9.4 Transformation Equations
Definition at line 634 of file ac3dec.c.
Referenced by decode_audio_block().
static void do_rematrixing | ( | AC3DecodeContext * | s | ) | [static] |
Stereo rematrixing.
reference: Section 7.5.4 Rematrixing : Decoding Technique
Definition at line 608 of file ac3dec.c.
Referenced by decode_audio_block().
void ff_ac3_downmix_c | ( | float(*) | samples[256], | |
float(*) | matrix[2], | |||
int | out_ch, | |||
int | in_ch, | |||
int | len | |||
) |
Downmix the output to mono or stereo.
Definition at line 663 of file ac3dec.c.
Referenced by dsputil_init().
static int parse_frame_header | ( | AC3DecodeContext * | s | ) | [static] |
Common function to parse AC-3 or E-AC-3 frame header.
Definition at line 271 of file ac3dec.c.
Referenced by ac3_decode_frame().
static void remove_dithering | ( | AC3DecodeContext * | s | ) | [static] |
Remove random dithering from coefficients with zero-bit mantissas reference: Section 7.3.4 Dither for Zero Bit Mantissas (bap=0).
Definition at line 523 of file ac3dec.c.
Referenced by decode_transform_coeffs().
static void 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 326 of file ac3dec.c.
Referenced by ac3_decode_frame().
static int symmetric_dequant | ( | int | code, | |
int | levels | |||
) | [inline, static] |
Symmetrical Dequantization reference: Section 7.3.3 Expansion of Mantissas for Symmetrical Quantization Tables 7.19 to 7.23.
Definition at line 124 of file ac3dec.c.
Referenced by ac3_tables_init().
Initial value:
{ .name = "ac3", .type = CODEC_TYPE_AUDIO, .id = CODEC_ID_AC3, .priv_data_size = sizeof (AC3DecodeContext), .init = ac3_decode_init, .close = ac3_decode_end, .decode = ac3_decode_frame, .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), }
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 }, }, }
Definition at line 107 of file ac3dec.c.
Referenced by set_downmix_coeffs().
int b1_mantissas[32][3] [static] |
tables for ungrouping mantissas
Definition at line 50 of file ac3dec.c.
Referenced by ac3_decode_transform_coeffs_ch(), and ac3_tables_init().
int b2_mantissas[128][3] [static] |
Definition at line 51 of file ac3dec.c.
Referenced by ac3_decode_transform_coeffs_ch(), and ac3_tables_init().
int b3_mantissas[8] [static] |
Definition at line 52 of file ac3dec.c.
Referenced by ac3_decode_transform_coeffs_ch(), and ac3_tables_init().
int b4_mantissas[128][2] [static] |
Definition at line 53 of file ac3dec.c.
Referenced by ac3_decode_transform_coeffs_ch(), and ac3_tables_init().
int b5_mantissas[16] [static] |
Definition at line 54 of file ac3dec.c.
Referenced by ac3_decode_transform_coeffs_ch(), and ac3_tables_init().
const uint8_t center_levels[4] = { 4, 5, 6, 5 } [static] |
Table for center mix levels reference: Section 5.4.2.4 cmixlev.
Definition at line 95 of file ac3dec.c.
Referenced by set_downmix_coeffs().
float dynamic_range_tab[256] [static] |
dynamic range table.
converts codes to scale factors.
Definition at line 66 of file ac3dec.c.
Referenced by ac3_tables_init(), and decode_audio_block().
Initial value:
{ .name = "eac3", .type = CODEC_TYPE_AUDIO, .id = CODEC_ID_EAC3, .priv_data_size = sizeof (AC3DecodeContext), .init = ac3_decode_init, .close = ac3_decode_end, .decode = ac3_decode_frame, .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52B (AC-3, E-AC-3)"), }
const float gain_levels[9] [static] |
Initial value:
{ LEVEL_PLUS_3DB, LEVEL_PLUS_1POINT5DB, LEVEL_ONE, LEVEL_MINUS_1POINT5DB, LEVEL_MINUS_3DB, LEVEL_MINUS_4POINT5DB, LEVEL_MINUS_6DB, LEVEL_ZERO, LEVEL_MINUS_9DB }
Definition at line 79 of file ac3dec.c.
Referenced by set_downmix_coeffs().
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 }
bits for asymmetric. reference: Table 7.18 Mapping of bap to Quantizer
Definition at line 60 of file ac3dec.c.
Referenced by ac3_decode_transform_coeffs_ch().
const uint8_t surround_levels[4] = { 4, 6, 7, 6 } [static] |
Table for surround mix levels reference: Section 5.4.2.5 surmixlev.
Definition at line 101 of file ac3dec.c.
Referenced by set_downmix_coeffs().
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 46 of file ac3dec.c.
Referenced by ac3_tables_init(), and decode_exponents().