1 /*****************************************************************************
2 * adec.h : A52 decoder interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: adec.h,v 1.1 2002/08/04 17:23:42 sam 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 /*****************************************************************************
27 *****************************************************************************/
28 vlc_thread_t a52dec_CreateThread( decoder_fifo_t * p_fifo );
30 /**** A52 decoder API - public A52 decoder structures */
32 typedef struct a52dec_s a52dec_t;
34 typedef struct sync_info_s {
35 int sample_rate; /* sample rate in Hz */
36 int frame_size; /* frame size in bytes */
37 int bit_rate; /* nominal bit rate in kbps */
41 /**** A52 decoder API - functions publically provided by the A52 decoder ****/
43 int E_( a52_init )(a52dec_t * p_a52dec);
44 int sync_frame (a52dec_t * p_a52dec, sync_info_t * p_sync_info);
45 int decode_frame (a52dec_t * p_a52dec, s16 * buffer);
47 /**** EVERYTHING AFTER THIS POINT IS PRIVATE ! DO NOT USE DIRECTLY ****/
49 /**** A52 decoder internal structures ****/
51 /* The following structures are filled in by their corresponding parse_*
52 * functions. See http://www.atsc.org/Standards/A52/a_52.pdf for
53 * full details on each field. Indented fields are used to denote
57 typedef struct syncinfo_s {
58 /* Sync word == 0x0B77 */
60 /* crc for the first 5/8 of the sync block */
62 /* Stream Sampling Rate (kHz) 0 = 48, 1 = 44.1, 2 = 32, 3 = reserved */
67 /* Information not in the AC-3 bitstream, but derived */
68 /* Frame size in 16 bit words */
70 /* Bit rate in kilobits */
74 typedef struct bsi_s {
75 /* Bit stream identification == 0x8 */
79 /* Audio coding mode */
81 /* If we're using the centre channel then */
82 /* centre mix level */
84 /* If we're using the surround channel then */
85 /* surround mix level */
87 /* If we're in 2/0 mode then */
88 /* Dolby surround mix level - NOT USED - */
90 /* Low frequency effects on */
92 /* Dialogue Normalization level */
94 /* Compression exists */
96 /* Compression level */
98 /* Language code exists */
102 /* Audio production info exists*/
106 /* If we're in dual mono mode (acmod == 0) then extra stuff */
119 /* Timecode 1 exists */
123 /* Timecode 2 exists */
127 /* Additional bit stream info exists */
129 /* Additional bit stream length - 1 (in bytes) */
131 /* Additional bit stream information (max 64 bytes) */
134 /* Information not in the AC-3 bitstream, but derived */
135 /* Number of channels (excluding LFE)
136 * Derived from acmod */
141 typedef struct audblk_s {
142 /* block switch bit indexed by channel num */
144 /* dither enable bit indexed by channel num */
146 /* dynamic range gain exists */
148 /* dynamic range gain */
150 /* if acmod==0 then */
151 /* dynamic range 2 gain exists */
153 /* dynamic range 2 gain */
155 /* coupling strategy exists */
157 /* coupling in use */
159 /* channel coupled */
161 /* if acmod==2 then */
162 /* Phase flags in use */
164 /* coupling begin frequency code */
166 /* coupling end frequency code */
168 /* coupling band structure bits */
170 /* Do coupling co-ords exist for this channel? */
172 /* Master coupling co-ordinate */
174 /* Per coupling band coupling co-ordinates */
176 u16 cplcomant[5][18];
177 /* Phase flags for dual mono */
179 /* Is there a rematrixing strategy */
181 /* Rematrixing bits */
183 /* Coupling exponent strategy */
185 /* Exponent strategy for full bandwidth channels */
187 /* Exponent strategy for lfe channel */
189 /* Channel bandwidth for independent channels */
191 /* The absolute coupling exponent */
193 /* Coupling channel exponents (D15 mode gives 18 * 12 /3 encoded exponents */
194 u16 cplexps[18 * 12 / 3];
195 /* Sanity checking constant */
197 /* fbw channel exponents */
198 u16 exps[5][252 / 3];
199 /* channel gain range */
201 /* low frequency exponents */
204 /* Bit allocation info */
206 /* Slow decay code */
208 /* Fast decay code */
212 /* dB per bit code */
214 /* masking floor code */
217 /* SNR offset info */
219 /* coarse SNR offset */
221 /* coupling fine SNR offset */
223 /* coupling fast gain code */
225 /* fbw fine SNR offset */
227 /* fbw fast gain code */
229 /* lfe fine SNR offset */
231 /* lfe fast gain code */
234 /* Coupling leak info */
236 /* coupling fast leak initialization */
238 /* coupling slow leak initialization */
241 /* delta bit allocation info */
243 /* coupling delta bit allocation exists */
245 /* fbw delta bit allocation exists */
247 /* number of cpl delta bit segments */
249 /* coupling delta bit allocation offset */
251 /* coupling delta bit allocation length */
253 /* coupling delta bit allocation length */
255 /* number of delta bit segments */
257 /* fbw delta bit allocation offset */
259 /* fbw delta bit allocation length */
261 /* fbw delta bit allocation length */
264 /* skip length exists */
269 /* channel mantissas */
270 // u16 chmant[5][256];
272 /* coupling mantissas */
273 float cpl_flt[ 256 ];
276 /* coupling mantissas */
279 /* -- Information not in the bitstream, but derived thereof -- */
281 /* Number of coupling sub-bands */
284 /* Number of combined coupling sub-bands
285 * Derived from ncplsubnd and cplbndstrc */
288 /* Number of exponent groups by channel
289 * Derived from strmant, endmant */
292 /* Number of coupling exponent groups
293 * Derived from cplbegf, cplendf, cplexpstr */
296 /* End mantissa numbers of fbw channels */
299 /* Start and end mantissa numbers for the coupling channel */
303 /* Decoded exponent info */
308 /* Bit allocation pointer results */
310 /* FIXME?? figure out exactly how many entries there should be (253-37?) */
315 /* Everything you wanted to know about band structure */
318 * The entire frequency domain is represented by 256 real
319 * floating point fourier coefficients. Only the lower 253
320 * coefficients are actually utilized however. We use arrays
321 * of 256 to be efficient in some cases.
323 * The 5 full bandwidth channels (fbw) can have their higher
324 * frequencies coupled together. These coupled channels then
325 * share their high frequency components.
327 * This coupling band is broken up into 18 sub-bands starting
328 * at mantissa number 37. Each sub-band is 12 bins wide.
330 * There are 50 bit allocation sub-bands which cover the entire
331 * frequency range. The sub-bands are of non-uniform width, and
332 * approximate a 1/6 octave scale.
335 typedef struct bit_allocate_s
348 /* These store the persistent state of the packed mantissas */
349 typedef struct mantissa_s
360 /*****************************************************************************
361 * a52dec_t : A52 decoder thread descriptor
362 *****************************************************************************/
369 void * decoder_orig; /* pointer before memalign */
374 vlc_thread_t thread_id; /* id for thread functions */
379 decoder_fifo_t * p_fifo; /* stores the PES stream data */
381 /* The bit stream structure handles the PES stream at the bit level */
382 bit_stream_t bit_stream;
384 unsigned int total_bits_read; /* temporary */
395 bit_allocate_t bit_allocate;
397 downmix_t * p_downmix;
402 aout_fifo_t * p_aout_fifo; /* stores the decompressed audio frames */
405 void * samples_orig; /* pointer before memalign */
407 void * imdct_orig; /* pointer before memalign */