remove a debugging function and variable, and remove the commented-out code which...
[libav.git] / libavcodec / ac3dec.c
CommitLineData
0ec2cc35
JR
1/*
2 * AC-3 Audio Decoder
032732d4
JR
3 * This code is developed as part of Google Summer of Code 2006 Program.
4 *
0ec2cc35 5 * Copyright (c) 2006 Kartikey Mahendra BHATT (bhattkm at gmail dot com).
032732d4 6 *
de17eee7
JR
7 * For exponent decoding the code is inspired by the code in liba52 by
8 * Michel Lespinasse and Aaron Holtzman.
032732d4
JR
9 * http://liba52.sourceforge.net
10 *
0ec2cc35 11 * This file is part of FFmpeg.
2aa2c5c4 12 *
0ec2cc35 13 * FFmpeg is free software; you can redistribute it and/or
9d109601 14 * modify it under the terms of the GNU General Public
2aa2c5c4
JR
15 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or (at your option) any later version.
17 *
0ec2cc35 18 * FFmpeg is distributed in the hope that it will be useful,
2aa2c5c4
JR
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
283614b5 21 * General Public License for more details.
2aa2c5c4 22 *
283614b5 23 * You should have received a copy of the GNU General Public
0ec2cc35 24 * License along with FFmpeg; if not, write to the Free Software
2aa2c5c4
JR
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
28#include <stdio.h>
29#include <stddef.h>
30#include <math.h>
2aa2c5c4
JR
31#include <string.h>
32
33#define ALT_BITSTREAM_READER
1b293437 34
e6bca37c 35#include "avcodec.h"
cc2a8443 36#include "ac3.h"
1b293437 37#include "ac3tab.h"
2aa2c5c4
JR
38#include "bitstream.h"
39#include "dsputil.h"
cb503702 40#include "random.h"
98a27a8a 41
cc2a8443
JR
42static uint8_t bndtab[51];
43static uint8_t masktab[253];
44
967d397a
JR
45static const int nfchans_tbl[8] = { 2, 1, 2, 3, 3, 4, 4, 5 };
46
47/* table for exponent to scale_factor mapping
48 * scale_factor[i] = 2 ^ -(i + 15)
49 */
50static float scale_factors[25];
51
52static int16_t psdtab[25];
53
54static int8_t exp_1[128];
55static int8_t exp_2[128];
56static int8_t exp_3[128];
57
58static int16_t l3_quantizers_1[32];
59static int16_t l3_quantizers_2[32];
60static int16_t l3_quantizers_3[32];
61
62static int16_t l5_quantizers_1[128];
63static int16_t l5_quantizers_2[128];
64static int16_t l5_quantizers_3[128];
65
66static int16_t l7_quantizers[7];
67
68static int16_t l11_quantizers_1[128];
69static int16_t l11_quantizers_2[128];
70
71static int16_t l15_quantizers[15];
72
73static const uint8_t qntztab[16] = { 0, 5, 7, 3, 7, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16 };
74
75/* Adjustmens in dB gain */
76#define LEVEL_MINUS_3DB 0.7071067811865476
77#define LEVEL_MINUS_4POINT5DB 0.5946035575013605
78#define LEVEL_MINUS_6DB 0.5000000000000000
79#define LEVEL_PLUS_3DB 1.4142135623730951
80#define LEVEL_PLUS_6DB 2.0000000000000000
81#define LEVEL_ZERO 0.0000000000000000
82
83static const float clevs[4] = { LEVEL_MINUS_3DB, LEVEL_MINUS_4POINT5DB,
84 LEVEL_MINUS_6DB, LEVEL_MINUS_4POINT5DB };
85
86static const float slevs[4] = { LEVEL_MINUS_3DB, LEVEL_MINUS_6DB, LEVEL_ZERO, LEVEL_MINUS_6DB };
87
98a27a8a 88#define N 512 /* constant for IMDCT Block size */
1b293437 89
486637af 90#define BLOCK_SIZE 256
1b293437 91
98a27a8a 92/* Output and input configurations. */
486637af
JR
93#define AC3_OUTPUT_UNMODIFIED 0x01
94#define AC3_OUTPUT_MONO 0x02
95#define AC3_OUTPUT_STEREO 0x04
96#define AC3_OUTPUT_DOLBY 0x08
97#define AC3_OUTPUT_LFEON 0x10
1b293437 98
98a27a8a 99typedef struct {
98a27a8a
JR
100 uint16_t crc1;
101 uint8_t fscod;
102
103 uint8_t acmod;
104 uint8_t cmixlev;
105 uint8_t surmixlev;
106 uint8_t dsurmod;
107
108 uint8_t blksw;
109 uint8_t dithflag;
110 uint8_t cplinu;
111 uint8_t chincpl;
112 uint8_t phsflginu;
113 uint8_t cplbegf;
114 uint8_t cplendf;
115 uint8_t cplcoe;
116 uint32_t cplbndstrc;
117 uint8_t rematstr;
118 uint8_t rematflg;
119 uint8_t cplexpstr;
120 uint8_t lfeexpstr;
121 uint8_t chexpstr[5];
122 uint8_t sdcycod;
123 uint8_t fdcycod;
124 uint8_t sgaincod;
125 uint8_t dbpbcod;
126 uint8_t floorcod;
127 uint8_t csnroffst;
128 uint8_t cplfsnroffst;
129 uint8_t cplfgaincod;
130 uint8_t fsnroffst[5];
131 uint8_t fgaincod[5];
132 uint8_t lfefsnroffst;
133 uint8_t lfefgaincod;
134 uint8_t cplfleak;
135 uint8_t cplsleak;
136 uint8_t cpldeltbae;
137 uint8_t deltbae[5];
138 uint8_t cpldeltnseg;
139 uint8_t cpldeltoffst[8];
140 uint8_t cpldeltlen[8];
141 uint8_t cpldeltba[8];
142 uint8_t deltnseg[5];
143 uint8_t deltoffst[5][8];
144 uint8_t deltlen[5][8];
145 uint8_t deltba[5][8];
146
147 /* Derived Attributes. */
148 int sampling_rate;
149 int bit_rate;
150 int frame_size;
151
c7cfc48f
JR
152 int nfchans; //number of channels
153 int lfeon; //lfe channel in use
154
155 float dynrng; //dynamic range gain
156 float dynrng2; //dynamic range gain for 1+1 mode
157 float chcoeffs[6]; //normalized channel coefficients
158 float cplco[5][18]; //coupling coordinates
159 int ncplbnd; //number of coupling bands
160 int ncplsubnd; //number of coupling sub bands
161 int cplstrtmant; //coupling start mantissa
162 int cplendmant; //coupling end mantissa
163 int endmant[5]; //channel end mantissas
164
165 uint8_t dcplexps[256]; //decoded coupling exponents
166 uint8_t dexps[5][256]; //decoded fbw channel exponents
167 uint8_t dlfeexps[256]; //decoded lfe channel exponents
168 uint8_t cplbap[256]; //coupling bit allocation pointers
169 uint8_t bap[5][256]; //fbw channel bit allocation pointers
170 uint8_t lfebap[256]; //lfe channel bit allocation pointers
171
172 int blkoutput; //output configuration for block
173
cc2a8443 174 DECLARE_ALIGNED_16(float, transform_coeffs[AC3_MAX_CHANNELS][BLOCK_SIZE]); //transform coefficients
98a27a8a
JR
175
176 /* For IMDCT. */
c7cfc48f
JR
177 MDCTContext imdct_512; //for 512 sample imdct transform
178 MDCTContext imdct_256; //for 256 sample imdct transform
1d0a6f52 179 DSPContext dsp; //for optimization
c7cfc48f 180
cc2a8443
JR
181 DECLARE_ALIGNED_16(float, output[AC3_MAX_CHANNELS][BLOCK_SIZE]); //output after imdct transform and windowing
182 DECLARE_ALIGNED_16(float, delay[AC3_MAX_CHANNELS][BLOCK_SIZE]); //delay - added to the next block
c7cfc48f
JR
183 DECLARE_ALIGNED_16(float, tmp_imdct[BLOCK_SIZE]); //temporary storage for imdct transform
184 DECLARE_ALIGNED_16(float, tmp_output[BLOCK_SIZE * 2]); //temporary storage for output before windowing
185 DECLARE_ALIGNED_16(float, window[BLOCK_SIZE]); //window coefficients
98a27a8a
JR
186
187 /* Miscellaneous. */
188 GetBitContext gb;
cb503702 189 AVRandomState dith_state; //for dither generation
98a27a8a
JR
190} AC3DecodeContext;
191
c7cfc48f 192/*********** BEGIN INIT HELPER FUNCTIONS ***********/
2fbbd087 193/**
2fbbd087 194 * Generate a Kaiser-Bessel Derived Window.
2fbbd087 195 */
860fe8c9 196static void ac3_window_init(float *window)
2fbbd087 197{
6dc5d71f
JR
198 int i, j;
199 double sum = 0.0, bessel, tmp;
200 double local_window[256];
201 double alpha2 = (5.0 * M_PI / 256.0) * (5.0 * M_PI / 256.0);
202
203 for (i = 0; i < 256; i++) {
204 tmp = i * (256 - i) * alpha2;
205 bessel = 1.0;
206 for (j = 100; j > 0; j--) /* defaul to 100 iterations */
207 bessel = bessel * tmp / (j * j) + 1;
208 sum += bessel;
209 local_window[i] = sum;
210 }
211
212 sum++;
213 for (i = 0; i < 256; i++)
214 window[i] = sqrt(local_window[i] / sum);
2fbbd087
JR
215}
216
c7cfc48f
JR
217/*
218 * Generate quantizer tables.
219 */
98a27a8a
JR
220static void generate_quantizers_table(int16_t quantizers[], int level, int length)
221{
222 int i;
223
224 for (i = 0; i < length; i++)
225 quantizers[i] = ((2 * i - level + 1) << 15) / level;
226}
227
228static void generate_quantizers_table_1(int16_t quantizers[], int level, int length1, int length2, int size)
229{
230 int i, j;
231 int16_t v;
232
233 for (i = 0; i < length1; i++) {
234 v = ((2 * i - level + 1) << 15) / level;
235 for (j = 0; j < length2; j++)
236 quantizers[i * length2 + j] = v;
237 }
238
239 for (i = length1 * length2; i < size; i++)
240 quantizers[i] = 0;
241}
242
243static void generate_quantizers_table_2(int16_t quantizers[], int level, int length1, int length2, int size)
244{
245 int i, j;
246 int16_t v;
247
248 for (i = 0; i < length1; i++) {
249 v = ((2 * (i % level) - level + 1) << 15) / level;
250 for (j = 0; j < length2; j++)
251 quantizers[i * length2 + j] = v;
252 }
253
254 for (i = length1 * length2; i < size; i++)
255 quantizers[i] = 0;
256
257}
258
259static void generate_quantizers_table_3(int16_t quantizers[], int level, int length1, int length2, int size)
260{
261 int i, j;
262
263 for (i = 0; i < length1; i++)
264 for (j = 0; j < length2; j++)
265 quantizers[i * length2 + j] = ((2 * (j % level) - level + 1) << 15) / level;
1b293437 266
98a27a8a
JR
267 for (i = length1 * length2; i < size; i++)
268 quantizers[i] = 0;
269}
270
c7cfc48f
JR
271/*
272 * Initialize tables at runtime.
273 */
98a27a8a 274static void ac3_tables_init(void)
00585845
JR
275{
276 int i, j, k, l, v;
277 /* compute bndtab and masktab from bandsz */
278 k = 0;
279 l = 0;
280 for(i=0;i<50;i++) {
281 bndtab[i] = l;
cc2a8443 282 v = ff_ac3_bndsz[i];
00585845
JR
283 for(j=0;j<v;j++) masktab[k++]=i;
284 l += v;
285 }
286 masktab[253] = masktab[254] = masktab[255] = 0;
287 bndtab[50] = 0;
98a27a8a 288
c7cfc48f
JR
289 /* PSD Table For Mapping Exponents To PSD. */
290 for (i = 0; i < 25; i++)
291 psdtab[i] = 3072 - (i << 7);
292
98a27a8a
JR
293 /* Exponent Decoding Tables */
294 for (i = 0; i < 5; i++) {
295 v = i - 2;
296 for (j = 0; j < 25; j++)
297 exp_1[i * 25 + j] = v;
298 }
299
300 for (i = 0; i < 25; i++) {
301 v = (i % 5) - 2;
302 for (j = 0; j < 5; j++)
303 exp_2[i * 5 + j] = v;
304 }
305
306 for (i = 0; i < 25; i++) {
307 v = -2;
308 for (j = 0; j < 5; j++)
309 exp_3[i * 5 + j] = v++;
310 }
311
312 for (i = 125; i < 128; i++)
313 exp_1[i] = exp_2[i] = exp_3[i] = 25;
314 /* End Exponent Decoding Tables */
315
316 /* Quantizer ungrouping tables. */
317 // for level-3 quantizers
318 generate_quantizers_table_1(l3_quantizers_1, 3, 3, 9, 32);
319 generate_quantizers_table_2(l3_quantizers_2, 3, 9, 3, 32);
320 generate_quantizers_table_3(l3_quantizers_3, 3, 9, 3, 32);
321
322 //for level-5 quantizers
323 generate_quantizers_table_1(l5_quantizers_1, 5, 5, 25, 128);
324 generate_quantizers_table_2(l5_quantizers_2, 5, 25, 5, 128);
325 generate_quantizers_table_3(l5_quantizers_3, 5, 25, 5, 128);
326
327 //for level-7 quantizers
328 generate_quantizers_table(l7_quantizers, 7, 7);
329
330 //for level-4 quantizers
331 generate_quantizers_table_2(l11_quantizers_1, 11, 11, 11, 128);
332 generate_quantizers_table_3(l11_quantizers_2, 11, 11, 11, 128);
333
334 //for level-15 quantizers
335 generate_quantizers_table(l15_quantizers, 15, 15);
c7cfc48f
JR
336 /* End Quantizer ungrouping tables. */
337
338 //generate scale factors
339 for (i = 0; i < 25; i++)
340 scale_factors[i] = pow(2.0, -(i + 15));
00585845
JR
341}
342
1b293437
JR
343
344static int ac3_decode_init(AVCodecContext *avctx)
345{
346 AC3DecodeContext *ctx = avctx->priv_data;
1b293437 347
cc2a8443 348 ac3_common_init();
98a27a8a 349 ac3_tables_init();
45b0ed13
JR
350 ff_mdct_init(&ctx->imdct_256, 8, 1);
351 ff_mdct_init(&ctx->imdct_512, 9, 1);
6dc5d71f 352 ac3_window_init(ctx->window);
1d0a6f52 353 dsputil_init(&ctx->dsp, avctx);
cb503702 354 av_init_random(0, &ctx->dith_state);
2aa2c5c4 355
1b293437 356 return 0;
2aa2c5c4 357}
c7cfc48f 358/*********** END INIT FUNCTIONS ***********/
2aa2c5c4 359
c7cfc48f
JR
360/* Synchronize to ac3 bitstream.
361 * This function searches for the syncword '0xb77'.
362 *
363 * @param buf Pointer to "probable" ac3 bitstream buffer
364 * @param buf_size Size of buffer
365 * @return Returns the position where syncword is found, -1 if no syncword is found
366 */
1b293437 367static int ac3_synchronize(uint8_t *buf, int buf_size)
2aa2c5c4 368{
1b293437 369 int i;
2aa2c5c4 370
1b293437
JR
371 for (i = 0; i < buf_size - 1; i++)
372 if (buf[i] == 0x0b && buf[i + 1] == 0x77)
373 return i;
2aa2c5c4 374
1b293437 375 return -1;
2aa2c5c4
JR
376}
377
c7cfc48f
JR
378/* Parse the 'sync_info' from the ac3 bitstream.
379 * This function extracts the sync_info from ac3 bitstream.
380 * GetBitContext within AC3DecodeContext must point to
381 * start of the synchronized ac3 bitstream.
382 *
383 * @param ctx AC3DecodeContext
384 * @return Returns framesize, returns 0 if fscod, frmsizecod or bsid is not valid
385 */
1b293437 386static int ac3_parse_sync_info(AC3DecodeContext *ctx)
2aa2c5c4 387{
1b293437 388 GetBitContext *gb = &ctx->gb;
98a27a8a 389 int frmsizecod, bsid;
2aa2c5c4 390
98a27a8a
JR
391 skip_bits(gb, 16); //skip the sync_word, sync_info->sync_word = get_bits(gb, 16);
392 ctx->crc1 = get_bits(gb, 16);
393 ctx->fscod = get_bits(gb, 2);
394 if (ctx->fscod == 0x03)
00585845 395 return 0;
98a27a8a
JR
396 frmsizecod = get_bits(gb, 6);
397 if (frmsizecod >= 38)
00585845 398 return 0;
cc2a8443
JR
399 ctx->sampling_rate = ff_ac3_freqs[ctx->fscod];
400 ctx->bit_rate = ff_ac3_bitratetab[frmsizecod >> 1];
2aa2c5c4 401
00585845 402 /* we include it here in order to determine validity of ac3 frame */
98a27a8a
JR
403 bsid = get_bits(gb, 5);
404 if (bsid > 0x08)
00585845 405 return 0;
98a27a8a 406 skip_bits(gb, 3); //skip the bsmod, bsi->bsmod = get_bits(gb, 3);
00585845 407
98a27a8a 408 switch (ctx->fscod) {
00585845 409 case 0x00:
98a27a8a
JR
410 ctx->frame_size = 4 * ctx->bit_rate;
411 return ctx->frame_size;
00585845 412 case 0x01:
98a27a8a
JR
413 ctx->frame_size = 2 * (320 * ctx->bit_rate / 147 + (frmsizecod & 1));
414 return ctx->frame_size;
00585845 415 case 0x02:
98a27a8a
JR
416 ctx->frame_size = 6 * ctx->bit_rate;
417 return ctx->frame_size;
00585845
JR
418 }
419
420 /* never reached */
1b293437 421 return 0;
2aa2c5c4
JR
422}
423
c7cfc48f
JR
424/* Parse bsi from ac3 bitstream.
425 * This function extracts the bitstream information (bsi) from ac3 bitstream.
426 *
427 * @param ctx AC3DecodeContext after processed by ac3_parse_sync_info
428 */
98a27a8a 429static void ac3_parse_bsi(AC3DecodeContext *ctx)
2aa2c5c4 430{
1b293437 431 GetBitContext *gb = &ctx->gb;
00585845 432 int i;
2aa2c5c4 433
98a27a8a
JR
434 ctx->cmixlev = 0;
435 ctx->surmixlev = 0;
436 ctx->dsurmod = 0;
437 ctx->nfchans = 0;
cc2a8443 438 ctx->cpldeltbae = DBA_NONE;
98a27a8a 439 ctx->cpldeltnseg = 0;
00585845 440 for (i = 0; i < 5; i++) {
cc2a8443 441 ctx->deltbae[i] = DBA_NONE;
98a27a8a 442 ctx->deltnseg[i] = 0;
00585845 443 }
6dc5d71f
JR
444 ctx->dynrng = 1.0;
445 ctx->dynrng2 = 1.0;
2aa2c5c4 446
98a27a8a
JR
447 ctx->acmod = get_bits(gb, 3);
448 ctx->nfchans = nfchans_tbl[ctx->acmod];
449
450 if (ctx->acmod & 0x01 && ctx->acmod != 0x01)
451 ctx->cmixlev = get_bits(gb, 2);
452 if (ctx->acmod & 0x04)
453 ctx->surmixlev = get_bits(gb, 2);
454 if (ctx->acmod == 0x02)
455 ctx->dsurmod = get_bits(gb, 2);
456
457 ctx->lfeon = get_bits1(gb);
458
459 i = !(ctx->acmod);
460 do {
461 skip_bits(gb, 5); //skip dialog normalization
462 if (get_bits1(gb))
463 skip_bits(gb, 8); //skip compression
464 if (get_bits1(gb))
465 skip_bits(gb, 8); //skip language code
466 if (get_bits1(gb))
467 skip_bits(gb, 7); //skip audio production information
468 } while (i--);
469
470 skip_bits(gb, 2); //skip copyright bit and original bitstream bit
471
00585845 472 if (get_bits1(gb))
98a27a8a 473 skip_bits(gb, 14); //skip timecode1
00585845 474 if (get_bits1(gb))
98a27a8a
JR
475 skip_bits(gb, 14); //skip timecode2
476
00585845 477 if (get_bits1(gb)) {
98a27a8a 478 i = get_bits(gb, 6); //additional bsi length
486637af 479 do {
00585845 480 skip_bits(gb, 8);
98a27a8a 481 } while(i--);
1b293437 482 }
2aa2c5c4
JR
483}
484
c7cfc48f
JR
485/* Decodes the grouped exponents.
486 * This function decodes the coded exponents according to exponent strategy
487 * and stores them in the decoded exponents buffer.
488 *
489 * @param gb GetBitContext which points to start of coded exponents
490 * @param expstr Exponent coding strategy
491 * @param ngrps Number of grouped exponetns
492 * @param absexp Absolute exponent
493 * @param dexps Decoded exponents are stored in dexps
494 * @return Returns 0 if exponents are decoded successfully, -1 if error occurs
2aa2c5c4 495 */
00585845 496static int decode_exponents(GetBitContext *gb, int expstr, int ngrps, uint8_t absexp, uint8_t *dexps)
2aa2c5c4 497{
1b293437 498 int exps;
1b293437
JR
499
500 while (ngrps--) {
00585845 501 exps = get_bits(gb, 7);
1b293437
JR
502
503 absexp += exp_1[exps];
00585845
JR
504 if (absexp > 24) {
505 av_log(NULL, AV_LOG_ERROR, "Absolute Exponent > 24, ngrp = %d\n", ngrps);
506 return -ngrps;
507 }
1b293437 508 switch (expstr) {
cc2a8443 509 case EXP_D45:
1b293437
JR
510 *(dexps++) = absexp;
511 *(dexps++) = absexp;
cc2a8443 512 case EXP_D25:
1b293437 513 *(dexps++) = absexp;
cc2a8443 514 case EXP_D15:
1b293437
JR
515 *(dexps++) = absexp;
516 }
00585845 517
1b293437 518 absexp += exp_2[exps];
00585845
JR
519 if (absexp > 24) {
520 av_log(NULL, AV_LOG_ERROR, "Absolute Exponent > 24, ngrp = %d\n", ngrps);
521 return -ngrps;
522 }
1b293437 523 switch (expstr) {
cc2a8443 524 case EXP_D45:
1b293437
JR
525 *(dexps++) = absexp;
526 *(dexps++) = absexp;
cc2a8443 527 case EXP_D25:
1b293437 528 *(dexps++) = absexp;
cc2a8443 529 case EXP_D15:
1b293437
JR
530 *(dexps++) = absexp;
531 }
2aa2c5c4 532
1b293437 533 absexp += exp_3[exps];
00585845
JR
534 if (absexp > 24) {
535 av_log(NULL, AV_LOG_ERROR, "Absolute Exponent > 24, ngrp = %d\n", ngrps);
536 return -ngrps;
537 }
1b293437 538 switch (expstr) {
cc2a8443 539 case EXP_D45:
1b293437
JR
540 *(dexps++) = absexp;
541 *(dexps++) = absexp;
cc2a8443 542 case EXP_D25:
1b293437 543 *(dexps++) = absexp;
cc2a8443 544 case EXP_D15:
1b293437
JR
545 *(dexps++) = absexp;
546 }
2aa2c5c4 547 }
2aa2c5c4 548
1b293437 549 return 0;
2aa2c5c4
JR
550}
551
c7cfc48f 552/*********** HELPER FUNCTIONS FOR BIT ALLOCATION ***********/
00585845 553static inline int logadd(int a, int b)
2aa2c5c4 554{
00585845
JR
555 int c = a - b;
556 int address;
1b293437 557
a39532b0 558 address = FFMIN((FFABS(c) >> 1), 255);
2aa2c5c4 559
00585845 560 if (c >= 0)
cc2a8443 561 return (a + ff_ac3_latab[address]);
00585845 562 else
cc2a8443 563 return (b + ff_ac3_latab[address]);
2aa2c5c4
JR
564}
565
00585845 566static inline int calc_lowcomp(int a, int b0, int b1, int bin)
2aa2c5c4 567{
1b293437
JR
568 if (bin < 7) {
569 if ((b0 + 256) == b1)
570 a = 384;
571 else if (b0 > b1)
2fbbd087 572 a = FFMAX(0, (a - 64));
1b293437
JR
573 }
574 else if (bin < 20) {
575 if ((b0 + 256) == b1)
576 a = 320;
577 else if (b0 > b1)
2fbbd087 578 a = FFMAX(0, (a - 64));
1b293437 579 }
00585845 580 else
2fbbd087 581 a = FFMAX(0, (a - 128));
1b293437
JR
582
583 return a;
2aa2c5c4 584}
c7cfc48f 585/*********** END HELPER FUNCTIONS FOR BIT ALLOCATION ***********/
2aa2c5c4 586
c7cfc48f
JR
587/* Performs bit allocation.
588 * This function performs bit allocation for the requested chanenl.
2aa2c5c4 589 */
2fbbd087 590static void do_bit_allocation(AC3DecodeContext *ctx, int chnl)
2aa2c5c4 591{
2fbbd087 592 int16_t psd[256], bndpsd[50], excite[50], mask[50], delta;
00585845 593 int sdecay, fdecay, sgain, dbknee, floor;
2fbbd087 594 int lowcomp = 0, fgain = 0, snroffset = 0, fastleak = 0, slowleak = 0, do_delta = 0;
00585845
JR
595 int start = 0, end = 0, bin = 0, i = 0, j = 0, k = 0, lastbin = 0, bndstrt = 0;
596 int bndend = 0, begin = 0, deltnseg = 0, band = 0, seg = 0, address = 0;
98a27a8a 597 int fscod = ctx->fscod;
2fbbd087
JR
598 uint8_t *deltoffst = 0, *deltlen = 0, *deltba = 0;
599 uint8_t *exps = 0, *bap = 0;
1b293437
JR
600
601 /* initialization */
cc2a8443
JR
602 sdecay = ff_sdecaytab[ctx->sdcycod];
603 fdecay = ff_fdecaytab[ctx->fdcycod];
604 sgain = ff_sgaintab[ctx->sgaincod];
605 dbknee = ff_dbkneetab[ctx->dbpbcod];
606 floor = ff_floortab[ctx->floorcod];
1b293437
JR
607
608 if (chnl == 5) {
98a27a8a
JR
609 start = ctx->cplstrtmant;
610 end = ctx->cplendmant;
cc2a8443 611 fgain = ff_fgaintab[ctx->cplfgaincod];
98a27a8a
JR
612 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->cplfsnroffst) << 2;
613 fastleak = (ctx->cplfleak << 8) + 768;
614 slowleak = (ctx->cplsleak << 8) + 768;
615 exps = ctx->dcplexps;
2fbbd087 616 bap = ctx->cplbap;
cc2a8443 617 if (ctx->cpldeltbae == DBA_NEW || ctx->deltbae == DBA_REUSE) {
1b293437 618 do_delta = 1;
98a27a8a
JR
619 deltnseg = ctx->cpldeltnseg;
620 deltoffst = ctx->cpldeltoffst;
621 deltlen = ctx->cpldeltlen;
622 deltba = ctx->cpldeltba;
2aa2c5c4
JR
623 }
624 }
1b293437
JR
625 else if (chnl == 6) {
626 start = 0;
627 end = 7;
628 lowcomp = 0;
00585845
JR
629 fastleak = 0;
630 slowleak = 0;
cc2a8443 631 fgain = ff_fgaintab[ctx->lfefgaincod];
98a27a8a
JR
632 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->lfefsnroffst) << 2;
633 exps = ctx->dlfeexps;
2fbbd087 634 bap = ctx->lfebap;
1b293437
JR
635 }
636 else {
637 start = 0;
98a27a8a 638 end = ctx->endmant[chnl];
1b293437 639 lowcomp = 0;
00585845
JR
640 fastleak = 0;
641 slowleak = 0;
cc2a8443 642 fgain = ff_fgaintab[ctx->fgaincod[chnl]];
98a27a8a
JR
643 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->fsnroffst[chnl]) << 2;
644 exps = ctx->dexps[chnl];
2fbbd087 645 bap = ctx->bap[chnl];
cc2a8443 646 if (ctx->deltbae[chnl] == DBA_NEW || ctx->deltbae[chnl] == DBA_REUSE) {
1b293437 647 do_delta = 1;
98a27a8a
JR
648 deltnseg = ctx->deltnseg[chnl];
649 deltoffst = ctx->deltoffst[chnl];
650 deltlen = ctx->deltlen[chnl];
651 deltba = ctx->deltba[chnl];
1b293437
JR
652 }
653 }
654
655 for (bin = start; bin < end; bin++) /* exponent mapping into psd */
c7cfc48f 656 psd[bin] = psdtab[exps[bin]];
1b293437
JR
657
658 /* psd integration */
659 j = start;
660 k = masktab[start];
661 do {
cc2a8443 662 lastbin = FFMIN((bndtab[k] + ff_ac3_bndsz[k]), end);
1b293437
JR
663 bndpsd[k] = psd[j];
664 j++;
665 for (i = j; i < lastbin; i++) {
666 bndpsd[k] = logadd(bndpsd[k], psd[j]);
667 j++;
668 }
669 k++;
670 } while (end > lastbin);
671
672 /* compute the excite function */
673 bndstrt = masktab[start];
674 bndend = masktab[end - 1] + 1;
675 if (bndstrt == 0) {
676 lowcomp = calc_lowcomp(lowcomp, bndpsd[0], bndpsd[1], 0);
677 excite[0] = bndpsd[0] - fgain - lowcomp;
678 lowcomp = calc_lowcomp(lowcomp, bndpsd[1], bndpsd[2], 1);
679 excite[1] = bndpsd[1] - fgain - lowcomp;
680 begin = 7;
681 for (bin = 2; bin < 7; bin++) {
2fbbd087 682 if ((bndend != 7) || (bin != 6))
1b293437
JR
683 lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin + 1], bin);
684 fastleak = bndpsd[bin] - fgain;
685 slowleak = bndpsd[bin] - sgain;
686 excite[bin] = fastleak - lowcomp;
2fbbd087 687 if ((bndend != 7) || (bin != 6))
1b293437
JR
688 if (bndpsd[bin] <= bndpsd[bin + 1]) {
689 begin = bin + 1;
690 break;
691 }
692 }
00585845 693 for (bin = begin; bin < FFMIN(bndend, 22); bin++) {
2fbbd087 694 if ((bndend != 7) || (bin != 6))
1b293437
JR
695 lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin + 1], bin);
696 fastleak -= fdecay;
2fbbd087 697 fastleak = FFMAX(fastleak, (bndpsd[bin] - fgain));
1b293437 698 slowleak -= sdecay;
2fbbd087
JR
699 slowleak = FFMAX(slowleak, (bndpsd[bin] - sgain));
700 excite[bin] = FFMAX((fastleak - lowcomp), slowleak);
1b293437
JR
701 }
702 begin = 22;
703 }
704 else {
705 begin = bndstrt;
706 }
707 for (bin = begin; bin < bndend; bin++) {
708 fastleak -= fdecay;
2fbbd087 709 fastleak = FFMAX(fastleak, (bndpsd[bin] - fgain));
1b293437 710 slowleak -= sdecay;
2fbbd087 711 slowleak = FFMAX(slowleak, (bndpsd[bin] - sgain));
1b293437
JR
712 excite[bin] = FFMAX(fastleak, slowleak);
713 }
714
715 /* compute the masking curve */
716 for (bin = bndstrt; bin < bndend; bin++) {
717 if (bndpsd[bin] < dbknee)
718 excite[bin] += ((dbknee - bndpsd[bin]) >> 2);
cc2a8443 719 mask[bin] = FFMAX(excite[bin], ff_ac3_hth[bin][fscod]);
1b293437
JR
720 }
721
722 /* apply the delta bit allocation */
723 if (do_delta) {
724 band = 0;
725 for (seg = 0; seg < deltnseg + 1; seg++) {
2fbbd087
JR
726 band += deltoffst[seg];
727 if (deltba[seg] >= 4)
728 delta = (deltba[seg] - 3) << 7;
1b293437 729 else
2fbbd087
JR
730 delta = (deltba[seg] - 4) << 7;
731 for (k = 0; k < deltlen[seg]; k++) {
1b293437
JR
732 mask[band] += delta;
733 band++;
734 }
735 }
736 }
737
738 /*compute the bit allocation */
739 i = start;
740 j = masktab[start];
741 do {
cc2a8443 742 lastbin = FFMIN((bndtab[j] + ff_ac3_bndsz[j]), end);
1b293437
JR
743 mask[j] -= snroffset;
744 mask[j] -= floor;
745 if (mask[j] < 0)
746 mask[j] = 0;
747 mask[j] &= 0x1fe0;
748 mask[j] += floor;
749 for (k = i; k < lastbin; k++) {
750 address = (psd[i] - mask[j]) >> 5;
2fbbd087 751 address = FFMIN(63, (FFMAX(0, address)));
cc2a8443 752 bap[i] = ff_ac3_baptab[address];
1b293437
JR
753 i++;
754 }
755 j++;
756 } while (end > lastbin);
2aa2c5c4
JR
757}
758
2fbbd087
JR
759/* Check if snroffsets are zero. */
760static int is_snr_offsets_zero(AC3DecodeContext *ctx)
2aa2c5c4 761{
2fbbd087 762 int i;
1b293437 763
2fbbd087 764 if ((ctx->csnroffst) || (ctx->cplinu && ctx->cplfsnroffst) ||
98a27a8a 765 (ctx->lfeon && ctx->lfefsnroffst))
2fbbd087 766 return 0;
1b293437 767
98a27a8a 768 for (i = 0; i < ctx->nfchans; i++)
2fbbd087
JR
769 if (ctx->fsnroffst[i])
770 return 0;
771
772 return 1;
1b293437 773}
2aa2c5c4 774
486637af 775typedef struct { /* grouped mantissas for 3-level 5-leve and 11-level quantization */
98a27a8a
JR
776 int16_t l3_quantizers[3];
777 int16_t l5_quantizers[3];
778 int16_t l11_quantizers[2];
486637af
JR
779 int l3ptr;
780 int l5ptr;
781 int l11ptr;
782} mant_groups;
783
784#define TRANSFORM_COEFF(tc, m, e, f) (tc) = (m) * (f)[(e)]
785
786/* Get the transform coefficients for coupling channel and uncouple channels.
787 * The coupling transform coefficients starts at the the cplstrtmant, which is
788 * equal to endmant[ch] for fbw channels. Hence we can uncouple channels before
789 * getting transform coefficients for the channel.
790 */
791static int get_transform_coeffs_cpling(AC3DecodeContext *ctx, mant_groups *m)
1b293437 792{
486637af 793 GetBitContext *gb = &ctx->gb;
2fbbd087 794 int ch, start, end, cplbndstrc, bnd, gcode, tbap;
486637af 795 float cplcos[5], cplcoeff;
98a27a8a
JR
796 uint8_t *exps = ctx->dcplexps;
797 uint8_t *bap = ctx->cplbap;
798
98a27a8a
JR
799 cplbndstrc = ctx->cplbndstrc;
800 start = ctx->cplstrtmant;
801 bnd = 0;
802
803 while (start < ctx->cplendmant) {
804 end = start + 12;
805 while (cplbndstrc & 1) {
806 end += 12;
807 cplbndstrc >>= 1;
808 }
809 cplbndstrc >>= 1;
810 for (ch = 0; ch < ctx->nfchans; ch++)
811 cplcos[ch] = ctx->chcoeffs[ch] * ctx->cplco[ch][bnd];
812 bnd++;
813
814 while (start < end) {
815 tbap = bap[start];
816 switch(tbap) {
486637af 817 case 0:
2fbbd087 818 for (ch = 0; ch < ctx->nfchans; ch++)
98a27a8a 819 if (((ctx->chincpl) >> ch) & 1) {
45b0ed13 820 if ((ctx->dithflag >> ch) & 1) {
cb503702 821 TRANSFORM_COEFF(cplcoeff, av_random(&ctx->dith_state) & 0xFFFF, exps[start], scale_factors);
45b0ed13 822 ctx->transform_coeffs[ch + 1][start] = cplcoeff * cplcos[ch] * LEVEL_MINUS_3DB;
486637af 823 } else
98a27a8a 824 ctx->transform_coeffs[ch + 1][start] = 0;
486637af 825 }
98a27a8a 826 start++;
486637af
JR
827 continue;
828 case 1:
829 if (m->l3ptr > 2) {
830 gcode = get_bits(gb, 5);
98a27a8a
JR
831 m->l3_quantizers[0] = l3_quantizers_1[gcode];
832 m->l3_quantizers[1] = l3_quantizers_2[gcode];
833 m->l3_quantizers[2] = l3_quantizers_3[gcode];
486637af
JR
834 m->l3ptr = 0;
835 }
98a27a8a 836 TRANSFORM_COEFF(cplcoeff, m->l3_quantizers[m->l3ptr++], exps[start], scale_factors);
486637af
JR
837 break;
838
839 case 2:
840 if (m->l5ptr > 2) {
841 gcode = get_bits(gb, 7);
98a27a8a
JR
842 m->l5_quantizers[0] = l5_quantizers_1[gcode];
843 m->l5_quantizers[1] = l5_quantizers_2[gcode];
844 m->l5_quantizers[2] = l5_quantizers_3[gcode];
486637af
JR
845 m->l5ptr = 0;
846 }
98a27a8a 847 TRANSFORM_COEFF(cplcoeff, m->l5_quantizers[m->l5ptr++], exps[start], scale_factors);
486637af
JR
848 break;
849
850 case 3:
2fbbd087 851 TRANSFORM_COEFF(cplcoeff, l7_quantizers[get_bits(gb, 3)], exps[start], scale_factors);
486637af
JR
852 break;
853
854 case 4:
855 if (m->l11ptr > 1) {
856 gcode = get_bits(gb, 7);
98a27a8a
JR
857 m->l11_quantizers[0] = l11_quantizers_1[gcode];
858 m->l11_quantizers[1] = l11_quantizers_2[gcode];
486637af
JR
859 m->l11ptr = 0;
860 }
98a27a8a 861 TRANSFORM_COEFF(cplcoeff, m->l11_quantizers[m->l11ptr++], exps[start], scale_factors);
486637af
JR
862 break;
863
864 case 5:
2fbbd087 865 TRANSFORM_COEFF(cplcoeff, l15_quantizers[get_bits(gb, 4)], exps[start], scale_factors);
486637af
JR
866 break;
867
868 default:
45b0ed13 869 TRANSFORM_COEFF(cplcoeff, get_sbits(gb, qntztab[tbap]) << (16 - qntztab[tbap]),
2fbbd087 870 exps[start], scale_factors);
486637af 871 }
98a27a8a
JR
872 for (ch = 0; ch < ctx->nfchans; ch++)
873 if ((ctx->chincpl >> ch) & 1)
2fbbd087 874 ctx->transform_coeffs[ch + 1][start] = cplcoeff * cplcos[ch];
98a27a8a 875 start++;
486637af
JR
876 }
877 }
878
879 return 0;
880}
1b293437
JR
881
882/* Get the transform coefficients for particular channel */
2fbbd087 883static int get_transform_coeffs_ch(AC3DecodeContext *ctx, int ch_index, mant_groups *m)
1b293437 884{
2fbbd087
JR
885 GetBitContext *gb = &ctx->gb;
886 int i, gcode, tbap, dithflag, end;
887 uint8_t *exps;
888 uint8_t *bap;
889 float *coeffs;
486637af 890 float factors[25];
1b293437 891
486637af 892 for (i = 0; i < 25; i++)
2fbbd087
JR
893 factors[i] = scale_factors[i] * ctx->chcoeffs[ch_index];
894
895 if (ch_index != -1) { /* fbw channels */
896 dithflag = (ctx->dithflag >> ch_index) & 1;
897 exps = ctx->dexps[ch_index];
898 bap = ctx->bap[ch_index];
899 coeffs = ctx->transform_coeffs[ch_index + 1];
900 end = ctx->endmant[ch_index];
901 } else if (ch_index == -1) {
902 dithflag = 0;
903 exps = ctx->dlfeexps;
904 bap = ctx->lfebap;
905 coeffs = ctx->transform_coeffs[0];
906 end = 7;
907 }
1b293437 908
2fbbd087
JR
909
910 for (i = 0; i < end; i++) {
98a27a8a
JR
911 tbap = bap[i];
912 switch (tbap) {
1b293437 913 case 0:
45b0ed13 914 if (!dithflag) {
00585845
JR
915 coeffs[i] = 0;
916 continue;
917 }
918 else {
cb503702 919 TRANSFORM_COEFF(coeffs[i], av_random(&ctx->dith_state) & 0xFFFF, exps[i], factors);
45b0ed13 920 coeffs[i] *= LEVEL_MINUS_3DB;
00585845
JR
921 continue;
922 }
1b293437
JR
923
924 case 1:
486637af 925 if (m->l3ptr > 2) {
00585845 926 gcode = get_bits(gb, 5);
98a27a8a
JR
927 m->l3_quantizers[0] = l3_quantizers_1[gcode];
928 m->l3_quantizers[1] = l3_quantizers_2[gcode];
929 m->l3_quantizers[2] = l3_quantizers_3[gcode];
486637af 930 m->l3ptr = 0;
1b293437 931 }
98a27a8a 932 TRANSFORM_COEFF(coeffs[i], m->l3_quantizers[m->l3ptr++], exps[i], factors);
00585845 933 continue;
1b293437
JR
934
935 case 2:
486637af 936 if (m->l5ptr > 2) {
00585845 937 gcode = get_bits(gb, 7);
98a27a8a
JR
938 m->l5_quantizers[0] = l5_quantizers_1[gcode];
939 m->l5_quantizers[1] = l5_quantizers_2[gcode];
940 m->l5_quantizers[2] = l5_quantizers_3[gcode];
486637af 941 m->l5ptr = 0;
1b293437 942 }
98a27a8a 943 TRANSFORM_COEFF(coeffs[i], m->l5_quantizers[m->l5ptr++], exps[i], factors);
00585845 944 continue;
1b293437
JR
945
946 case 3:
2fbbd087 947 TRANSFORM_COEFF(coeffs[i], l7_quantizers[get_bits(gb, 3)], exps[i], factors);
00585845 948 continue;
1b293437
JR
949
950 case 4:
486637af 951 if (m->l11ptr > 1) {
00585845 952 gcode = get_bits(gb, 7);
98a27a8a
JR
953 m->l11_quantizers[0] = l11_quantizers_1[gcode];
954 m->l11_quantizers[1] = l11_quantizers_2[gcode];
486637af 955 m->l11ptr = 0;
1b293437 956 }
98a27a8a 957 TRANSFORM_COEFF(coeffs[i], m->l11_quantizers[m->l11ptr++], exps[i], factors);
00585845 958 continue;
1b293437
JR
959
960 case 5:
2fbbd087 961 TRANSFORM_COEFF(coeffs[i], l15_quantizers[get_bits(gb, 4)], exps[i], factors);
00585845 962 continue;
1b293437
JR
963
964 default:
45b0ed13 965 TRANSFORM_COEFF(coeffs[i], get_sbits(gb, qntztab[tbap]) << (16 - qntztab[tbap]), exps[i], factors);
00585845 966 continue;
1b293437
JR
967 }
968 }
969
1b293437
JR
970 return 0;
971}
972
c7cfc48f
JR
973/* Get the transform coefficients.
974 * This function extracts the tranform coefficients form the ac3 bitstream.
975 * This function is called after bit allocation is performed.
976 */
1b293437
JR
977static int get_transform_coeffs(AC3DecodeContext * ctx)
978{
486637af 979 int i, end;
1b293437 980 int got_cplchan = 0;
486637af
JR
981 mant_groups m;
982
983 m.l3ptr = m.l5ptr = m.l11ptr = 3;
1b293437 984
98a27a8a 985 for (i = 0; i < ctx->nfchans; i++) {
1b293437 986 /* transform coefficients for individual channel */
2fbbd087 987 if (get_transform_coeffs_ch(ctx, i, &m))
1b293437
JR
988 return -1;
989 /* tranform coefficients for coupling channels */
98a27a8a 990 if ((ctx->chincpl >> i) & 1) {
486637af 991 if (!got_cplchan) {
98a27a8a
JR
992 if (get_transform_coeffs_cpling(ctx, &m)) {
993 av_log(NULL, AV_LOG_ERROR, "error in decoupling channels\n");
486637af 994 return -1;
98a27a8a 995 }
486637af
JR
996 got_cplchan = 1;
997 }
98a27a8a 998 end = ctx->cplendmant;
486637af 999 } else
98a27a8a 1000 end = ctx->endmant[i];
486637af 1001 do
98a27a8a 1002 ctx->transform_coeffs[i + 1][end] = 0;
486637af
JR
1003 while(++end < 256);
1004 }
98a27a8a 1005 if (ctx->lfeon) {
2fbbd087 1006 if (get_transform_coeffs_ch(ctx, -1, &m))
1b293437 1007 return -1;
486637af 1008 for (i = 7; i < 256; i++) {
98a27a8a 1009 ctx->transform_coeffs[0][i] = 0;
1b293437
JR
1010 }
1011 }
1b293437
JR
1012
1013 return 0;
2aa2c5c4
JR
1014}
1015
c7cfc48f 1016/* Rematrixing routines. */
00585845 1017static void do_rematrixing1(AC3DecodeContext *ctx, int start, int end)
1b293437
JR
1018{
1019 float tmp0, tmp1;
1020
1021 while (start < end) {
98a27a8a
JR
1022 tmp0 = ctx->transform_coeffs[1][start];
1023 tmp1 = ctx->transform_coeffs[2][start];
1024 ctx->transform_coeffs[1][start] = tmp0 + tmp1;
1025 ctx->transform_coeffs[2][start] = tmp0 - tmp1;
1b293437
JR
1026 start++;
1027 }
1b293437 1028}
2aa2c5c4 1029
1b293437
JR
1030static void do_rematrixing(AC3DecodeContext *ctx)
1031{
2fbbd087
JR
1032 int bnd1 = 13, bnd2 = 25, bnd3 = 37, bnd4 = 61;
1033 int end, bndend;
1034
1035 end = FFMIN(ctx->endmant[0], ctx->endmant[1]);
1b293437 1036
98a27a8a 1037 if (ctx->rematflg & 1)
00585845 1038 do_rematrixing1(ctx, bnd1, bnd2);
2fbbd087 1039
98a27a8a 1040 if (ctx->rematflg & 2)
00585845 1041 do_rematrixing1(ctx, bnd2, bnd3);
2fbbd087
JR
1042
1043 bndend = bnd4;
1044 if (bndend > end) {
1045 bndend = end;
1046 if (ctx->rematflg & 4)
00585845 1047 do_rematrixing1(ctx, bnd3, bndend);
2fbbd087
JR
1048 } else {
1049 if (ctx->rematflg & 4)
00585845 1050 do_rematrixing1(ctx, bnd3, bnd4);
2fbbd087
JR
1051 if (ctx->rematflg & 8)
1052 do_rematrixing1(ctx, bnd4, end);
1b293437
JR
1053 }
1054}
2aa2c5c4 1055
c7cfc48f
JR
1056/* This function sets the normalized channel coefficients.
1057 * Transform coefficients are multipllied by the channel
1058 * coefficients to get normalized transform coefficients.
1059 */
1b293437
JR
1060static void get_downmix_coeffs(AC3DecodeContext *ctx)
1061{
98a27a8a
JR
1062 int from = ctx->acmod;
1063 int to = ctx->blkoutput;
1064 float clev = clevs[ctx->cmixlev];
1065 float slev = slevs[ctx->surmixlev];
45b0ed13 1066 float nf = 1.0; //normalization factor for downmix coeffs
6dc5d71f
JR
1067 int i;
1068
1069 if (!ctx->acmod) {
1070 ctx->chcoeffs[0] = 2 * ctx->dynrng;
1071 ctx->chcoeffs[1] = 2 * ctx->dynrng2;
1072 } else {
1073 for (i = 0; i < ctx->nfchans; i++)
1074 ctx->chcoeffs[i] = 2 * ctx->dynrng;
1075 }
1b293437
JR
1076
1077 if (to == AC3_OUTPUT_UNMODIFIED)
00585845 1078 return;
1b293437
JR
1079
1080 switch (from) {
cc2a8443 1081 case AC3_ACMOD_DUALMONO:
1b293437
JR
1082 switch (to) {
1083 case AC3_OUTPUT_MONO:
1084 case AC3_OUTPUT_STEREO: /* We Assume that sum of both mono channels is requested */
45b0ed13
JR
1085 nf = 0.5;
1086 ctx->chcoeffs[0] *= nf;
1087 ctx->chcoeffs[1] *= nf;
1b293437
JR
1088 break;
1089 }
1090 break;
cc2a8443 1091 case AC3_ACMOD_MONO:
1b293437
JR
1092 switch (to) {
1093 case AC3_OUTPUT_STEREO:
45b0ed13
JR
1094 nf = LEVEL_MINUS_3DB;
1095 ctx->chcoeffs[0] *= nf;
1b293437
JR
1096 break;
1097 }
1098 break;
cc2a8443 1099 case AC3_ACMOD_STEREO:
1b293437
JR
1100 switch (to) {
1101 case AC3_OUTPUT_MONO:
45b0ed13
JR
1102 nf = LEVEL_MINUS_3DB;
1103 ctx->chcoeffs[0] *= nf;
1104 ctx->chcoeffs[1] *= nf;
1b293437
JR
1105 break;
1106 }
1107 break;
cc2a8443 1108 case AC3_ACMOD_3F:
1b293437
JR
1109 switch (to) {
1110 case AC3_OUTPUT_MONO:
45b0ed13
JR
1111 nf = LEVEL_MINUS_3DB / (1.0 + clev);
1112 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
1113 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
1114 ctx->chcoeffs[1] *= ((nf * clev * LEVEL_MINUS_3DB) / 2.0);
1b293437
JR
1115 break;
1116 case AC3_OUTPUT_STEREO:
45b0ed13
JR
1117 nf = 1.0 / (1.0 + clev);
1118 ctx->chcoeffs[0] *= nf;
1119 ctx->chcoeffs[2] *= nf;
1120 ctx->chcoeffs[1] *= (nf * clev);
1b293437
JR
1121 break;
1122 }
1123 break;
cc2a8443 1124 case AC3_ACMOD_2F1R:
1b293437
JR
1125 switch (to) {
1126 case AC3_OUTPUT_MONO:
45b0ed13
JR
1127 nf = 2.0 * LEVEL_MINUS_3DB / (2.0 + slev);
1128 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
1129 ctx->chcoeffs[1] *= (nf * LEVEL_MINUS_3DB);
1130 ctx->chcoeffs[2] *= (nf * slev * LEVEL_MINUS_3DB);
1b293437
JR
1131 break;
1132 case AC3_OUTPUT_STEREO:
45b0ed13
JR
1133 nf = 1.0 / (1.0 + (slev * LEVEL_MINUS_3DB));
1134 ctx->chcoeffs[0] *= nf;
1135 ctx->chcoeffs[1] *= nf;
1136 ctx->chcoeffs[2] *= (nf * slev * LEVEL_MINUS_3DB);
1b293437
JR
1137 break;
1138 case AC3_OUTPUT_DOLBY:
45b0ed13
JR
1139 nf = 1.0 / (1.0 + LEVEL_MINUS_3DB);
1140 ctx->chcoeffs[0] *= nf;
1141 ctx->chcoeffs[1] *= nf;
1142 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
1b293437
JR
1143 break;
1144 }
1145 break;
cc2a8443 1146 case AC3_ACMOD_3F1R:
1b293437
JR
1147 switch (to) {
1148 case AC3_OUTPUT_MONO:
45b0ed13
JR
1149 nf = LEVEL_MINUS_3DB / (1.0 + clev + (slev / 2.0));
1150 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
1151 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
1152 ctx->chcoeffs[1] *= (nf * clev * LEVEL_PLUS_3DB);
1153 ctx->chcoeffs[3] *= (nf * slev * LEVEL_MINUS_3DB);
1b293437
JR
1154 break;
1155 case AC3_OUTPUT_STEREO:
45b0ed13
JR
1156 nf = 1.0 / (1.0 + clev + (slev * LEVEL_MINUS_3DB));
1157 ctx->chcoeffs[0] *= nf;
1158 ctx->chcoeffs[2] *= nf;
1159 ctx->chcoeffs[1] *= (nf * clev);
1160 ctx->chcoeffs[3] *= (nf * slev * LEVEL_MINUS_3DB);
1b293437
JR
1161 break;
1162 case AC3_OUTPUT_DOLBY:
45b0ed13
JR
1163 nf = 1.0 / (1.0 + (2.0 * LEVEL_MINUS_3DB));
1164 ctx->chcoeffs[0] *= nf;
1165 ctx->chcoeffs[1] *= nf;
1166 ctx->chcoeffs[1] *= (nf * LEVEL_MINUS_3DB);
1167 ctx->chcoeffs[3] *= (nf * LEVEL_MINUS_3DB);
1b293437
JR
1168 break;
1169 }
1170 break;
cc2a8443 1171 case AC3_ACMOD_2F2R:
1b293437
JR
1172 switch (to) {
1173 case AC3_OUTPUT_MONO:
45b0ed13
JR
1174 nf = LEVEL_MINUS_3DB / (1.0 + slev);
1175 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
1176 ctx->chcoeffs[1] *= (nf * LEVEL_MINUS_3DB);
1177 ctx->chcoeffs[2] *= (nf * slev * LEVEL_MINUS_3DB);
1178 ctx->chcoeffs[3] *= (nf * slev * LEVEL_MINUS_3DB);
1b293437
JR
1179 break;
1180 case AC3_OUTPUT_STEREO:
45b0ed13
JR
1181 nf = 1.0 / (1.0 + slev);
1182 ctx->chcoeffs[0] *= nf;
1183 ctx->chcoeffs[1] *= nf;
1184 ctx->chcoeffs[2] *= (nf * slev);
1185 ctx->chcoeffs[3] *= (nf * slev);
1b293437
JR
1186 break;
1187 case AC3_OUTPUT_DOLBY:
45b0ed13
JR
1188 nf = 1.0 / (1.0 + (2.0 * LEVEL_MINUS_3DB));
1189 ctx->chcoeffs[0] *= nf;
1190 ctx->chcoeffs[1] *= nf;
1191 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
1192 ctx->chcoeffs[3] *= (nf * LEVEL_MINUS_3DB);
1b293437
JR
1193 break;
1194 }
1195 break;
cc2a8443 1196 case AC3_ACMOD_3F2R:
1b293437
JR
1197 switch (to) {
1198 case AC3_OUTPUT_MONO:
45b0ed13
JR
1199 nf = LEVEL_MINUS_3DB / (1.0 + clev + slev);
1200 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
1201 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
1202 ctx->chcoeffs[1] *= (nf * clev * LEVEL_PLUS_3DB);
1203 ctx->chcoeffs[3] *= (nf * slev * LEVEL_MINUS_3DB);
1204 ctx->chcoeffs[4] *= (nf * slev * LEVEL_MINUS_3DB);
1b293437
JR
1205 break;
1206 case AC3_OUTPUT_STEREO:
45b0ed13
JR
1207 nf = 1.0 / (1.0 + clev + slev);
1208 ctx->chcoeffs[0] *= nf;
1209 ctx->chcoeffs[2] *= nf;
1210 ctx->chcoeffs[1] *= (nf * clev);
1211 ctx->chcoeffs[3] *= (nf * slev);
1212 ctx->chcoeffs[4] *= (nf * slev);
1b293437
JR
1213 break;
1214 case AC3_OUTPUT_DOLBY:
45b0ed13
JR
1215 nf = 1.0 / (1.0 + (3.0 * LEVEL_MINUS_3DB));
1216 ctx->chcoeffs[0] *= nf;
1217 ctx->chcoeffs[1] *= nf;
1218 ctx->chcoeffs[1] *= (nf * LEVEL_MINUS_3DB);
1219 ctx->chcoeffs[3] *= (nf * LEVEL_MINUS_3DB);
1220 ctx->chcoeffs[4] *= (nf * LEVEL_MINUS_3DB);
1b293437
JR
1221 break;
1222 }
1223 break;
1224 }
1225}
2aa2c5c4 1226
c7cfc48f 1227/*********** BEGIN DOWNMIX FUNCTIONS ***********/
00585845 1228static inline void mix_dualmono_to_mono(AC3DecodeContext *ctx)
1b293437
JR
1229{
1230 int i;
98a27a8a 1231 float (*output)[BLOCK_SIZE] = ctx->output;
2aa2c5c4 1232
00585845
JR
1233 for (i = 0; i < 256; i++)
1234 output[1][i] += output[2][i];
1235 memset(output[2], 0, sizeof(output[2]));
1b293437
JR
1236}
1237
00585845 1238static inline void mix_dualmono_to_stereo(AC3DecodeContext *ctx)
2aa2c5c4 1239{
1b293437
JR
1240 int i;
1241 float tmp;
98a27a8a 1242 float (*output)[BLOCK_SIZE] = ctx->output;
1b293437
JR
1243
1244 for (i = 0; i < 256; i++) {
00585845
JR
1245 tmp = output[1][i] + output[2][i];
1246 output[1][i] = output[2][i] = tmp;
1b293437 1247 }
2aa2c5c4
JR
1248}
1249
00585845 1250static inline void upmix_mono_to_stereo(AC3DecodeContext *ctx)
1b293437
JR
1251{
1252 int i;
98a27a8a 1253 float (*output)[BLOCK_SIZE] = ctx->output;
2aa2c5c4 1254
1b293437 1255 for (i = 0; i < 256; i++)
00585845 1256 output[2][i] = output[1][i];
1b293437
JR
1257}
1258
00585845 1259static inline void mix_stereo_to_mono(AC3DecodeContext *ctx)
2aa2c5c4 1260{
1b293437 1261 int i;
98a27a8a 1262 float (*output)[BLOCK_SIZE] = ctx->output;
2aa2c5c4 1263
00585845
JR
1264 for (i = 0; i < 256; i++)
1265 output[1][i] += output[2][i];
1266 memset(output[2], 0, sizeof(output[2]));
1b293437 1267}
2aa2c5c4 1268
00585845 1269static inline void mix_3f_to_mono(AC3DecodeContext *ctx)
1b293437
JR
1270{
1271 int i;
98a27a8a 1272 float (*output)[BLOCK_SIZE] = ctx->output;
2aa2c5c4 1273
00585845
JR
1274 for (i = 0; i < 256; i++)
1275 output[1][i] += (output[2][i] + output[3][i]);
1276 memset(output[2], 0, sizeof(output[2]));
1277 memset(output[3], 0, sizeof(output[3]));
2aa2c5c4
JR
1278}
1279
00585845 1280static inline void mix_3f_to_stereo(AC3DecodeContext *ctx)
2aa2c5c4 1281{
1b293437 1282 int i;
98a27a8a 1283 float (*output)[BLOCK_SIZE] = ctx->output;
2aa2c5c4 1284
1b293437 1285 for (i = 0; i < 256; i++) {
00585845
JR
1286 output[1][i] += output[2][i];
1287 output[2][i] += output[3][i];
1b293437 1288 }
00585845 1289 memset(output[3], 0, sizeof(output[3]));
1b293437 1290}
2aa2c5c4 1291
00585845 1292static inline void mix_2f_1r_to_mono(AC3DecodeContext *ctx)
1b293437
JR
1293{
1294 int i;
98a27a8a 1295 float (*output)[BLOCK_SIZE] = ctx->output;
00585845
JR
1296
1297 for (i = 0; i < 256; i++)
1298 output[1][i] += (output[2][i] + output[3][i]);
1299 memset(output[2], 0, sizeof(output[2]));
1300 memset(output[3], 0, sizeof(output[3]));
1b293437 1301
2aa2c5c4
JR
1302}
1303
00585845 1304static inline void mix_2f_1r_to_stereo(AC3DecodeContext *ctx)
2aa2c5c4 1305{
1b293437 1306 int i;
98a27a8a 1307 float (*output)[BLOCK_SIZE] = ctx->output;
1b293437
JR
1308
1309 for (i = 0; i < 256; i++) {
00585845
JR
1310 output[1][i] += output[2][i];
1311 output[2][i] += output[3][i];
2aa2c5c4 1312 }
00585845 1313 memset(output[3], 0, sizeof(output[3]));
1b293437 1314}
2aa2c5c4 1315
00585845 1316static inline void mix_2f_1r_to_dolby(AC3DecodeContext *ctx)
1b293437
JR
1317{
1318 int i;
98a27a8a 1319 float (*output)[BLOCK_SIZE] = ctx->output;
2aa2c5c4 1320
1b293437 1321 for (i = 0; i < 256; i++) {
00585845
JR
1322 output[1][i] -= output[3][i];
1323 output[2][i] += output[3][i];
1b293437 1324 }
00585845 1325 memset(output[3], 0, sizeof(output[3]));
2aa2c5c4
JR
1326}
1327
00585845 1328static inline void mix_3f_1r_to_mono(AC3DecodeContext *ctx)
2aa2c5c4 1329{
1b293437 1330 int i;
98a27a8a 1331 float (*output)[BLOCK_SIZE] = ctx->output;
1b293437 1332
00585845
JR
1333 for (i = 0; i < 256; i++)
1334 output[1][i] = (output[2][i] + output[3][i] + output[4][i]);
1335 memset(output[2], 0, sizeof(output[2]));
1336 memset(output[3], 0, sizeof(output[3]));
1337 memset(output[4], 0, sizeof(output[4]));
1b293437
JR
1338}
1339
00585845 1340static inline void mix_3f_1r_to_stereo(AC3DecodeContext *ctx)
1b293437
JR
1341{
1342 int i;
98a27a8a 1343 float (*output)[BLOCK_SIZE] = ctx->output;
1b293437
JR
1344
1345 for (i = 0; i < 256; i++) {
00585845
JR
1346 output[1][i] += (output[2][i] + output[4][i]);
1347 output[2][i] += (output[3][i] + output[4][i]);
1b293437 1348 }
00585845
JR
1349 memset(output[3], 0, sizeof(output[3]));
1350 memset(output[4], 0, sizeof(output[4]));
1b293437
JR
1351}
1352
00585845 1353static inline void mix_3f_1r_to_dolby(AC3DecodeContext *ctx)
1b293437
JR
1354{
1355 int i;
98a27a8a 1356 float (*output)[BLOCK_SIZE] = ctx->output;
1b293437
JR
1357
1358 for (i = 0; i < 256; i++) {
00585845
JR
1359 output[1][i] += (output[2][i] - output[4][i]);
1360 output[2][i] += (output[3][i] + output[4][i]);
1b293437 1361 }
00585845
JR
1362 memset(output[3], 0, sizeof(output[3]));
1363 memset(output[4], 0, sizeof(output[4]));
1b293437
JR
1364}
1365
00585845 1366static inline void mix_2f_2r_to_mono(AC3DecodeContext *ctx)
1b293437
JR
1367{
1368 int i;
98a27a8a 1369 float (*output)[BLOCK_SIZE] = ctx->output;
1b293437 1370
00585845
JR
1371 for (i = 0; i < 256; i++)
1372 output[1][i] = (output[2][i] + output[3][i] + output[4][i]);
1373 memset(output[2], 0, sizeof(output[2]));
1374 memset(output[3], 0, sizeof(output[3]));
1375 memset(output[4], 0, sizeof(output[4]));
1b293437
JR
1376}
1377
00585845 1378static inline void mix_2f_2r_to_stereo(AC3DecodeContext *ctx)
1b293437
JR
1379{
1380 int i;
98a27a8a 1381 float (*output)[BLOCK_SIZE] = ctx->output;
1b293437
JR
1382
1383 for (i = 0; i < 256; i++) {
00585845
JR
1384 output[1][i] += output[3][i];
1385 output[2][i] += output[4][i];
1b293437 1386 }
00585845
JR
1387 memset(output[3], 0, sizeof(output[3]));
1388 memset(output[4], 0, sizeof(output[4]));
1b293437
JR
1389}
1390
00585845 1391static inline void mix_2f_2r_to_dolby(AC3DecodeContext *ctx)
1b293437
JR
1392{
1393 int i;
98a27a8a 1394 float (*output)[BLOCK_SIZE] = ctx->output;
1b293437
JR
1395
1396 for (i = 0; i < 256; i++) {
00585845
JR
1397 output[1][i] -= output[3][i];
1398 output[2][i] += output[4][i];
1b293437 1399 }
00585845
JR
1400 memset(output[3], 0, sizeof(output[3]));
1401 memset(output[4], 0, sizeof(output[4]));
1b293437
JR
1402}
1403
00585845 1404static inline void mix_3f_2r_to_mono(AC3DecodeContext *ctx)
1b293437
JR
1405{
1406 int i;
98a27a8a 1407 float (*output)[BLOCK_SIZE] = ctx->output;
1b293437 1408
00585845
JR
1409 for (i = 0; i < 256; i++)
1410 output[1][i] += (output[2][i] + output[3][i] + output[4][i] + output[5][i]);
1411 memset(output[2], 0, sizeof(output[2]));
1412 memset(output[3], 0, sizeof(output[3]));
1413 memset(output[4], 0, sizeof(output[4]));
1414 memset(output[5], 0, sizeof(output[5]));
1b293437
JR
1415}
1416
00585845 1417static inline void mix_3f_2r_to_stereo(AC3DecodeContext *ctx)
1b293437
JR
1418{
1419 int i;
98a27a8a 1420 float (*output)[BLOCK_SIZE] = ctx->output;
1b293437
JR
1421
1422 for (i = 0; i < 256; i++) {
00585845
JR
1423 output[1][i] += (output[2][i] + output[4][i]);
1424 output[2][i] += (output[3][i] + output[5][i]);
1b293437 1425 }
00585845
JR
1426 memset(output[3], 0, sizeof(output[3]));
1427 memset(output[4], 0, sizeof(output[4]));
1428 memset(output[5], 0, sizeof(output[5]));
1b293437
JR
1429}
1430
00585845 1431static inline void mix_3f_2r_to_dolby(AC3DecodeContext *ctx)
1b293437
JR
1432{
1433 int i;
98a27a8a 1434 float (*output)[BLOCK_SIZE] = ctx->output;
2aa2c5c4 1435
1b293437 1436 for (i = 0; i < 256; i++) {
00585845
JR
1437 output[1][i] += (output[2][i] - output[4][i] - output[5][i]);
1438 output[2][i] += (output[3][i] + output[4][i] + output[5][i]);
1b293437 1439 }
00585845
JR
1440 memset(output[3], 0, sizeof(output[3]));
1441 memset(output[4], 0, sizeof(output[4]));
1442 memset(output[5], 0, sizeof(output[5]));
1b293437 1443}
c7cfc48f 1444/*********** END DOWNMIX FUNCTIONS ***********/
1b293437 1445
c7cfc48f
JR
1446/* Downmix the output.
1447 * This function downmixes the output when the number of input
1448 * channels is not equal to the number of output channels requested.
1449 */
1b293437
JR
1450static void do_downmix(AC3DecodeContext *ctx)
1451{
98a27a8a
JR
1452 int from = ctx->acmod;
1453 int to = ctx->blkoutput;
1b293437 1454
c7cfc48f
JR
1455 if (to == AC3_OUTPUT_UNMODIFIED)
1456 return;
1457
1b293437 1458 switch (from) {
cc2a8443 1459 case AC3_ACMOD_DUALMONO:
1b293437
JR
1460 switch (to) {
1461 case AC3_OUTPUT_MONO:
00585845 1462 mix_dualmono_to_mono(ctx);
1b293437 1463 break;
486637af 1464 case AC3_OUTPUT_STEREO: /* We assume that sum of both mono channels is requested */
00585845 1465 mix_dualmono_to_stereo(ctx);
1b293437
JR
1466 break;
1467 }
1468 break;
cc2a8443 1469 case AC3_ACMOD_MONO:
1b293437
JR
1470 switch (to) {
1471 case AC3_OUTPUT_STEREO:
00585845 1472 upmix_mono_to_stereo(ctx);
1b293437
JR
1473 break;
1474 }
1475 break;
cc2a8443 1476 case AC3_ACMOD_STEREO:
1b293437
JR
1477 switch (to) {
1478 case AC3_OUTPUT_MONO:
00585845 1479 mix_stereo_to_mono(ctx);
1b293437
JR
1480 break;
1481 }
1482 break;
cc2a8443 1483 case AC3_ACMOD_3F:
1b293437
JR
1484 switch (to) {
1485 case AC3_OUTPUT_MONO:
00585845 1486 mix_3f_to_mono(ctx);
1b293437
JR
1487 break;
1488 case AC3_OUTPUT_STEREO:
00585845 1489 mix_3f_to_stereo(ctx);
1b293437
JR
1490 break;
1491 }
1492 break;
cc2a8443 1493 case AC3_ACMOD_2F1R:
1b293437
JR
1494 switch (to) {
1495 case AC3_OUTPUT_MONO:
00585845 1496 mix_2f_1r_to_mono(ctx);
1b293437
JR
1497 break;
1498 case AC3_OUTPUT_STEREO:
00585845 1499 mix_2f_1r_to_stereo(ctx);
1b293437
JR
1500 break;
1501 case AC3_OUTPUT_DOLBY:
00585845 1502 mix_2f_1r_to_dolby(ctx);
1b293437
JR
1503 break;
1504 }
1505 break;
cc2a8443 1506 case AC3_ACMOD_3F1R:
1b293437
JR
1507 switch (to) {
1508 case AC3_OUTPUT_MONO:
00585845 1509 mix_3f_1r_to_mono(ctx);
1b293437
JR
1510 break;
1511 case AC3_OUTPUT_STEREO:
00585845 1512 mix_3f_1r_to_stereo(ctx);
1b293437
JR
1513 break;
1514 case AC3_OUTPUT_DOLBY:
00585845 1515 mix_3f_1r_to_dolby(ctx);
1b293437
JR
1516 break;
1517 }
1518 break;
cc2a8443 1519 case AC3_ACMOD_2F2R:
1b293437
JR
1520 switch (to) {
1521 case AC3_OUTPUT_MONO:
00585845 1522 mix_2f_2r_to_mono(ctx);
1b293437
JR
1523 break;
1524 case AC3_OUTPUT_STEREO:
00585845 1525 mix_2f_2r_to_stereo(ctx);
1b293437
JR
1526 break;
1527 case AC3_OUTPUT_DOLBY:
00585845 1528 mix_2f_2r_to_dolby(ctx);
1b293437
JR
1529 break;
1530 }
1531 break;
cc2a8443 1532 case AC3_ACMOD_3F2R:
1b293437
JR
1533 switch (to) {
1534 case AC3_OUTPUT_MONO:
00585845 1535 mix_3f_2r_to_mono(ctx);
1b293437
JR
1536 break;
1537 case AC3_OUTPUT_STEREO:
00585845 1538 mix_3f_2r_to_stereo(ctx);
1b293437
JR
1539 break;
1540 case AC3_OUTPUT_DOLBY:
00585845 1541 mix_3f_2r_to_dolby(ctx);
1b293437
JR
1542 break;
1543 }
1544 break;
1545 }
2aa2c5c4
JR
1546}
1547
c7cfc48f
JR
1548/* This function performs the imdct on 256 sample transform
1549 * coefficients.
1550 */
45b0ed13 1551static void do_imdct_256(AC3DecodeContext *ctx, int chindex)
486637af 1552{
45b0ed13 1553 int k;
98a27a8a 1554 float x1[128], x2[128];
1ea76064
JR
1555 float *o_ptr, *d_ptr, *w;
1556 FFTComplex *ptr1, *ptr2;
98a27a8a 1557
45b0ed13
JR
1558 for (k = 0; k < N / 4; k++) {
1559 x1[k] = ctx->transform_coeffs[chindex][2 * k];
1560 x2[k] = ctx->transform_coeffs[chindex][2 * k + 1];
98a27a8a
JR
1561 }
1562
afb46fc0
LM
1563 ctx->imdct_256.fft.imdct_calc(&ctx->imdct_256, ctx->tmp_output, x1, ctx->tmp_imdct);
1564 ctx->imdct_256.fft.imdct_calc(&ctx->imdct_256, ctx->tmp_output + 256, x2, ctx->tmp_imdct);
486637af 1565
1ea76064
JR
1566 o_ptr = ctx->output[chindex];
1567 d_ptr = ctx->delay[chindex];
1568 ptr1 = (FFTComplex *)ctx->tmp_output;
1569 ptr2 = (FFTComplex *)ctx->tmp_output + 256;
1570 w = ctx->window;
1571
1572 for (k = 0; k < N / 8; k++)
1573 {
1574 o_ptr[2 * k] = -ptr1[k].im * w[2 * k] + d_ptr[2 * k] + 384.0;
1575 o_ptr[2 * k + 1] = ptr1[N / 8 - k - 1].re * w[2 * k + 1] + 384.0;
1576 o_ptr[N / 4 + 2 * k] = -ptr1[k].re * w[N / 4 + 2 * k] + d_ptr[N / 4 + 2 * k] + 384.0;
1577 o_ptr[N / 4 + 2 * k + 1] = ptr1[N / 8 - k - 1].im * w[N / 4 + 2 * k + 1] + d_ptr[N / 4 + 2 * k + 1] + 384.0;
1578 d_ptr[2 * k] = ptr2[k].re * w[k / 2 - 2 * k - 1];
1579 d_ptr[2 * k + 1] = -ptr2[N / 8 - k - 1].im * w[N / 2 - 2 * k - 2];
1580 d_ptr[N / 4 + 2 * k] = ptr2[k].im * w[N / 4 - 2 * k - 1];
1581 d_ptr[N / 4 + 2 * k + 1] = -ptr2[N / 8 - k - 1].re * w[N / 4 - 2 * k - 2];
1582 }
486637af
JR
1583}
1584
c7cfc48f
JR
1585/* This function performs the imdct on 512 sample transform
1586 * coefficients.
1587 */
45b0ed13 1588static void do_imdct_512(AC3DecodeContext *ctx, int chindex)
98a27a8a 1589{
1d0a6f52 1590 float *ptr;
98a27a8a 1591
afb46fc0
LM
1592 ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output,
1593 ctx->transform_coeffs[chindex], ctx->tmp_imdct);
1d0a6f52 1594 ptr = ctx->output[chindex];
6dc5d71f 1595 ctx->dsp.vector_fmul_add_add(ptr, ctx->tmp_output, ctx->window, ctx->delay[chindex], 384, BLOCK_SIZE, 1);
1d0a6f52 1596 ptr = ctx->delay[chindex];
6dc5d71f 1597 ctx->dsp.vector_fmul_reverse(ptr, ctx->tmp_output + 256, ctx->window, BLOCK_SIZE);
98a27a8a 1598}
486637af 1599
c7cfc48f 1600/* IMDCT Transform. */
486637af
JR
1601static inline void do_imdct(AC3DecodeContext *ctx)
1602{
486637af
JR
1603 int i;
1604
98a27a8a 1605 if (ctx->blkoutput & AC3_OUTPUT_LFEON) {
45b0ed13 1606 do_imdct_512(ctx, 0);
486637af 1607 }
2fbbd087 1608 for (i = 0; i < ctx->nfchans; i++) {
45b0ed13
JR
1609 if ((ctx->blksw >> i) & 1)
1610 do_imdct_256(ctx, i + 1);
1611 else
1612 do_imdct_512(ctx, i + 1);
486637af
JR
1613 }
1614}
1615
c7cfc48f
JR
1616/* Parse the audio block from ac3 bitstream.
1617 * This function extract the audio block from the ac3 bitstream
1618 * and produces the output for the block. This function must
1619 * be called for each of the six audio block in the ac3 bitstream.
1620 */
98a27a8a 1621static int ac3_parse_audio_block(AC3DecodeContext * ctx)
2aa2c5c4 1622{
98a27a8a
JR
1623 int nfchans = ctx->nfchans;
1624 int acmod = ctx->acmod;
00585845 1625 int i, bnd, rbnd, seg, grpsize;
1b293437 1626 GetBitContext *gb = &ctx->gb;
1b293437 1627 int bit_alloc_flags = 0;
00585845 1628 uint8_t *dexps;
2fbbd087 1629 int mstrcplco, cplcoexp, cplcomant;
98a27a8a 1630 int dynrng, chbwcod, ngrps, cplabsexp, skipl;
1b293437 1631
67414da7 1632 ctx->blksw = 0;
1b293437 1633 for (i = 0; i < nfchans; i++) /*block switch flag */
98a27a8a
JR
1634 ctx->blksw |= get_bits1(gb) << i;
1635
67414da7 1636 ctx->dithflag = 0;
1b293437 1637 for (i = 0; i < nfchans; i++) /* dithering flag */
98a27a8a
JR
1638 ctx->dithflag |= get_bits1(gb) << i;
1639
00585845 1640 if (get_bits1(gb)) { /* dynamic range */
45b0ed13 1641 dynrng = get_sbits(gb, 8);
6dc5d71f 1642 ctx->dynrng = ((((dynrng & 0x1f) | 0x20) << 13) * scale_factors[3 - (dynrng >> 5)]);
1b293437 1643 }
98a27a8a
JR
1644
1645 if (acmod == 0x00 && get_bits1(gb)) { /* dynamic range 1+1 mode */
45b0ed13 1646 dynrng = get_sbits(gb, 8);
6dc5d71f 1647 ctx->dynrng2 = ((((dynrng & 0x1f) | 0x20) << 13) * scale_factors[3 - (dynrng >> 5)]);
98a27a8a
JR
1648 }
1649
1b293437 1650 get_downmix_coeffs(ctx);
98a27a8a 1651
00585845 1652 if (get_bits1(gb)) { /* coupling strategy */
98a27a8a 1653 ctx->cplinu = get_bits1(gb);
2fbbd087
JR
1654 ctx->cplbndstrc = 0;
1655 ctx->chincpl = 0;
98a27a8a 1656 if (ctx->cplinu) { /* coupling in use */
1b293437 1657 for (i = 0; i < nfchans; i++)
98a27a8a
JR
1658 ctx->chincpl |= get_bits1(gb) << i;
1659
1b293437 1660 if (acmod == 0x02)
98a27a8a
JR
1661 ctx->phsflginu = get_bits1(gb); //phase flag in use
1662
1663 ctx->cplbegf = get_bits(gb, 4);
1664 ctx->cplendf = get_bits(gb, 4);
1665
1666 if (3 + ctx->cplendf - ctx->cplbegf < 0) {
1667 av_log(NULL, AV_LOG_ERROR, "cplendf = %d < cplbegf = %d\n", ctx->cplendf, ctx->cplbegf);
00585845 1668 return -1;
98a27a8a
JR
1669 }
1670
1671 ctx->ncplbnd = ctx->ncplsubnd = 3 + ctx->cplendf - ctx->cplbegf;
1672 ctx->cplstrtmant = ctx->cplbegf * 12 + 37;
1673 ctx->cplendmant = ctx->cplendf * 12 + 73;
98a27a8a 1674 for (i = 0; i < ctx->ncplsubnd - 1; i++) /* coupling band structure */
00585845 1675 if (get_bits1(gb)) {
98a27a8a
JR
1676 ctx->cplbndstrc |= 1 << i;
1677 ctx->ncplbnd--;
1b293437
JR
1678 }
1679 }
1680 }
98a27a8a
JR
1681
1682 if (ctx->cplinu) {
1683 ctx->cplcoe = 0;
1684
1b293437 1685 for (i = 0; i < nfchans; i++)
98a27a8a 1686 if ((ctx->chincpl) >> i & 1)
00585845 1687 if (get_bits1(gb)) { /* coupling co-ordinates */
2fbbd087 1688 ctx->cplcoe |= 1 << i;
486637af 1689 mstrcplco = 3 * get_bits(gb, 2);
98a27a8a 1690 for (bnd = 0; bnd < ctx->ncplbnd; bnd++) {
486637af
JR
1691 cplcoexp = get_bits(gb, 4);
1692 cplcomant = get_bits(gb, 4);
1693 if (cplcoexp == 15)
1694 cplcomant <<= 14;
1695 else
1696 cplcomant = (cplcomant | 0x10) << 13;
98a27a8a 1697 ctx->cplco[i][bnd] = cplcomant * scale_factors[cplcoexp + mstrcplco];
486637af 1698 }
486637af 1699 }
98a27a8a 1700
2fbbd087 1701 if (acmod == 0x02 && ctx->phsflginu && (ctx->cplcoe & 1 || ctx->cplcoe & 2))
98a27a8a
JR
1702 for (bnd = 0; bnd < ctx->ncplbnd; bnd++)
1703 if (get_bits1(gb))
1704 ctx->cplco[1][bnd] = -ctx->cplco[1][bnd];
2aa2c5c4 1705 }
98a27a8a
JR
1706
1707 if (acmod == 0x02) {/* rematrixing */
1708 ctx->rematstr = get_bits1(gb);
1709 if (ctx->rematstr) {
1710 ctx->rematflg = 0;
1711
1712 if (!(ctx->cplinu) || ctx->cplbegf > 2)
1b293437 1713 for (rbnd = 0; rbnd < 4; rbnd++)
98a27a8a
JR
1714 ctx->rematflg |= get_bits1(gb) << rbnd;
1715 if (ctx->cplbegf > 0 && ctx->cplbegf <= 2 && ctx->cplinu)
1b293437 1716 for (rbnd = 0; rbnd < 3; rbnd++)
98a27a8a
JR
1717 ctx->rematflg |= get_bits1(gb) << rbnd;
1718 if (ctx->cplbegf == 0 && ctx->cplinu)
1b293437 1719 for (rbnd = 0; rbnd < 2; rbnd++)
98a27a8a 1720 ctx->rematflg |= get_bits1(gb) << rbnd;
1b293437 1721 }
98a27a8a
JR
1722 }
1723
cc2a8443
JR
1724 ctx->cplexpstr = EXP_REUSE;
1725 ctx->lfeexpstr = EXP_REUSE;
98a27a8a
JR
1726 if (ctx->cplinu) /* coupling exponent strategy */
1727 ctx->cplexpstr = get_bits(gb, 2);
1728 for (i = 0; i < nfchans; i++) /* channel exponent strategy */
1729 ctx->chexpstr[i] = get_bits(gb, 2);
1730 if (ctx->lfeon) /* lfe exponent strategy */
1731 ctx->lfeexpstr = get_bits1(gb);
1732
1b293437 1733 for (i = 0; i < nfchans; i++) /* channel bandwidth code */
cc2a8443 1734 if (ctx->chexpstr[i] != EXP_REUSE) {
98a27a8a
JR
1735 if ((ctx->chincpl >> i) & 1)
1736 ctx->endmant[i] = ctx->cplstrtmant;
00585845 1737 else {
98a27a8a
JR
1738 chbwcod = get_bits(gb, 6);
1739 if (chbwcod > 60) {
1740 av_log(NULL, AV_LOG_ERROR, "chbwcod = %d > 60", chbwcod);
00585845
JR
1741 return -1;
1742 }
98a27a8a 1743 ctx->endmant[i] = chbwcod * 3 + 73;
1b293437 1744 }
00585845 1745 }
98a27a8a 1746
cc2a8443 1747 if (ctx->cplexpstr != EXP_REUSE) {/* coupling exponents */
2fbbd087 1748 bit_alloc_flags = 64;
98a27a8a
JR
1749 cplabsexp = get_bits(gb, 4) << 1;
1750 ngrps = (ctx->cplendmant - ctx->cplstrtmant) / (3 << (ctx->cplexpstr - 1));
1751 if (decode_exponents(gb, ctx->cplexpstr, ngrps, cplabsexp, ctx->dcplexps + ctx->cplstrtmant)) {
486637af
JR
1752 av_log(NULL, AV_LOG_ERROR, "error decoding coupling exponents\n");
1753 return -1;
1b293437 1754 }
486637af 1755 }
98a27a8a 1756
1b293437 1757 for (i = 0; i < nfchans; i++) /* fbw channel exponents */
cc2a8443 1758 if (ctx->chexpstr[i] != EXP_REUSE) {
1b293437 1759 bit_alloc_flags |= 1 << i;
98a27a8a
JR
1760 grpsize = 3 << (ctx->chexpstr[i] - 1);
1761 ngrps = (ctx->endmant[i] + grpsize - 4) / grpsize;
1762 dexps = ctx->dexps[i];
00585845 1763 dexps[0] = get_bits(gb, 4);
98a27a8a 1764 if (decode_exponents(gb, ctx->chexpstr[i], ngrps, dexps[0], dexps + 1)) {
00585845
JR
1765 av_log(NULL, AV_LOG_ERROR, "error decoding channel %d exponents\n", i);
1766 return -1;
1767 }
98a27a8a 1768 skip_bits(gb, 2); /* skip gainrng */
1b293437 1769 }
98a27a8a 1770
cc2a8443 1771 if (ctx->lfeexpstr != EXP_REUSE) { /* lfe exponents */
486637af 1772 bit_alloc_flags |= 32;
98a27a8a
JR
1773 ctx->dlfeexps[0] = get_bits(gb, 4);
1774 if (decode_exponents(gb, ctx->lfeexpstr, 2, ctx->dlfeexps[0], ctx->dlfeexps + 1)) {
486637af
JR
1775 av_log(NULL, AV_LOG_ERROR, "error decoding lfe exponents\n");
1776 return -1;
1b293437 1777 }
486637af 1778 }
1b293437 1779
00585845 1780 if (get_bits1(gb)) { /* bit allocation information */
2fbbd087 1781 bit_alloc_flags = 127;
98a27a8a
JR
1782 ctx->sdcycod = get_bits(gb, 2);
1783 ctx->fdcycod = get_bits(gb, 2);
1784 ctx->sgaincod = get_bits(gb, 2);
1785 ctx->dbpbcod = get_bits(gb, 2);
1786 ctx->floorcod = get_bits(gb, 3);
1b293437 1787 }
98a27a8a 1788
00585845 1789 if (get_bits1(gb)) { /* snroffset */
2fbbd087 1790 bit_alloc_flags = 127;
98a27a8a 1791 ctx->csnroffst = get_bits(gb, 6);
de17eee7 1792 if (ctx->cplinu) { /* coupling fine snr offset and fast gain code */
98a27a8a
JR
1793 ctx->cplfsnroffst = get_bits(gb, 4);
1794 ctx->cplfgaincod = get_bits(gb, 3);
1b293437
JR
1795 }
1796 for (i = 0; i < nfchans; i++) { /* channel fine snr offset and fast gain code */
98a27a8a
JR
1797 ctx->fsnroffst[i] = get_bits(gb, 4);
1798 ctx->fgaincod[i] = get_bits(gb, 3);
1b293437 1799 }
98a27a8a
JR
1800 if (ctx->lfeon) { /* lfe fine snr offset and fast gain code */
1801 ctx->lfefsnroffst = get_bits(gb, 4);
1802 ctx->lfefgaincod = get_bits(gb, 3);
1b293437
JR
1803 }
1804 }
98a27a8a 1805
98a27a8a
JR
1806 if (ctx->cplinu && get_bits1(gb)) { /* coupling leak information */
1807 bit_alloc_flags |= 64;
1808 ctx->cplfleak = get_bits(gb, 3);
1809 ctx->cplsleak = get_bits(gb, 3);
1810 }
1811
00585845 1812 if (get_bits1(gb)) { /* delta bit allocation information */
2fbbd087 1813 bit_alloc_flags = 127;
98a27a8a
JR
1814
1815 if (ctx->cplinu) {
1816 ctx->cpldeltbae = get_bits(gb, 2);
cc2a8443 1817 if (ctx->cpldeltbae == DBA_RESERVED) {
1b293437
JR
1818 av_log(NULL, AV_LOG_ERROR, "coupling delta bit allocation strategy reserved\n");
1819 return -1;
1820 }
1821 }
98a27a8a 1822
1b293437 1823 for (i = 0; i < nfchans; i++) {
98a27a8a 1824 ctx->deltbae[i] = get_bits(gb, 2);
cc2a8443 1825 if (ctx->deltbae[i] == DBA_RESERVED) {
1b293437
JR
1826 av_log(NULL, AV_LOG_ERROR, "delta bit allocation strategy reserved\n");
1827 return -1;
1828 }
1829 }
98a27a8a
JR
1830
1831 if (ctx->cplinu)
cc2a8443 1832 if (ctx->cpldeltbae == DBA_NEW) { /*coupling delta offset, len and bit allocation */
98a27a8a
JR
1833 ctx->cpldeltnseg = get_bits(gb, 3);
1834 for (seg = 0; seg <= ctx->cpldeltnseg; seg++) {
1835 ctx->cpldeltoffst[seg] = get_bits(gb, 5);
1836 ctx->cpldeltlen[seg] = get_bits(gb, 4);
1837 ctx->cpldeltba[seg] = get_bits(gb, 3);
1b293437
JR
1838 }
1839 }
98a27a8a 1840
1b293437 1841 for (i = 0; i < nfchans; i++)
cc2a8443 1842 if (ctx->deltbae[i] == DBA_NEW) {/*channel delta offset, len and bit allocation */
98a27a8a
JR
1843 ctx->deltnseg[i] = get_bits(gb, 3);
1844 for (seg = 0; seg <= ctx->deltnseg[i]; seg++) {
1845 ctx->deltoffst[i][seg] = get_bits(gb, 5);
1846 ctx->deltlen[i][seg] = get_bits(gb, 4);
1847 ctx->deltba[i][seg] = get_bits(gb, 3);
1b293437
JR
1848 }
1849 }
1850 }
00585845 1851
2fbbd087
JR
1852 if (bit_alloc_flags) {
1853 if (is_snr_offsets_zero(ctx)) {
1854 memset(ctx->cplbap, 0, sizeof (ctx->cplbap));
1855 memset(ctx->lfebap, 0, sizeof (ctx->lfebap));
1856 for (i = 0; i < nfchans; i++)
1857 memset(ctx->bap[i], 0, sizeof(ctx->bap[i]));
1858 } else {
1859 if (ctx->chincpl && (bit_alloc_flags & 64))
1860 do_bit_allocation(ctx, 5);
1861 for (i = 0; i < nfchans; i++)
1862 if ((bit_alloc_flags >> i) & 1)
1863 do_bit_allocation(ctx, i);
1864 if (ctx->lfeon && (bit_alloc_flags & 32))
1865 do_bit_allocation(ctx, 6);
1866 }
1867 }
98a27a8a 1868
00585845 1869 if (get_bits1(gb)) { /* unused dummy data */
98a27a8a
JR
1870 skipl = get_bits(gb, 9);
1871 while(skipl--)
00585845 1872 skip_bits(gb, 8);
1b293437
JR
1873 }
1874 /* unpack the transform coefficients
1875 * * this also uncouples channels if coupling is in use.
1876 */
1877 if (get_transform_coeffs(ctx)) {
1878 av_log(NULL, AV_LOG_ERROR, "Error in routine get_transform_coeffs\n");
1879 return -1;
1880 }
486637af 1881
1b293437 1882 /* recover coefficients if rematrixing is in use */
67414da7 1883 if (ctx->rematflg)
1b293437
JR
1884 do_rematrixing(ctx);
1885
d7bcc4ad
JR
1886 do_downmix(ctx);
1887
486637af 1888 do_imdct(ctx);
486637af 1889
1b293437
JR
1890 return 0;
1891}
1892
d7bcc4ad
JR
1893static inline int16_t convert(int32_t i)
1894{
1895 if (i > 0x43c07fff)
1896 return 32767;
1897 else if (i <= 0x43bf8000)
1898 return -32768;
1899 else
1900 return (i - 0x43c00000);
486637af
JR
1901}
1902
c7cfc48f
JR
1903/* Decode ac3 frame.
1904 *
1905 * @param avctx Pointer to AVCodecContext
1906 * @param data Pointer to pcm smaples
1907 * @param data_size Set to number of pcm samples produced by decoding
1908 * @param buf Data to be decoded
1909 * @param buf_size Size of the buffer
1910 */
00585845 1911static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
1b293437 1912{
00585845 1913 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data;
1b293437 1914 int frame_start;
00585845 1915 int16_t *out_samples = (int16_t *)data;
d7bcc4ad
JR
1916 int i, j, k, start;
1917 int32_t *int_ptr[6];
1b293437 1918
d7bcc4ad
JR
1919 for (i = 0; i < 6; i++)
1920 int_ptr[i] = (int32_t *)(&ctx->output[i]);
1921
1b293437
JR
1922 //Synchronize the frame.
1923 frame_start = ac3_synchronize(buf, buf_size);
1924 if (frame_start == -1) {
1925 av_log(avctx, AV_LOG_ERROR, "frame is not synchronized\n");
1926 *data_size = 0;
00585845 1927 return buf_size;
1b293437 1928 }
2aa2c5c4 1929
1b293437
JR
1930 //Initialize the GetBitContext with the start of valid AC3 Frame.
1931 init_get_bits(&(ctx->gb), buf + frame_start, (buf_size - frame_start) * 8);
00585845 1932
1b293437 1933 //Parse the syncinfo.
00585845
JR
1934 //If 'fscod' or 'bsid' is not valid the decoder shall mute as per the standard.
1935 if (!ac3_parse_sync_info(ctx)) {
1936 av_log(avctx, AV_LOG_ERROR, "\n");
1b293437 1937 *data_size = 0;
486637af 1938 return buf_size;
1b293437 1939 }
2aa2c5c4 1940
1b293437
JR
1941 //Parse the BSI.
1942 //If 'bsid' is not valid decoder shall not decode the audio as per the standard.
486637af 1943 ac3_parse_bsi(ctx);
2aa2c5c4 1944
98a27a8a
JR
1945 avctx->sample_rate = ctx->sampling_rate;
1946 avctx->bit_rate = ctx->bit_rate;
45b0ed13 1947
1b293437 1948 if (avctx->channels == 0) {
98a27a8a 1949 ctx->blkoutput |= AC3_OUTPUT_UNMODIFIED;
45b0ed13
JR
1950 if (ctx->lfeon)
1951 ctx->blkoutput |= AC3_OUTPUT_LFEON;
1952 avctx->channels = ctx->nfchans + ctx->lfeon;
1953 }
1954 else if (avctx->channels == 1)
98a27a8a 1955 ctx->blkoutput |= AC3_OUTPUT_MONO;
45b0ed13 1956 else if (avctx->channels == 2) {
98a27a8a
JR
1957 if (ctx->dsurmod == 0x02)
1958 ctx->blkoutput |= AC3_OUTPUT_DOLBY;
1b293437 1959 else
98a27a8a 1960 ctx->blkoutput |= AC3_OUTPUT_STEREO;
486637af 1961 }
45b0ed13
JR
1962 else {
1963 if (avctx->channels < (ctx->nfchans + ctx->lfeon))
1964 av_log(avctx, AV_LOG_INFO, "ac3_decoder: AC3 Source Channels Are Less Then Specified %d: Output to %d Channels\n",avctx->channels, ctx->nfchans + ctx->lfeon);
1965 ctx->blkoutput |= AC3_OUTPUT_UNMODIFIED;
1966 if (ctx->lfeon)
1967 ctx->blkoutput |= AC3_OUTPUT_LFEON;
1968 avctx->channels = ctx->nfchans + ctx->lfeon;
1b293437
JR
1969 }
1970
d7bcc4ad 1971 //av_log(avctx, AV_LOG_INFO, "channels = %d \t bit rate = %d \t sampling rate = %d \n", avctx->channels, avctx->bit_rate * 1000, avctx->sample_rate);
1b293437
JR
1972
1973 //Parse the Audio Blocks.
cc2a8443 1974 for (i = 0; i < NB_BLOCKS; i++) {
98a27a8a 1975 if (ac3_parse_audio_block(ctx)) {
1b293437
JR
1976 av_log(avctx, AV_LOG_ERROR, "error parsing the audio block\n");
1977 *data_size = 0;
98a27a8a 1978 return ctx->frame_size;
1b293437 1979 }
d7bcc4ad
JR
1980 start = (ctx->blkoutput & AC3_OUTPUT_LFEON) ? 0 : 1;
1981 for (k = 0; k < BLOCK_SIZE; k++)
1982 for (j = start; j <= avctx->channels; j++)
1983 *(out_samples++) = convert(int_ptr[j][k]);
1b293437 1984 }
cc2a8443 1985 *data_size = NB_BLOCKS * BLOCK_SIZE * avctx->channels * sizeof (int16_t);
98a27a8a 1986 return ctx->frame_size;
2aa2c5c4 1987}
1b293437 1988
c7cfc48f
JR
1989/* Uninitialize ac3 decoder.
1990 */
1991static int ac3_decode_end(AVCodecContext *avctx)
1b293437 1992{
c7cfc48f
JR
1993 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data;
1994 ff_mdct_end(&ctx->imdct_512);
1995 ff_mdct_end(&ctx->imdct_256);
1996
1b293437
JR
1997 return 0;
1998}
1999
2000AVCodec lgpl_ac3_decoder = {
e6bca37c
JR
2001 .name = "ac3",
2002 .type = CODEC_TYPE_AUDIO,
2003 .id = CODEC_ID_AC3,
2004 .priv_data_size = sizeof (AC3DecodeContext),
2005 .init = ac3_decode_init,
2006 .close = ac3_decode_end,
2007 .decode = ac3_decode_frame,
1b293437
JR
2008};
2009