1 /*****************************************************************************
2 * ac3_decoder.h : ac3 decoder thread interface
4 *****************************************************************************/
8 /* Exponent strategy constants */
14 /* Delta bit allocation constants */
15 #define DELTA_BIT_REUSE (0)
16 #define DELTA_BIT_NEW (1)
17 #define DELTA_BIT_NONE (2)
18 #define DELTA_BIT_RESERVED (3)
20 /* The following structures are filled in by their corresponding parse_*
21 * functions. See http://www.atsc.org/Standards/A52/a_52.pdf for
22 * full details on each field. Indented fields are used to denote
26 typedef struct syncinfo_s
28 /* Sync word == 0x0B77 */
30 /* crc for the first 5/8 of the sync block */
32 /* Stream Sampling Rate (kHz) 0 = 48, 1 = 44.1, 2 = 32, 3 = reserved */
37 /* Information not in the AC-3 bitstream, but derived */
38 /* Frame size in 16 bit words */
40 /* Bit rate in kilobits */
47 /* Bit stream identification == 0x8 */
51 /* Audio coding mode */
53 /* If we're using the centre channel then */
54 /* centre mix level */
56 /* If we're using the surround channel then */
57 /* surround mix level */
59 /* If we're in 2/0 mode then */
60 /* Dolby surround mix level - NOT USED - */
62 /* Low frequency effects on */
64 /* Dialogue Normalization level */
66 /* Compression exists */
68 /* Compression level */
70 /* Language code exists */
74 /* Audio production info exists*/
78 /* If we're in dual mono mode (acmod == 0) then extra stuff */
91 /* Timecode 1 exists */
95 /* Timecode 2 exists */
99 /* Additional bit stream info exists */
101 /* Additional bit stream length - 1 (in bytes) */
103 /* Additional bit stream information (max 64 bytes) */
106 /* Information not in the AC-3 bitstream, but derived */
107 /* Number of channels (excluding LFE)
108 * Derived from acmod */
114 typedef struct audblk_s
116 /* block switch bit indexed by channel num */
118 /* dither enable bit indexed by channel num */
120 /* dynamic range gain exists */
122 /* dynamic range gain */
124 /* if acmod==0 then */
125 /* dynamic range 2 gain exists */
127 /* dynamic range 2 gain */
129 /* coupling strategy exists */
131 /* coupling in use */
133 /* channel coupled */
135 /* if acmod==2 then */
136 /* Phase flags in use */
138 /* coupling begin frequency code */
140 /* coupling end frequency code */
142 /* coupling band structure bits */
144 /* Do coupling co-ords exist for this channel? */
146 /* Master coupling co-ordinate */
148 /* Per coupling band coupling co-ordinates */
150 u16 cplcomant[5][18];
151 /* Phase flags for dual mono */
153 /* Is there a rematrixing strategy */
155 /* Rematrixing bits */
157 /* Coupling exponent strategy */
159 /* Exponent strategy for full bandwidth channels */
161 /* Exponent strategy for lfe channel */
163 /* Channel bandwidth for independent channels */
165 /* The absolute coupling exponent */
167 /* Coupling channel exponents (D15 mode gives 18 * 12 /3 encoded exponents */
168 u16 cplexps[18 * 12 / 3];
169 /* Sanity checking constant */
171 /* fbw channel exponents */
172 u16 exps[5][252 / 3];
173 /* channel gain range */
175 /* low frequency exponents */
178 /* Bit allocation info */
180 /* Slow decay code */
182 /* Fast decay code */
186 /* dB per bit code */
188 /* masking floor code */
191 /* SNR offset info */
193 /* coarse SNR offset */
195 /* coupling fine SNR offset */
197 /* coupling fast gain code */
199 /* fbw fine SNR offset */
201 /* fbw fast gain code */
203 /* lfe fine SNR offset */
205 /* lfe fast gain code */
208 /* Coupling leak info */
210 /* coupling fast leak initialization */
212 /* coupling slow leak initialization */
215 /* delta bit allocation info */
217 /* coupling delta bit allocation exists */
219 /* fbw delta bit allocation exists */
221 /* number of cpl delta bit segments */
223 /* coupling delta bit allocation offset */
225 /* coupling delta bit allocation length */
227 /* coupling delta bit allocation length */
229 /* number of delta bit segments */
231 /* fbw delta bit allocation offset */
233 /* fbw delta bit allocation length */
235 /* fbw delta bit allocation length */
238 /* skip length exists */
243 /* channel mantissas */
244 // u16 chmant[5][256];
246 /* coupling mantissas */
250 /* coupling mantissas */
253 /* -- Information not in the bitstream, but derived thereof -- */
255 /* Number of coupling sub-bands */
258 /* Number of combined coupling sub-bands
259 * Derived from ncplsubnd and cplbndstrc */
262 /* Number of exponent groups by channel
263 * Derived from strmant, endmant */
266 /* Number of coupling exponent groups
267 * Derived from cplbegf, cplendf, cplexpstr */
270 /* End mantissa numbers of fbw channels */
273 /* Start and end mantissa numbers for the coupling channel */
277 /* Decoded exponent info */
282 /* Bit allocation pointer results */
284 //FIXME figure out exactly how many entries there should be (253-37?)
290 /* Everything you wanted to know about band structure */
292 * The entire frequency domain is represented by 256 real
293 * floating point fourier coefficients. Only the lower 253
294 * coefficients are actually utilized however. We use arrays
295 * of 256 to be efficient in some cases.
297 * The 5 full bandwidth channels (fbw) can have their higher
298 * frequencies coupled together. These coupled channels then
299 * share their high frequency components.
301 * This coupling band is broken up into 18 sub-bands starting
302 * at mantissa number 37. Each sub-band is 12 bins wide.
304 * There are 50 bit allocation sub-bands which cover the entire
305 * frequency range. The sub-bands are of non-uniform width, and
306 * approximate a 1/6 octave scale.
309 typedef struct stream_coeffs_s
316 typedef struct stream_samples_s
318 float channel[6][256];
322 #define AC3DEC_FRAME_SIZE (2*256)
324 /*****************************************************************************
326 *****************************************************************************/
327 typedef s16 ac3dec_frame_t[ AC3DEC_FRAME_SIZE ];
329 /*****************************************************************************
330 * ac3dec_thread_t : ac3 decoder thread descriptor
331 *****************************************************************************/
332 typedef struct ac3dec_thread_s
337 vlc_thread_t thread_id; /* id for thread functions */
338 boolean_t b_die; /* `die' flag */
339 boolean_t b_error; /* `error' flag */
340 boolean_t b_invalid; /* `invalid' flag */
345 decoder_fifo_t fifo; /* stores the PES stream data */
346 /* The bit stream structure handles the PES stream at the bit level */
347 bit_stream_t bit_stream;
352 unsigned int total_bits_read;
358 stream_coeffs_t coeffs;
359 stream_samples_t samples;
364 aout_fifo_t * p_aout_fifo; /* stores the decompressed audio frames */
365 aout_thread_t * p_aout; /* needed to create the audio fifo */
369 /*****************************************************************************
371 *****************************************************************************/
372 ac3dec_thread_t * ac3dec_CreateThread( input_thread_t * p_input );
373 void ac3dec_DestroyThread( ac3dec_thread_t * p_ac3dec );