FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ac3dec_data.c
Go to the documentation of this file.
1 /*
2  * AC-3 and E-AC-3 decoder tables
3  * Copyright (c) 2007 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Tables taken directly from the AC-3 spec or derived from it.
25  */
26 
27 #include "ac3dec_data.h"
28 #include "libavutil/thread.h"
29 
30 /**
31  * Table used to ungroup 3 values stored in 5 bits.
32  * Used by bap=1 mantissas and GAQ.
33  * ff_ac3_ungroup_3_in_5_bits_tab[i] = { i/9, (i%9)/3, (i%9)%3 }
34  */
35 const uint8_t ff_ac3_ungroup_3_in_5_bits_tab[32][3] = {
36  { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 2 }, { 0, 1, 0 },
37  { 0, 1, 1 }, { 0, 1, 2 }, { 0, 2, 0 }, { 0, 2, 1 },
38  { 0, 2, 2 }, { 1, 0, 0 }, { 1, 0, 1 }, { 1, 0, 2 },
39  { 1, 1, 0 }, { 1, 1, 1 }, { 1, 1, 2 }, { 1, 2, 0 },
40  { 1, 2, 1 }, { 1, 2, 2 }, { 2, 0, 0 }, { 2, 0, 1 },
41  { 2, 0, 2 }, { 2, 1, 0 }, { 2, 1, 1 }, { 2, 1, 2 },
42  { 2, 2, 0 }, { 2, 2, 1 }, { 2, 2, 2 }, { 3, 0, 0 },
43  { 3, 0, 1 }, { 3, 0, 2 }, { 3, 1, 0 }, { 3, 1, 1 }
44 };
45 
46 /**
47  * table for ungrouping 3 values in 7 bits.
48  * used for exponents and bap=2 mantissas
49  */
51 
52 /**
53  * Symmetrical Dequantization
54  * reference: Section 7.3.3 Expansion of Mantissas for Symmetrical Quantization
55  * Tables 7.19 to 7.23
56  */
57 #define SYMMETRIC_DEQUANT(code, levels) (((code - (levels >> 1)) * (1 << 24)) / levels)
58 /**
59  * Ungrouped mantissa tables; the extra entry is padding to avoid range checks
60  */
61 /**
62  * Table 7.21
63  */
64 const int ff_ac3_bap3_mantissas[7 + 1] = {
65  SYMMETRIC_DEQUANT(0, 7),
66  SYMMETRIC_DEQUANT(1, 7),
67  SYMMETRIC_DEQUANT(2, 7),
68  SYMMETRIC_DEQUANT(3, 7),
69  SYMMETRIC_DEQUANT(4, 7),
70  SYMMETRIC_DEQUANT(5, 7),
71  SYMMETRIC_DEQUANT(6, 7),
72 };
73 /**
74  * Table 7.23
75  */
76 const int ff_ac3_bap5_mantissas[15 + 1] = {
77  SYMMETRIC_DEQUANT(0, 15),
78  SYMMETRIC_DEQUANT(1, 15),
79  SYMMETRIC_DEQUANT(2, 15),
80  SYMMETRIC_DEQUANT(3, 15),
81  SYMMETRIC_DEQUANT(4, 15),
82  SYMMETRIC_DEQUANT(5, 15),
83  SYMMETRIC_DEQUANT(6, 15),
84  SYMMETRIC_DEQUANT(7, 15),
85  SYMMETRIC_DEQUANT(8, 15),
86  SYMMETRIC_DEQUANT(9, 15),
87  SYMMETRIC_DEQUANT(10, 15),
88  SYMMETRIC_DEQUANT(11, 15),
89  SYMMETRIC_DEQUANT(12, 15),
90  SYMMETRIC_DEQUANT(13, 15),
91  SYMMETRIC_DEQUANT(14, 15),
92 };
93 
97 
98 static inline int
99 symmetric_dequant(int code, int levels)
100 {
101  return SYMMETRIC_DEQUANT(code, levels);
102 }
103 
104 static av_cold void ac3_init_static(void)
105 {
106  /* generate table for ungrouping 3 values in 7 bits
107  reference: Section 7.1.3 Exponent Decoding */
108  for (int i = 0; i < 128; ++i) {
110  ff_ac3_ungroup_3_in_7_bits_tab[i][1] = (i % 25) / 5;
111  ff_ac3_ungroup_3_in_7_bits_tab[i][2] = (i % 25) % 5;
112  }
113 
114  /* generate grouped mantissa tables
115  reference: Section 7.3.5 Ungrouping of Mantissas */
116  for (int i = 0; i < 32; ++i) {
117  /* bap=1 mantissas */
121  }
122  for (int i = 0; i < 128; ++i) {
123  /* bap=2 mantissas */
127 
128  /* bap=4 mantissas */
129  ff_ac3_bap4_mantissas[i][0] = symmetric_dequant(i / 11, 11);
130  ff_ac3_bap4_mantissas[i][1] = symmetric_dequant(i % 11, 11);
131  }
132 }
133 
135 {
136  static AVOnce ac3_init_static_once = AV_ONCE_INIT;
137  ff_thread_once(&ac3_init_static_once, ac3_init_static);
138 }
139 
140 /**
141  * Quantization table: levels for symmetric. bits for asymmetric.
142  * reference: Table 7.18 Mapping of bap to Quantizer
143  */
144 const uint8_t ff_ac3_quantization_tab[16] = {
145  0, 3, 5, 7, 11, 15,
146  5, 6, 7, 8, 9, 10, 11, 12, 14, 16
147 };
148 
149 /**
150  * Table for default stereo downmixing coefficients
151  * reference: Section 7.8.2 Downmixing Into Two Channels
152  */
153 const uint8_t ff_ac3_default_coeffs[8][5][2] = {
154  { { 2, 7 }, { 7, 2 }, },
155  { { 4, 4 }, },
156  { { 2, 7 }, { 7, 2 }, },
157  { { 2, 7 }, { 5, 5 }, { 7, 2 }, },
158  { { 2, 7 }, { 7, 2 }, { 6, 6 }, },
159  { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 8, 8 }, },
160  { { 2, 7 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, },
161  { { 2, 7 }, { 5, 5 }, { 7, 2 }, { 6, 7 }, { 7, 6 }, },
162 };
163 
164 const uint8_t ff_eac3_hebap_tab[64] = {
165  0, 1, 2, 3, 4, 5, 6, 7, 8, 8,
166  8, 8, 9, 9, 9, 10, 10, 10, 10, 11,
167  11, 11, 11, 12, 12, 12, 12, 13, 13, 13,
168  13, 14, 14, 14, 14, 15, 15, 15, 15, 16,
169  16, 16, 16, 17, 17, 17, 17, 18, 18, 18,
170  18, 18, 18, 18, 18, 19, 19, 19, 19, 19,
171  19, 19, 19, 19,
172 };
173 
174 /**
175  * Table E2.15 Default Spectral Extension Banding Structure
176  */
178 { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 };
179 
180 /** Adjustments in dB gain (LFE, +10 to -21 dB) */
181 const float ff_eac3_gain_levels_lfe[32] = {
182  3.162275, 2.818382, 2.511886, 2.238719, 1.995261, 1.778278, 1.584893,
183  1.412536, 1.258924, 1.122018, 1.000000, 0.891251, 0.794328, 0.707946,
184  0.630957, 0.562341, 0.501187, 0.446683, 0.398107, 0.354813, 0.316227,
185  0.281838, 0.251188, 0.223872, 0.199526, 0.177828, 0.158489, 0.141253,
186  0.125892, 0.112201, 0.100000, 0.089125
187 };
thread.h
SYMMETRIC_DEQUANT
#define SYMMETRIC_DEQUANT(code, levels)
Symmetrical Dequantization reference: Section 7.3.3 Expansion of Mantissas for Symmetrical Quantizati...
Definition: ac3dec_data.c:57
ff_ac3_bap4_mantissas
int ff_ac3_bap4_mantissas[128][2]
Definition: ac3dec_data.c:96
ff_ac3_bap2_mantissas
int ff_ac3_bap2_mantissas[128][3]
Definition: ac3dec_data.c:95
ff_eac3_gain_levels_lfe
const float ff_eac3_gain_levels_lfe[32]
Adjustments in dB gain (LFE, +10 to -21 dB)
Definition: ac3dec_data.c:181
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
av_cold
#define av_cold
Definition: attributes.h:90
ff_ac3_init_static
av_cold void ff_ac3_init_static(void)
Definition: ac3dec_data.c:134
ff_ac3_default_coeffs
const uint8_t ff_ac3_default_coeffs[8][5][2]
Table for default stereo downmixing coefficients reference: Section 7.8.2 Downmixing Into Two Channel...
Definition: ac3dec_data.c:153
ff_ac3_ungroup_3_in_7_bits_tab
uint8_t ff_ac3_ungroup_3_in_7_bits_tab[128][3]
table for ungrouping 3 values in 7 bits.
Definition: ac3dec_data.c:50
ac3_init_static
static av_cold void ac3_init_static(void)
Definition: ac3dec_data.c:104
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
symmetric_dequant
static int symmetric_dequant(int code, int levels)
Definition: ac3dec_data.c:99
AVOnce
#define AVOnce
Definition: thread.h:202
ac3dec_data.h
ff_ac3_ungroup_3_in_5_bits_tab
const uint8_t ff_ac3_ungroup_3_in_5_bits_tab[32][3]
Table used to ungroup 3 values stored in 5 bits.
Definition: ac3dec_data.c:35
ff_ac3_bap1_mantissas
int ff_ac3_bap1_mantissas[32][3]
tables for ungrouping mantissas
Definition: ac3dec_data.c:94
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
ff_ac3_quantization_tab
const uint8_t ff_ac3_quantization_tab[16]
Quantization table: levels for symmetric.
Definition: ac3dec_data.c:144
ff_ac3_bap5_mantissas
const int ff_ac3_bap5_mantissas[15+1]
Table 7.23.
Definition: ac3dec_data.c:76
ff_ac3_bap3_mantissas
const int ff_ac3_bap3_mantissas[7+1]
Ungrouped mantissa tables; the extra entry is padding to avoid range checks.
Definition: ac3dec_data.c:64
ff_eac3_hebap_tab
const uint8_t ff_eac3_hebap_tab[64]
Definition: ac3dec_data.c:164
ff_eac3_default_spx_band_struct
const uint8_t ff_eac3_default_spx_band_struct[17]
Table E2.15 Default Spectral Extension Banding Structure.
Definition: ac3dec_data.c:177