1 /*****************************************************************************
2 * ac3_decoder.h : ac3 decoder interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: ac3_decoder.h,v 1.2 2002/02/24 20:51:09 gbazin Exp $
7 * Authors: Michel Kaempf <maxx@via.ecp.fr>
8 * Renaud Dartus <reno@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /**** ac3 decoder API - public ac3 decoder structures */
27 typedef struct ac3dec_s ac3dec_t;
29 typedef struct ac3_sync_info_s {
30 int sample_rate; /* sample rate in Hz */
31 int frame_size; /* frame size in bytes */
32 int bit_rate; /* nominal bit rate in kbps */
36 /**** ac3 decoder API - functions publically provided by the ac3 decoder ****/
38 int ac3_init (ac3dec_t * p_ac3dec);
39 int ac3_sync_frame (ac3dec_t * p_ac3dec, ac3_sync_info_t * p_sync_info);
40 int ac3_decode_frame (ac3dec_t * p_ac3dec, s16 * buffer);
42 /**** EVERYTHING AFTER THIS POINT IS PRIVATE ! DO NOT USE DIRECTLY ****/
44 /**** ac3 decoder internal structures ****/
46 /* The following structures are filled in by their corresponding parse_*
47 * functions. See http://www.atsc.org/Standards/A52/a_52.pdf for
48 * full details on each field. Indented fields are used to denote
52 typedef struct syncinfo_s {
53 /* Sync word == 0x0B77 */
55 /* crc for the first 5/8 of the sync block */
57 /* Stream Sampling Rate (kHz) 0 = 48, 1 = 44.1, 2 = 32, 3 = reserved */
62 /* Information not in the AC-3 bitstream, but derived */
63 /* Frame size in 16 bit words */
65 /* Bit rate in kilobits */
69 typedef struct bsi_s {
70 /* Bit stream identification == 0x8 */
74 /* Audio coding mode */
76 /* If we're using the centre channel then */
77 /* centre mix level */
79 /* If we're using the surround channel then */
80 /* surround mix level */
82 /* If we're in 2/0 mode then */
83 /* Dolby surround mix level - NOT USED - */
85 /* Low frequency effects on */
87 /* Dialogue Normalization level */
89 /* Compression exists */
91 /* Compression level */
93 /* Language code exists */
97 /* Audio production info exists*/
101 /* If we're in dual mono mode (acmod == 0) then extra stuff */
114 /* Timecode 1 exists */
118 /* Timecode 2 exists */
122 /* Additional bit stream info exists */
124 /* Additional bit stream length - 1 (in bytes) */
126 /* Additional bit stream information (max 64 bytes) */
129 /* Information not in the AC-3 bitstream, but derived */
130 /* Number of channels (excluding LFE)
131 * Derived from acmod */
136 typedef struct audblk_s {
137 /* block switch bit indexed by channel num */
139 /* dither enable bit indexed by channel num */
141 /* dynamic range gain exists */
143 /* dynamic range gain */
145 /* if acmod==0 then */
146 /* dynamic range 2 gain exists */
148 /* dynamic range 2 gain */
150 /* coupling strategy exists */
152 /* coupling in use */
154 /* channel coupled */
156 /* if acmod==2 then */
157 /* Phase flags in use */
159 /* coupling begin frequency code */
161 /* coupling end frequency code */
163 /* coupling band structure bits */
165 /* Do coupling co-ords exist for this channel? */
167 /* Master coupling co-ordinate */
169 /* Per coupling band coupling co-ordinates */
171 u16 cplcomant[5][18];
172 /* Phase flags for dual mono */
174 /* Is there a rematrixing strategy */
176 /* Rematrixing bits */
178 /* Coupling exponent strategy */
180 /* Exponent strategy for full bandwidth channels */
182 /* Exponent strategy for lfe channel */
184 /* Channel bandwidth for independent channels */
186 /* The absolute coupling exponent */
188 /* Coupling channel exponents (D15 mode gives 18 * 12 /3 encoded exponents */
189 u16 cplexps[18 * 12 / 3];
190 /* Sanity checking constant */
192 /* fbw channel exponents */
193 u16 exps[5][252 / 3];
194 /* channel gain range */
196 /* low frequency exponents */
199 /* Bit allocation info */
201 /* Slow decay code */
203 /* Fast decay code */
207 /* dB per bit code */
209 /* masking floor code */
212 /* SNR offset info */
214 /* coarse SNR offset */
216 /* coupling fine SNR offset */
218 /* coupling fast gain code */
220 /* fbw fine SNR offset */
222 /* fbw fast gain code */
224 /* lfe fine SNR offset */
226 /* lfe fast gain code */
229 /* Coupling leak info */
231 /* coupling fast leak initialization */
233 /* coupling slow leak initialization */
236 /* delta bit allocation info */
238 /* coupling delta bit allocation exists */
240 /* fbw delta bit allocation exists */
242 /* number of cpl delta bit segments */
244 /* coupling delta bit allocation offset */
246 /* coupling delta bit allocation length */
248 /* coupling delta bit allocation length */
250 /* number of delta bit segments */
252 /* fbw delta bit allocation offset */
254 /* fbw delta bit allocation length */
256 /* fbw delta bit allocation length */
259 /* skip length exists */
264 /* channel mantissas */
265 // u16 chmant[5][256];
267 /* coupling mantissas */
268 float cpl_flt[ 256 ];
271 /* coupling mantissas */
274 /* -- Information not in the bitstream, but derived thereof -- */
276 /* Number of coupling sub-bands */
279 /* Number of combined coupling sub-bands
280 * Derived from ncplsubnd and cplbndstrc */
283 /* Number of exponent groups by channel
284 * Derived from strmant, endmant */
287 /* Number of coupling exponent groups
288 * Derived from cplbegf, cplendf, cplexpstr */
291 /* End mantissa numbers of fbw channels */
294 /* Start and end mantissa numbers for the coupling channel */
298 /* Decoded exponent info */
303 /* Bit allocation pointer results */
305 /* FIXME?? figure out exactly how many entries there should be (253-37?) */
310 /* Everything you wanted to know about band structure */
313 * The entire frequency domain is represented by 256 real
314 * floating point fourier coefficients. Only the lower 253
315 * coefficients are actually utilized however. We use arrays
316 * of 256 to be efficient in some cases.
318 * The 5 full bandwidth channels (fbw) can have their higher
319 * frequencies coupled together. These coupled channels then
320 * share their high frequency components.
322 * This coupling band is broken up into 18 sub-bands starting
323 * at mantissa number 37. Each sub-band is 12 bins wide.
325 * There are 50 bit allocation sub-bands which cover the entire
326 * frequency range. The sub-bands are of non-uniform width, and
327 * approximate a 1/6 octave scale.
330 typedef struct bit_allocate_s
343 /* These store the persistent state of the packed mantissas */
344 typedef struct mantissa_s
364 /* The bit stream structure handles the PES stream at the bit level */
365 bit_stream_t bit_stream;
367 unsigned int total_bits_read; /* temporary */
378 bit_allocate_t bit_allocate;