1 /*****************************************************************************
2 * ac3_decoder.h : ac3 decoder thread interface
4 *****************************************************************************/
6 /* Exponent strategy constants */
12 /* Delta bit allocation constants */
13 #define DELTA_BIT_REUSE (0)
14 #define DELTA_BIT_NEW (1)
15 #define DELTA_BIT_NONE (2)
16 #define DELTA_BIT_RESERVED (3)
18 /* The following structures are filled in by their corresponding parse_*
19 * functions. See http://www.atsc.org/Standards/A52/a_52.pdf for
20 * full details on each field. Indented fields are used to denote
24 typedef struct syncinfo_s
26 /* Sync word == 0x0B77 */
28 /* crc for the first 5/8 of the sync block */
30 /* Stream Sampling Rate (kHz) 0 = 48, 1 = 44.1, 2 = 32, 3 = reserved */
35 /* Information not in the AC-3 bitstream, but derived */
36 /* Frame size in 16 bit words */
38 /* Bit rate in kilobits */
45 /* Bit stream identification == 0x8 */
49 /* Audio coding mode */
51 /* If we're using the centre channel then */
52 /* centre mix level */
54 /* If we're using the surround channel then */
55 /* surround mix level */
57 /* If we're in 2/0 mode then */
58 /* Dolby surround mix level - NOT USED - */
60 /* Low frequency effects on */
62 /* Dialogue Normalization level */
64 /* Compression exists */
66 /* Compression level */
68 /* Language code exists */
72 /* Audio production info exists*/
76 /* If we're in dual mono mode (acmod == 0) then extra stuff */
89 /* Timecode 1 exists */
93 /* Timecode 2 exists */
97 /* Additional bit stream info exists */
99 /* Additional bit stream length - 1 (in bytes) */
101 /* Additional bit stream information (max 64 bytes) */
104 /* Information not in the AC-3 bitstream, but derived */
105 /* Number of channels (excluding LFE)
106 * Derived from acmod */
112 typedef struct audblk_s
114 /* block switch bit indexed by channel num */
116 /* dither enable bit indexed by channel num */
118 /* dynamic range gain exists */
120 /* dynamic range gain */
122 /* if acmod==0 then */
123 /* dynamic range 2 gain exists */
125 /* dynamic range 2 gain */
127 /* coupling strategy exists */
129 /* coupling in use */
131 /* channel coupled */
133 /* if acmod==2 then */
134 /* Phase flags in use */
136 /* coupling begin frequency code */
138 /* coupling end frequency code */
140 /* coupling band structure bits */
142 /* Do coupling co-ords exist for this channel? */
144 /* Master coupling co-ordinate */
146 /* Per coupling band coupling co-ordinates */
148 u16 cplcomant[5][18];
149 /* Phase flags for dual mono */
151 /* Is there a rematrixing strategy */
153 /* Rematrixing bits */
155 /* Coupling exponent strategy */
157 /* Exponent strategy for full bandwidth channels */
159 /* Exponent strategy for lfe channel */
161 /* Channel bandwidth for independent channels */
163 /* The absolute coupling exponent */
165 /* Coupling channel exponents (D15 mode gives 18 * 12 /3 encoded exponents */
166 u16 cplexps[18 * 12 / 3];
167 /* Sanity checking constant */
169 /* fbw channel exponents */
170 u16 exps[5][252 / 3];
171 /* channel gain range */
173 /* low frequency exponents */
176 /* Bit allocation info */
178 /* Slow decay code */
180 /* Fast decay code */
184 /* dB per bit code */
186 /* masking floor code */
189 /* SNR offset info */
191 /* coarse SNR offset */
193 /* coupling fine SNR offset */
195 /* coupling fast gain code */
197 /* fbw fine SNR offset */
199 /* fbw fast gain code */
201 /* lfe fine SNR offset */
203 /* lfe fast gain code */
206 /* Coupling leak info */
208 /* coupling fast leak initialization */
210 /* coupling slow leak initialization */
213 /* delta bit allocation info */
215 /* coupling delta bit allocation exists */
217 /* fbw delta bit allocation exists */
219 /* number of cpl delta bit segments */
221 /* coupling delta bit allocation offset */
223 /* coupling delta bit allocation length */
225 /* coupling delta bit allocation length */
227 /* number of delta bit segments */
229 /* fbw delta bit allocation offset */
231 /* fbw delta bit allocation length */
233 /* fbw delta bit allocation length */
236 /* skip length exists */
241 /* channel mantissas */
242 // u16 chmant[5][256];
244 /* coupling mantissas */
248 /* coupling mantissas */
251 /* -- Information not in the bitstream, but derived thereof -- */
253 /* Number of coupling sub-bands */
256 /* Number of combined coupling sub-bands
257 * Derived from ncplsubnd and cplbndstrc */
260 /* Number of exponent groups by channel
261 * Derived from strmant, endmant */
264 /* Number of coupling exponent groups
265 * Derived from cplbegf, cplendf, cplexpstr */
268 /* End mantissa numbers of fbw channels */
271 /* Start and end mantissa numbers for the coupling channel */
275 /* Decoded exponent info */
280 /* Bit allocation pointer results */
282 //FIXME figure out exactly how many entries there should be (253-37?)
288 /* Everything you wanted to know about band structure */
290 * The entire frequency domain is represented by 256 real
291 * floating point fourier coefficients. Only the lower 253
292 * coefficients are actually utilized however. We use arrays
293 * of 256 to be efficient in some cases.
295 * The 5 full bandwidth channels (fbw) can have their higher
296 * frequencies coupled together. These coupled channels then
297 * share their high frequency components.
299 * This coupling band is broken up into 18 sub-bands starting
300 * at mantissa number 37. Each sub-band is 12 bins wide.
302 * There are 50 bit allocation sub-bands which cover the entire
303 * frequency range. The sub-bands are of non-uniform width, and
304 * approximate a 1/6 octave scale.
307 typedef struct stream_coeffs_s
314 typedef struct stream_samples_s
316 float channel[6][256];
320 #define AC3DEC_FRAME_SIZE (2*256)
322 /*****************************************************************************
324 *****************************************************************************/
325 typedef s16 ac3dec_frame_t[ AC3DEC_FRAME_SIZE ];
327 /*****************************************************************************
328 * ac3dec_t : ac3 decoder descriptor
329 *****************************************************************************/
330 typedef struct ac3dec_s
332 boolean_t b_invalid; /* `invalid' flag */
338 /* The bit stream structure handles the PES stream at the bit level */
339 bit_stream_t bit_stream;
344 unsigned int total_bits_read;
350 stream_coeffs_t coeffs;
351 stream_samples_t samples;
355 int ac3_audio_block (ac3dec_t * p_ac3dec, s16 * buffer);