annotate ac3dec.c @ 5386:d6347c3cb329 libavcodec

Use shared AC-3 header parsing. Move some initializations to block parsing function.
author jbr
date Sat, 21 Jul 2007 16:28:12 +0000
parents bc14cca988aa
children 1194da3349cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5328
5f83f09bd748 revise license header for simplicity and consistency
jbr
parents: 5326
diff changeset
1 /*
5f83f09bd748 revise license header for simplicity and consistency
jbr
parents: 5326
diff changeset
2 * AC-3 Audio Decoder
5316
a09b700fcfca AC-3 decoder, soc revision 56, Aug 17 14:21:58 2006 UTC by cloud9
jbr
parents: 5315
diff changeset
3 * This code is developed as part of Google Summer of Code 2006 Program.
a09b700fcfca AC-3 decoder, soc revision 56, Aug 17 14:21:58 2006 UTC by cloud9
jbr
parents: 5315
diff changeset
4 *
5328
5f83f09bd748 revise license header for simplicity and consistency
jbr
parents: 5326
diff changeset
5 * Copyright (c) 2006 Kartikey Mahendra BHATT (bhattkm at gmail dot com).
5377
2020fab0e37a update license header. add copyright for myself. correct and complete the statement about liba52.
jbr
parents: 5376
diff changeset
6 * Copyright (c) 2007 Justin Ruggles
5316
a09b700fcfca AC-3 decoder, soc revision 56, Aug 17 14:21:58 2006 UTC by cloud9
jbr
parents: 5315
diff changeset
7 *
5377
2020fab0e37a update license header. add copyright for myself. correct and complete the statement about liba52.
jbr
parents: 5376
diff changeset
8 * Portions of this code are derived from liba52
5316
a09b700fcfca AC-3 decoder, soc revision 56, Aug 17 14:21:58 2006 UTC by cloud9
jbr
parents: 5315
diff changeset
9 * http://liba52.sourceforge.net
5377
2020fab0e37a update license header. add copyright for myself. correct and complete the statement about liba52.
jbr
parents: 5376
diff changeset
10 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
2020fab0e37a update license header. add copyright for myself. correct and complete the statement about liba52.
jbr
parents: 5376
diff changeset
11 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5316
a09b700fcfca AC-3 decoder, soc revision 56, Aug 17 14:21:58 2006 UTC by cloud9
jbr
parents: 5315
diff changeset
12 *
5328
5f83f09bd748 revise license header for simplicity and consistency
jbr
parents: 5326
diff changeset
13 * This file is part of FFmpeg.
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
14 *
5328
5f83f09bd748 revise license header for simplicity and consistency
jbr
parents: 5326
diff changeset
15 * FFmpeg is free software; you can redistribute it and/or
5329
06e7dda51f65 10l to me. I accidentally removed a word.
jbr
parents: 5328
diff changeset
16 * modify it under the terms of the GNU General Public
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
17 * License as published by the Free Software Foundation; either
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
18 * version 2 of the License, or (at your option) any later version.
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
19 *
5328
5f83f09bd748 revise license header for simplicity and consistency
jbr
parents: 5326
diff changeset
20 * FFmpeg is distributed in the hope that it will be useful,
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5326
923aacd40ee8 make ac3dec.c GPL until violations are fixed
jbr
parents: 5325
diff changeset
23 * General Public License for more details.
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
24 *
5326
923aacd40ee8 make ac3dec.c GPL until violations are fixed
jbr
parents: 5325
diff changeset
25 * You should have received a copy of the GNU General Public
5328
5f83f09bd748 revise license header for simplicity and consistency
jbr
parents: 5326
diff changeset
26 * License along with FFmpeg; if not, write to the Free Software
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
28 */
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
29
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
30 #include <stdio.h>
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
31 #include <stddef.h>
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
32 #include <math.h>
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
33 #include <string.h>
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
34
5315
31033309ebc9 AC-3 decoder, soc revision 55, Aug 17 12:25:24 2006 UTC by cloud9
jbr
parents: 5314
diff changeset
35 #include "avcodec.h"
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
36 #include "ac3_parser.h"
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
37 #include "bitstream.h"
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
38 #include "dsputil.h"
5330
37de2d864f03 use random number generator from libavutil
jbr
parents: 5329
diff changeset
39 #include "random.h"
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
40
5325
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
41 static const int nfchans_tbl[8] = { 2, 1, 2, 3, 3, 4, 4, 5 };
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
42
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
43 /* table for exponent to scale_factor mapping
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
44 * scale_factor[i] = 2 ^ -(i + 15)
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
45 */
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
46 static float scale_factors[25];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
47
5375
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
48 /** table for grouping exponents */
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
49 static uint8_t exp_ungroup_tbl[128][3];
5325
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
50
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
51 static int16_t l3_quantizers_1[32];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
52 static int16_t l3_quantizers_2[32];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
53 static int16_t l3_quantizers_3[32];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
54
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
55 static int16_t l5_quantizers_1[128];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
56 static int16_t l5_quantizers_2[128];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
57 static int16_t l5_quantizers_3[128];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
58
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
59 static int16_t l7_quantizers[7];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
60
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
61 static int16_t l11_quantizers_1[128];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
62 static int16_t l11_quantizers_2[128];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
63
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
64 static int16_t l15_quantizers[15];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
65
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
66 static const uint8_t qntztab[16] = { 0, 5, 7, 3, 7, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16 };
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
67
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
68 /* Adjustmens in dB gain */
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
69 #define LEVEL_MINUS_3DB 0.7071067811865476
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
70 #define LEVEL_MINUS_4POINT5DB 0.5946035575013605
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
71 #define LEVEL_MINUS_6DB 0.5000000000000000
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
72 #define LEVEL_PLUS_3DB 1.4142135623730951
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
73 #define LEVEL_PLUS_6DB 2.0000000000000000
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
74 #define LEVEL_ZERO 0.0000000000000000
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
75
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
76 static const float clevs[4] = { LEVEL_MINUS_3DB, LEVEL_MINUS_4POINT5DB,
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
77 LEVEL_MINUS_6DB, LEVEL_MINUS_4POINT5DB };
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
78
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
79 static const float slevs[4] = { LEVEL_MINUS_3DB, LEVEL_MINUS_6DB, LEVEL_ZERO, LEVEL_MINUS_6DB };
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
80
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
81 #define BLOCK_SIZE 256
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
82
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
83 /* Output and input configurations. */
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
84 #define AC3_OUTPUT_UNMODIFIED 0x01
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
85 #define AC3_OUTPUT_MONO 0x02
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
86 #define AC3_OUTPUT_STEREO 0x04
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
87 #define AC3_OUTPUT_DOLBY 0x08
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
88 #define AC3_OUTPUT_LFEON 0x10
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
89
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
90 typedef struct {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
91 uint8_t acmod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
92 uint8_t cmixlev;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
93 uint8_t surmixlev;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
94 uint8_t dsurmod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
95
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
96 uint8_t blksw;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
97 uint8_t dithflag;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
98 uint8_t cplinu;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
99 uint8_t chincpl;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
100 uint8_t phsflginu;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
101 uint8_t cplbegf;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
102 uint8_t cplendf;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
103 uint8_t cplcoe;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
104 uint32_t cplbndstrc;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
105 uint8_t rematstr;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
106 uint8_t rematflg;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
107 uint8_t cplexpstr;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
108 uint8_t lfeexpstr;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
109 uint8_t chexpstr[5];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
110 uint8_t sdcycod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
111 uint8_t fdcycod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
112 uint8_t sgaincod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
113 uint8_t dbpbcod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
114 uint8_t floorcod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
115 uint8_t csnroffst;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
116 uint8_t cplfsnroffst;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
117 uint8_t cplfgaincod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
118 uint8_t fsnroffst[5];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
119 uint8_t fgaincod[5];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
120 uint8_t lfefsnroffst;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
121 uint8_t lfefgaincod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
122 uint8_t cplfleak;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
123 uint8_t cplsleak;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
124 uint8_t cpldeltbae;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
125 uint8_t deltbae[5];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
126 uint8_t cpldeltnseg;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
127 uint8_t cpldeltoffst[8];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
128 uint8_t cpldeltlen[8];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
129 uint8_t cpldeltba[8];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
130 uint8_t deltnseg[5];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
131 uint8_t deltoffst[5][8];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
132 uint8_t deltlen[5][8];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
133 uint8_t deltba[5][8];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
134
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
135 /* Derived Attributes. */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
136 int sampling_rate;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
137 int bit_rate;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
138 int frame_size;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
139
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
140 int nchans; //number of total channels
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
141 int nfchans; //number of full-bandwidth channels
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
142 int lfeon; //lfe channel in use
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
143
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
144 float dynrng; //dynamic range gain
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
145 float dynrng2; //dynamic range gain for 1+1 mode
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
146 float chcoeffs[6]; //normalized channel coefficients
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
147 float cplco[5][18]; //coupling coordinates
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
148 int ncplbnd; //number of coupling bands
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
149 int ncplsubnd; //number of coupling sub bands
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
150 int cplstrtmant; //coupling start mantissa
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
151 int cplendmant; //coupling end mantissa
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
152 int endmant[5]; //channel end mantissas
5335
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
153 AC3BitAllocParameters bit_alloc_params; ///< bit allocation parameters
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
154
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
155 uint8_t dcplexps[256]; //decoded coupling exponents
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
156 uint8_t dexps[5][256]; //decoded fbw channel exponents
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
157 uint8_t dlfeexps[256]; //decoded lfe channel exponents
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
158 uint8_t cplbap[256]; //coupling bit allocation pointers
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
159 uint8_t bap[5][256]; //fbw channel bit allocation pointers
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
160 uint8_t lfebap[256]; //lfe channel bit allocation pointers
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
161
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
162 int blkoutput; //output configuration for block
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
163
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
164 DECLARE_ALIGNED_16(float, transform_coeffs[AC3_MAX_CHANNELS][BLOCK_SIZE]); //transform coefficients
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
165
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
166 /* For IMDCT. */
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
167 MDCTContext imdct_512; //for 512 sample imdct transform
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
168 MDCTContext imdct_256; //for 256 sample imdct transform
5317
6d81881f257f AC-3 decoder, soc revision 57, Aug 19 12:44:38 2006 UTC by cloud9
jbr
parents: 5316
diff changeset
169 DSPContext dsp; //for optimization
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
170
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
171 DECLARE_ALIGNED_16(float, output[AC3_MAX_CHANNELS][BLOCK_SIZE]); //output after imdct transform and windowing
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
172 DECLARE_ALIGNED_16(float, delay[AC3_MAX_CHANNELS][BLOCK_SIZE]); //delay - added to the next block
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
173 DECLARE_ALIGNED_16(float, tmp_imdct[BLOCK_SIZE]); //temporary storage for imdct transform
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
174 DECLARE_ALIGNED_16(float, tmp_output[BLOCK_SIZE * 2]); //temporary storage for output before windowing
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
175 DECLARE_ALIGNED_16(float, window[BLOCK_SIZE]); //window coefficients
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
176
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
177 /* Miscellaneous. */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
178 GetBitContext gb;
5330
37de2d864f03 use random number generator from libavutil
jbr
parents: 5329
diff changeset
179 AVRandomState dith_state; //for dither generation
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
180 } AC3DecodeContext;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
181
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
182 /*********** BEGIN INIT HELPER FUNCTIONS ***********/
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
183 /**
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
184 * Generate a Kaiser-Bessel Derived Window.
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
185 */
5320
3348a76efb67 AC-3 decoder, soc revision 70, Aug 31 18:04:23 2006 UTC by banan
jbr
parents: 5319
diff changeset
186 static void ac3_window_init(float *window)
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
187 {
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
188 int i, j;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
189 double sum = 0.0, bessel, tmp;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
190 double local_window[256];
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
191 double alpha2 = (5.0 * M_PI / 256.0) * (5.0 * M_PI / 256.0);
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
192
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
193 for (i = 0; i < 256; i++) {
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
194 tmp = i * (256 - i) * alpha2;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
195 bessel = 1.0;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
196 for (j = 100; j > 0; j--) /* defaul to 100 iterations */
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
197 bessel = bessel * tmp / (j * j) + 1;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
198 sum += bessel;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
199 local_window[i] = sum;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
200 }
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
201
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
202 sum++;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
203 for (i = 0; i < 256; i++)
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
204 window[i] = sqrt(local_window[i] / sum);
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
205 }
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
206
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
207 /*
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
208 * Generate quantizer tables.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
209 */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
210 static void generate_quantizers_table(int16_t quantizers[], int level, int length)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
211 {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
212 int i;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
213
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
214 for (i = 0; i < length; i++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
215 quantizers[i] = ((2 * i - level + 1) << 15) / level;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
216 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
217
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
218 static void generate_quantizers_table_1(int16_t quantizers[], int level, int length1, int length2, int size)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
219 {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
220 int i, j;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
221 int16_t v;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
222
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
223 for (i = 0; i < length1; i++) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
224 v = ((2 * i - level + 1) << 15) / level;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
225 for (j = 0; j < length2; j++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
226 quantizers[i * length2 + j] = v;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
227 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
228
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
229 for (i = length1 * length2; i < size; i++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
230 quantizers[i] = 0;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
231 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
232
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
233 static void generate_quantizers_table_2(int16_t quantizers[], int level, int length1, int length2, int size)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
234 {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
235 int i, j;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
236 int16_t v;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
237
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
238 for (i = 0; i < length1; i++) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
239 v = ((2 * (i % level) - level + 1) << 15) / level;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
240 for (j = 0; j < length2; j++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
241 quantizers[i * length2 + j] = v;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
242 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
243
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
244 for (i = length1 * length2; i < size; i++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
245 quantizers[i] = 0;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
246
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
247 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
248
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
249 static void generate_quantizers_table_3(int16_t quantizers[], int level, int length1, int length2, int size)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
250 {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
251 int i, j;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
252
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
253 for (i = 0; i < length1; i++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
254 for (j = 0; j < length2; j++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
255 quantizers[i * length2 + j] = ((2 * (j % level) - level + 1) << 15) / level;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
256
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
257 for (i = length1 * length2; i < size; i++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
258 quantizers[i] = 0;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
259 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
260
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
261 /*
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
262 * Initialize tables at runtime.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
263 */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
264 static void ac3_tables_init(void)
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
265 {
5375
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
266 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
267
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
268 /* Quantizer ungrouping tables. */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
269 // for level-3 quantizers
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
270 generate_quantizers_table_1(l3_quantizers_1, 3, 3, 9, 32);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
271 generate_quantizers_table_2(l3_quantizers_2, 3, 9, 3, 32);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
272 generate_quantizers_table_3(l3_quantizers_3, 3, 9, 3, 32);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
273
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
274 //for level-5 quantizers
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
275 generate_quantizers_table_1(l5_quantizers_1, 5, 5, 25, 128);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
276 generate_quantizers_table_2(l5_quantizers_2, 5, 25, 5, 128);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
277 generate_quantizers_table_3(l5_quantizers_3, 5, 25, 5, 128);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
278
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
279 //for level-7 quantizers
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
280 generate_quantizers_table(l7_quantizers, 7, 7);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
281
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
282 //for level-4 quantizers
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
283 generate_quantizers_table_2(l11_quantizers_1, 11, 11, 11, 128);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
284 generate_quantizers_table_3(l11_quantizers_2, 11, 11, 11, 128);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
285
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
286 //for level-15 quantizers
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
287 generate_quantizers_table(l15_quantizers, 15, 15);
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
288 /* End Quantizer ungrouping tables. */
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
289
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
290 //generate scale factors
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
291 for (i = 0; i < 25; i++)
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
292 scale_factors[i] = pow(2.0, -(i + 15));
5375
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
293
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
294 /* generate exponent tables
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
295 reference: Section 7.1.3 Exponent Decoding */
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
296 for(i=0; i<128; i++) {
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
297 exp_ungroup_tbl[i][0] = i / 25;
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
298 exp_ungroup_tbl[i][1] = (i % 25) / 5;
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
299 exp_ungroup_tbl[i][2] = (i % 25) % 5;
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
300 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
301 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
302
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
303
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
304 static int ac3_decode_init(AVCodecContext *avctx)
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
305 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
306 AC3DecodeContext *ctx = avctx->priv_data;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
307
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
308 ac3_common_init();
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
309 ac3_tables_init();
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
310 ff_mdct_init(&ctx->imdct_256, 8, 1);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
311 ff_mdct_init(&ctx->imdct_512, 9, 1);
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
312 ac3_window_init(ctx->window);
5317
6d81881f257f AC-3 decoder, soc revision 57, Aug 19 12:44:38 2006 UTC by cloud9
jbr
parents: 5316
diff changeset
313 dsputil_init(&ctx->dsp, avctx);
5330
37de2d864f03 use random number generator from libavutil
jbr
parents: 5329
diff changeset
314 av_init_random(0, &ctx->dith_state);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
315
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
316 return 0;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
317 }
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
318 /*********** END INIT FUNCTIONS ***********/
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
319
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
320 /**
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
321 * Parses the 'sync info' and 'bit stream info' from the AC-3 bitstream.
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
322 * GetBitContext within AC3DecodeContext must point to
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
323 * start of the synchronized ac3 bitstream.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
324 */
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
325 static int ac3_parse_header(AC3DecodeContext *ctx)
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
326 {
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
327 AC3HeaderInfo hdr;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
328 GetBitContext *gb = &ctx->gb;
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
329 int err, i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
330
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
331 err = ff_ac3_parse_header(gb->buffer, &hdr);
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
332 if(err)
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
333 return err;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
334
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
335 /* get decoding parameters from header info */
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
336 ctx->bit_alloc_params.fscod = hdr.fscod;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
337 ctx->acmod = hdr.acmod;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
338 ctx->cmixlev = hdr.cmixlev;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
339 ctx->surmixlev = hdr.surmixlev;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
340 ctx->dsurmod = hdr.dsurmod;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
341 ctx->lfeon = hdr.lfeon;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
342 ctx->bit_alloc_params.halfratecod = hdr.halfratecod;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
343 ctx->sampling_rate = hdr.sample_rate;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
344 ctx->bit_rate = hdr.bit_rate;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
345 ctx->nchans = hdr.channels;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
346 ctx->nfchans = ctx->nchans - ctx->lfeon;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
347 ctx->frame_size = hdr.frame_size;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
348 ctx->blkoutput = nfchans_tbl[ctx->acmod];
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
349 if(ctx->lfeon)
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
350 ctx->blkoutput |= AC3_OUTPUT_LFEON;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
351
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
352 /* skip over portion of header which has already been read */
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
353 skip_bits(gb, 16); //skip the sync_word, sync_info->sync_word = get_bits(gb, 16);
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
354 skip_bits(gb, 16); // skip crc1
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
355 skip_bits(gb, 8); // skip fscod and frmsizecod
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
356 skip_bits(gb, 11); // skip bsid, bsmod, and acmod
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
357 if(ctx->acmod == AC3_ACMOD_STEREO) {
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
358 skip_bits(gb, 2); // skip dsurmod
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
359 } else {
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
360 if((ctx->acmod & 1) && ctx->acmod != AC3_ACMOD_MONO)
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
361 skip_bits(gb, 2); // skip cmixlev
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
362 if(ctx->acmod & 4)
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
363 skip_bits(gb, 2); // skip surmixlev
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
364 }
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
365 skip_bits1(gb); // skip lfeon
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
366
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
367 /* read the rest of the bsi. read twice for dual mono mode. */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
368 i = !(ctx->acmod);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
369 do {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
370 skip_bits(gb, 5); //skip dialog normalization
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
371 if (get_bits1(gb))
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
372 skip_bits(gb, 8); //skip compression
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
373 if (get_bits1(gb))
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
374 skip_bits(gb, 8); //skip language code
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
375 if (get_bits1(gb))
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
376 skip_bits(gb, 7); //skip audio production information
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
377 } while (i--);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
378
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
379 skip_bits(gb, 2); //skip copyright bit and original bitstream bit
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
380
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
381 /* FIXME: read & use the xbsi1 downmix levels */
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
382 if (get_bits1(gb))
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
383 skip_bits(gb, 14); //skip timecode1
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
384 if (get_bits1(gb))
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
385 skip_bits(gb, 14); //skip timecode2
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
386
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
387 if (get_bits1(gb)) {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
388 i = get_bits(gb, 6); //additional bsi length
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
389 do {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
390 skip_bits(gb, 8);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
391 } while(i--);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
392 }
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
393
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
394 return 0;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
395 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
396
5376
83682d6837e4 revise comment for exponent decoding function
jbr
parents: 5375
diff changeset
397 /**
83682d6837e4 revise comment for exponent decoding function
jbr
parents: 5375
diff changeset
398 * Decodes the grouped exponents.
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
399 * This function decodes the coded exponents according to exponent strategy
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
400 * and stores them in the decoded exponents buffer.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
401 *
5376
83682d6837e4 revise comment for exponent decoding function
jbr
parents: 5375
diff changeset
402 * @param[in] gb GetBitContext which points to start of coded exponents
83682d6837e4 revise comment for exponent decoding function
jbr
parents: 5375
diff changeset
403 * @param[in] expstr Exponent coding strategy
83682d6837e4 revise comment for exponent decoding function
jbr
parents: 5375
diff changeset
404 * @param[in] ngrps Number of grouped exponents
83682d6837e4 revise comment for exponent decoding function
jbr
parents: 5375
diff changeset
405 * @param[in] absexp Absolute exponent or DC exponent
83682d6837e4 revise comment for exponent decoding function
jbr
parents: 5375
diff changeset
406 * @param[out] dexps Decoded exponents are stored in dexps
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
407 */
5375
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
408 static void decode_exponents(GetBitContext *gb, int expstr, int ngrps,
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
409 uint8_t absexp, uint8_t *dexps)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
410 {
5375
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
411 int i, j, grp, grpsize;
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
412 int dexp[256];
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
413 int expacc, prevexp;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
414
5375
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
415 /* unpack groups */
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
416 grpsize = expstr + (expstr == EXP_D45);
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
417 for(grp=0,i=0; grp<ngrps; grp++) {
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
418 expacc = get_bits(gb, 7);
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
419 dexp[i++] = exp_ungroup_tbl[expacc][0];
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
420 dexp[i++] = exp_ungroup_tbl[expacc][1];
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
421 dexp[i++] = exp_ungroup_tbl[expacc][2];
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
422 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
423
5375
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
424 /* convert to absolute exps and expand groups */
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
425 prevexp = absexp;
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
426 for(i=0; i<ngrps*3; i++) {
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
427 prevexp = av_clip(prevexp + dexp[i]-2, 0, 24);
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
428 for(j=0; j<grpsize; j++) {
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
429 dexps[(i*grpsize)+j] = prevexp;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
430 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
431 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
432 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
433
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
434 /* Performs bit allocation.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
435 * This function performs bit allocation for the requested chanenl.
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
436 */
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
437 static void do_bit_allocation(AC3DecodeContext *ctx, int chnl)
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
438 {
5335
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
439 int fgain, snroffset;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
440
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
441 if (chnl == 5) {
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
442 fgain = ff_fgaintab[ctx->cplfgaincod];
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
443 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->cplfsnroffst) << 2;
5335
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
444 ac3_parametric_bit_allocation(&ctx->bit_alloc_params, ctx->cplbap,
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
445 ctx->dcplexps, ctx->cplstrtmant,
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
446 ctx->cplendmant, snroffset, fgain, 0,
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
447 ctx->cpldeltbae, ctx->cpldeltnseg,
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
448 ctx->cpldeltoffst, ctx->cpldeltlen,
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
449 ctx->cpldeltba);
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
450 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
451 else if (chnl == 6) {
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
452 fgain = ff_fgaintab[ctx->lfefgaincod];
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
453 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->lfefsnroffst) << 2;
5335
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
454 ac3_parametric_bit_allocation(&ctx->bit_alloc_params, ctx->lfebap,
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
455 ctx->dlfeexps, 0, 7, snroffset, fgain, 1,
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
456 DBA_NONE, 0, NULL, NULL, NULL);
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
457 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
458 else {
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
459 fgain = ff_fgaintab[ctx->fgaincod[chnl]];
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
460 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->fsnroffst[chnl]) << 2;
5335
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
461 ac3_parametric_bit_allocation(&ctx->bit_alloc_params, ctx->bap[chnl],
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
462 ctx->dexps[chnl], 0, ctx->endmant[chnl],
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
463 snroffset, fgain, 0, ctx->deltbae[chnl],
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
464 ctx->deltnseg[chnl], ctx->deltoffst[chnl],
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
465 ctx->deltlen[chnl], ctx->deltba[chnl]);
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
466 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
467 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
468
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
469 typedef struct { /* grouped mantissas for 3-level 5-leve and 11-level quantization */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
470 int16_t l3_quantizers[3];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
471 int16_t l5_quantizers[3];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
472 int16_t l11_quantizers[2];
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
473 int l3ptr;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
474 int l5ptr;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
475 int l11ptr;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
476 } mant_groups;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
477
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
478 /* Get the transform coefficients for coupling channel and uncouple channels.
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
479 * The coupling transform coefficients starts at the the cplstrtmant, which is
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
480 * equal to endmant[ch] for fbw channels. Hence we can uncouple channels before
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
481 * getting transform coefficients for the channel.
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
482 */
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
483 static int get_transform_coeffs_cpling(AC3DecodeContext *ctx, mant_groups *m)
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
484 {
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
485 GetBitContext *gb = &ctx->gb;
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
486 int ch, start, end, cplbndstrc, bnd, gcode, tbap;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
487 float cplcos[5], cplcoeff;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
488 uint8_t *exps = ctx->dcplexps;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
489 uint8_t *bap = ctx->cplbap;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
490
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
491 cplbndstrc = ctx->cplbndstrc;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
492 start = ctx->cplstrtmant;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
493 bnd = 0;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
494
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
495 while (start < ctx->cplendmant) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
496 end = start + 12;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
497 while (cplbndstrc & 1) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
498 end += 12;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
499 cplbndstrc >>= 1;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
500 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
501 cplbndstrc >>= 1;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
502 for (ch = 0; ch < ctx->nfchans; ch++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
503 cplcos[ch] = ctx->chcoeffs[ch] * ctx->cplco[ch][bnd];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
504 bnd++;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
505
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
506 while (start < end) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
507 tbap = bap[start];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
508 switch(tbap) {
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
509 case 0:
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
510 for (ch = 0; ch < ctx->nfchans; ch++)
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
511 if (((ctx->chincpl) >> ch) & 1) {
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
512 if ((ctx->dithflag >> ch) & 1) {
5384
3721d0042e5a get rid of an ugly macro
jbr
parents: 5378
diff changeset
513 cplcoeff = (av_random(&ctx->dith_state) & 0xFFFF) * scale_factors[exps[start]];
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
514 ctx->transform_coeffs[ch + 1][start] = cplcoeff * cplcos[ch] * LEVEL_MINUS_3DB;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
515 } else
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
516 ctx->transform_coeffs[ch + 1][start] = 0;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
517 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
518 start++;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
519 continue;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
520 case 1:
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
521 if (m->l3ptr > 2) {
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
522 gcode = get_bits(gb, 5);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
523 m->l3_quantizers[0] = l3_quantizers_1[gcode];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
524 m->l3_quantizers[1] = l3_quantizers_2[gcode];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
525 m->l3_quantizers[2] = l3_quantizers_3[gcode];
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
526 m->l3ptr = 0;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
527 }
5384
3721d0042e5a get rid of an ugly macro
jbr
parents: 5378
diff changeset
528 cplcoeff = m->l3_quantizers[m->l3ptr++] * scale_factors[exps[start]];
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
529 break;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
530
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
531 case 2:
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
532 if (m->l5ptr > 2) {
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
533 gcode = get_bits(gb, 7);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
534 m->l5_quantizers[0] = l5_quantizers_1[gcode];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
535 m->l5_quantizers[1] = l5_quantizers_2[gcode];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
536 m->l5_quantizers[2] = l5_quantizers_3[gcode];
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
537 m->l5ptr = 0;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
538 }
5384
3721d0042e5a get rid of an ugly macro
jbr
parents: 5378
diff changeset
539 cplcoeff = m->l5_quantizers[m->l5ptr++] * scale_factors[exps[start]];
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
540 break;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
541
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
542 case 3:
5384
3721d0042e5a get rid of an ugly macro
jbr
parents: 5378
diff changeset
543 cplcoeff = l7_quantizers[get_bits(gb, 3)] * scale_factors[exps[start]];
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
544 break;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
545
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
546 case 4:
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
547 if (m->l11ptr > 1) {
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
548 gcode = get_bits(gb, 7);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
549 m->l11_quantizers[0] = l11_quantizers_1[gcode];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
550 m->l11_quantizers[1] = l11_quantizers_2[gcode];
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
551 m->l11ptr = 0;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
552 }
5384
3721d0042e5a get rid of an ugly macro
jbr
parents: 5378
diff changeset
553 cplcoeff = m->l11_quantizers[m->l11ptr++] * scale_factors[exps[start]];
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
554 break;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
555
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
556 case 5:
5384
3721d0042e5a get rid of an ugly macro
jbr
parents: 5378
diff changeset
557 cplcoeff = l15_quantizers[get_bits(gb, 4)] * scale_factors[exps[start]];
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
558 break;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
559
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
560 default:
5384
3721d0042e5a get rid of an ugly macro
jbr
parents: 5378
diff changeset
561 cplcoeff = (get_sbits(gb, qntztab[tbap]) << (16 - qntztab[tbap])) * scale_factors[exps[start]];
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
562 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
563 for (ch = 0; ch < ctx->nfchans; ch++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
564 if ((ctx->chincpl >> ch) & 1)
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
565 ctx->transform_coeffs[ch + 1][start] = cplcoeff * cplcos[ch];
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
566 start++;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
567 }
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
568 }
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
569
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
570 return 0;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
571 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
572
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
573 /* Get the transform coefficients for particular channel */
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
574 static int get_transform_coeffs_ch(AC3DecodeContext *ctx, int ch_index, mant_groups *m)
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
575 {
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
576 GetBitContext *gb = &ctx->gb;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
577 int i, gcode, tbap, dithflag, end;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
578 uint8_t *exps;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
579 uint8_t *bap;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
580 float *coeffs;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
581 float factors[25];
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
582
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
583 for (i = 0; i < 25; i++)
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
584 factors[i] = scale_factors[i] * ctx->chcoeffs[ch_index];
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
585
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
586 if (ch_index != -1) { /* fbw channels */
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
587 dithflag = (ctx->dithflag >> ch_index) & 1;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
588 exps = ctx->dexps[ch_index];
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
589 bap = ctx->bap[ch_index];
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
590 coeffs = ctx->transform_coeffs[ch_index + 1];
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
591 end = ctx->endmant[ch_index];
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
592 } else if (ch_index == -1) {
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
593 dithflag = 0;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
594 exps = ctx->dlfeexps;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
595 bap = ctx->lfebap;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
596 coeffs = ctx->transform_coeffs[0];
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
597 end = 7;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
598 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
599
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
600
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
601 for (i = 0; i < end; i++) {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
602 tbap = bap[i];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
603 switch (tbap) {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
604 case 0:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
605 if (!dithflag) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
606 coeffs[i] = 0;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
607 continue;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
608 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
609 else {
5384
3721d0042e5a get rid of an ugly macro
jbr
parents: 5378
diff changeset
610 coeffs[i] = (av_random(&ctx->dith_state) & 0xFFFF) * factors[exps[i]];
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
611 coeffs[i] *= LEVEL_MINUS_3DB;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
612 continue;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
613 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
614
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
615 case 1:
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
616 if (m->l3ptr > 2) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
617 gcode = get_bits(gb, 5);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
618 m->l3_quantizers[0] = l3_quantizers_1[gcode];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
619 m->l3_quantizers[1] = l3_quantizers_2[gcode];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
620 m->l3_quantizers[2] = l3_quantizers_3[gcode];
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
621 m->l3ptr = 0;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
622 }
5384
3721d0042e5a get rid of an ugly macro
jbr
parents: 5378
diff changeset
623 coeffs[i] = m->l3_quantizers[m->l3ptr++] * factors[exps[i]];
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
624 continue;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
625
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
626 case 2:
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
627 if (m->l5ptr > 2) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
628 gcode = get_bits(gb, 7);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
629 m->l5_quantizers[0] = l5_quantizers_1[gcode];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
630 m->l5_quantizers[1] = l5_quantizers_2[gcode];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
631 m->l5_quantizers[2] = l5_quantizers_3[gcode];
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
632 m->l5ptr = 0;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
633 }
5384
3721d0042e5a get rid of an ugly macro
jbr
parents: 5378
diff changeset
634 coeffs[i] = m->l5_quantizers[m->l5ptr++] * factors[exps[i]];
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
635 continue;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
636
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
637 case 3:
5384
3721d0042e5a get rid of an ugly macro
jbr
parents: 5378
diff changeset
638 coeffs[i] = l7_quantizers[get_bits(gb, 3)] * factors[exps[i]];
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
639 continue;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
640
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
641 case 4:
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
642 if (m->l11ptr > 1) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
643 gcode = get_bits(gb, 7);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
644 m->l11_quantizers[0] = l11_quantizers_1[gcode];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
645 m->l11_quantizers[1] = l11_quantizers_2[gcode];
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
646 m->l11ptr = 0;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
647 }
5384
3721d0042e5a get rid of an ugly macro
jbr
parents: 5378
diff changeset
648 coeffs[i] = m->l11_quantizers[m->l11ptr++] * factors[exps[i]];
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
649 continue;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
650
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
651 case 5:
5384
3721d0042e5a get rid of an ugly macro
jbr
parents: 5378
diff changeset
652 coeffs[i] = l15_quantizers[get_bits(gb, 4)] * factors[exps[i]];
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
653 continue;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
654
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
655 default:
5384
3721d0042e5a get rid of an ugly macro
jbr
parents: 5378
diff changeset
656 coeffs[i] = (get_sbits(gb, qntztab[tbap]) << (16 - qntztab[tbap])) * factors[exps[i]];
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
657 continue;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
658 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
659 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
660
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
661 return 0;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
662 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
663
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
664 /* Get the transform coefficients.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
665 * This function extracts the tranform coefficients form the ac3 bitstream.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
666 * This function is called after bit allocation is performed.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
667 */
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
668 static int get_transform_coeffs(AC3DecodeContext * ctx)
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
669 {
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
670 int i, end;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
671 int got_cplchan = 0;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
672 mant_groups m;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
673
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
674 m.l3ptr = m.l5ptr = m.l11ptr = 3;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
675
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
676 for (i = 0; i < ctx->nfchans; i++) {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
677 /* transform coefficients for individual channel */
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
678 if (get_transform_coeffs_ch(ctx, i, &m))
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
679 return -1;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
680 /* tranform coefficients for coupling channels */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
681 if ((ctx->chincpl >> i) & 1) {
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
682 if (!got_cplchan) {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
683 if (get_transform_coeffs_cpling(ctx, &m)) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
684 av_log(NULL, AV_LOG_ERROR, "error in decoupling channels\n");
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
685 return -1;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
686 }
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
687 got_cplchan = 1;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
688 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
689 end = ctx->cplendmant;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
690 } else
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
691 end = ctx->endmant[i];
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
692 do
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
693 ctx->transform_coeffs[i + 1][end] = 0;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
694 while(++end < 256);
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
695 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
696 if (ctx->lfeon) {
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
697 if (get_transform_coeffs_ch(ctx, -1, &m))
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
698 return -1;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
699 for (i = 7; i < 256; i++) {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
700 ctx->transform_coeffs[0][i] = 0;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
701 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
702 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
703
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
704 return 0;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
705 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
706
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
707 /* Rematrixing routines. */
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
708 static void do_rematrixing1(AC3DecodeContext *ctx, int start, int end)
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
709 {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
710 float tmp0, tmp1;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
711
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
712 while (start < end) {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
713 tmp0 = ctx->transform_coeffs[1][start];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
714 tmp1 = ctx->transform_coeffs[2][start];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
715 ctx->transform_coeffs[1][start] = tmp0 + tmp1;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
716 ctx->transform_coeffs[2][start] = tmp0 - tmp1;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
717 start++;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
718 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
719 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
720
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
721 static void do_rematrixing(AC3DecodeContext *ctx)
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
722 {
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
723 int bnd1 = 13, bnd2 = 25, bnd3 = 37, bnd4 = 61;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
724 int end, bndend;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
725
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
726 end = FFMIN(ctx->endmant[0], ctx->endmant[1]);
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
727
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
728 if (ctx->rematflg & 1)
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
729 do_rematrixing1(ctx, bnd1, bnd2);
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
730
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
731 if (ctx->rematflg & 2)
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
732 do_rematrixing1(ctx, bnd2, bnd3);
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
733
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
734 bndend = bnd4;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
735 if (bndend > end) {
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
736 bndend = end;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
737 if (ctx->rematflg & 4)
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
738 do_rematrixing1(ctx, bnd3, bndend);
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
739 } else {
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
740 if (ctx->rematflg & 4)
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
741 do_rematrixing1(ctx, bnd3, bnd4);
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
742 if (ctx->rematflg & 8)
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
743 do_rematrixing1(ctx, bnd4, end);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
744 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
745 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
746
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
747 /* This function sets the normalized channel coefficients.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
748 * Transform coefficients are multipllied by the channel
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
749 * coefficients to get normalized transform coefficients.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
750 */
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
751 static void get_downmix_coeffs(AC3DecodeContext *ctx)
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
752 {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
753 int from = ctx->acmod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
754 int to = ctx->blkoutput;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
755 float clev = clevs[ctx->cmixlev];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
756 float slev = slevs[ctx->surmixlev];
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
757 float nf = 1.0; //normalization factor for downmix coeffs
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
758 int i;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
759
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
760 if (!ctx->acmod) {
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
761 ctx->chcoeffs[0] = 2 * ctx->dynrng;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
762 ctx->chcoeffs[1] = 2 * ctx->dynrng2;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
763 } else {
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
764 for (i = 0; i < ctx->nfchans; i++)
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
765 ctx->chcoeffs[i] = 2 * ctx->dynrng;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
766 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
767
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
768 if (to == AC3_OUTPUT_UNMODIFIED)
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
769 return;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
770
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
771 switch (from) {
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
772 case AC3_ACMOD_DUALMONO:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
773 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
774 case AC3_OUTPUT_MONO:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
775 case AC3_OUTPUT_STEREO: /* We Assume that sum of both mono channels is requested */
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
776 nf = 0.5;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
777 ctx->chcoeffs[0] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
778 ctx->chcoeffs[1] *= nf;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
779 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
780 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
781 break;
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
782 case AC3_ACMOD_MONO:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
783 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
784 case AC3_OUTPUT_STEREO:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
785 nf = LEVEL_MINUS_3DB;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
786 ctx->chcoeffs[0] *= nf;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
787 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
788 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
789 break;
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
790 case AC3_ACMOD_STEREO:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
791 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
792 case AC3_OUTPUT_MONO:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
793 nf = LEVEL_MINUS_3DB;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
794 ctx->chcoeffs[0] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
795 ctx->chcoeffs[1] *= nf;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
796 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
797 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
798 break;
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
799 case AC3_ACMOD_3F:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
800 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
801 case AC3_OUTPUT_MONO:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
802 nf = LEVEL_MINUS_3DB / (1.0 + clev);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
803 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
804 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
805 ctx->chcoeffs[1] *= ((nf * clev * LEVEL_MINUS_3DB) / 2.0);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
806 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
807 case AC3_OUTPUT_STEREO:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
808 nf = 1.0 / (1.0 + clev);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
809 ctx->chcoeffs[0] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
810 ctx->chcoeffs[2] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
811 ctx->chcoeffs[1] *= (nf * clev);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
812 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
813 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
814 break;
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
815 case AC3_ACMOD_2F1R:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
816 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
817 case AC3_OUTPUT_MONO:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
818 nf = 2.0 * LEVEL_MINUS_3DB / (2.0 + slev);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
819 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
820 ctx->chcoeffs[1] *= (nf * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
821 ctx->chcoeffs[2] *= (nf * slev * LEVEL_MINUS_3DB);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
822 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
823 case AC3_OUTPUT_STEREO:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
824 nf = 1.0 / (1.0 + (slev * LEVEL_MINUS_3DB));
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
825 ctx->chcoeffs[0] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
826 ctx->chcoeffs[1] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
827 ctx->chcoeffs[2] *= (nf * slev * LEVEL_MINUS_3DB);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
828 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
829 case AC3_OUTPUT_DOLBY:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
830 nf = 1.0 / (1.0 + LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
831 ctx->chcoeffs[0] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
832 ctx->chcoeffs[1] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
833 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
834 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
835 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
836 break;
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
837 case AC3_ACMOD_3F1R:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
838 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
839 case AC3_OUTPUT_MONO:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
840 nf = LEVEL_MINUS_3DB / (1.0 + clev + (slev / 2.0));
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
841 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
842 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
843 ctx->chcoeffs[1] *= (nf * clev * LEVEL_PLUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
844 ctx->chcoeffs[3] *= (nf * slev * LEVEL_MINUS_3DB);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
845 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
846 case AC3_OUTPUT_STEREO:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
847 nf = 1.0 / (1.0 + clev + (slev * LEVEL_MINUS_3DB));
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
848 ctx->chcoeffs[0] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
849 ctx->chcoeffs[2] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
850 ctx->chcoeffs[1] *= (nf * clev);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
851 ctx->chcoeffs[3] *= (nf * slev * LEVEL_MINUS_3DB);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
852 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
853 case AC3_OUTPUT_DOLBY:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
854 nf = 1.0 / (1.0 + (2.0 * LEVEL_MINUS_3DB));
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
855 ctx->chcoeffs[0] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
856 ctx->chcoeffs[1] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
857 ctx->chcoeffs[1] *= (nf * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
858 ctx->chcoeffs[3] *= (nf * LEVEL_MINUS_3DB);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
859 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
860 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
861 break;
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
862 case AC3_ACMOD_2F2R:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
863 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
864 case AC3_OUTPUT_MONO:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
865 nf = LEVEL_MINUS_3DB / (1.0 + slev);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
866 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
867 ctx->chcoeffs[1] *= (nf * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
868 ctx->chcoeffs[2] *= (nf * slev * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
869 ctx->chcoeffs[3] *= (nf * slev * LEVEL_MINUS_3DB);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
870 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
871 case AC3_OUTPUT_STEREO:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
872 nf = 1.0 / (1.0 + slev);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
873 ctx->chcoeffs[0] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
874 ctx->chcoeffs[1] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
875 ctx->chcoeffs[2] *= (nf * slev);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
876 ctx->chcoeffs[3] *= (nf * slev);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
877 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
878 case AC3_OUTPUT_DOLBY:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
879 nf = 1.0 / (1.0 + (2.0 * LEVEL_MINUS_3DB));
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
880 ctx->chcoeffs[0] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
881 ctx->chcoeffs[1] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
882 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
883 ctx->chcoeffs[3] *= (nf * LEVEL_MINUS_3DB);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
884 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
885 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
886 break;
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
887 case AC3_ACMOD_3F2R:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
888 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
889 case AC3_OUTPUT_MONO:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
890 nf = LEVEL_MINUS_3DB / (1.0 + clev + slev);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
891 ctx->chcoeffs[0] *= (nf * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
892 ctx->chcoeffs[2] *= (nf * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
893 ctx->chcoeffs[1] *= (nf * clev * LEVEL_PLUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
894 ctx->chcoeffs[3] *= (nf * slev * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
895 ctx->chcoeffs[4] *= (nf * slev * LEVEL_MINUS_3DB);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
896 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
897 case AC3_OUTPUT_STEREO:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
898 nf = 1.0 / (1.0 + clev + slev);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
899 ctx->chcoeffs[0] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
900 ctx->chcoeffs[2] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
901 ctx->chcoeffs[1] *= (nf * clev);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
902 ctx->chcoeffs[3] *= (nf * slev);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
903 ctx->chcoeffs[4] *= (nf * slev);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
904 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
905 case AC3_OUTPUT_DOLBY:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
906 nf = 1.0 / (1.0 + (3.0 * LEVEL_MINUS_3DB));
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
907 ctx->chcoeffs[0] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
908 ctx->chcoeffs[1] *= nf;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
909 ctx->chcoeffs[1] *= (nf * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
910 ctx->chcoeffs[3] *= (nf * LEVEL_MINUS_3DB);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
911 ctx->chcoeffs[4] *= (nf * LEVEL_MINUS_3DB);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
912 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
913 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
914 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
915 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
916 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
917
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
918 /*********** BEGIN DOWNMIX FUNCTIONS ***********/
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
919 static inline void mix_dualmono_to_mono(AC3DecodeContext *ctx)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
920 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
921 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
922 float (*output)[BLOCK_SIZE] = ctx->output;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
923
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
924 for (i = 0; i < 256; i++)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
925 output[1][i] += output[2][i];
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
926 memset(output[2], 0, sizeof(output[2]));
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
927 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
928
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
929 static inline void mix_dualmono_to_stereo(AC3DecodeContext *ctx)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
930 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
931 int i;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
932 float tmp;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
933 float (*output)[BLOCK_SIZE] = ctx->output;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
934
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
935 for (i = 0; i < 256; i++) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
936 tmp = output[1][i] + output[2][i];
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
937 output[1][i] = output[2][i] = tmp;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
938 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
939 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
940
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
941 static inline void upmix_mono_to_stereo(AC3DecodeContext *ctx)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
942 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
943 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
944 float (*output)[BLOCK_SIZE] = ctx->output;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
945
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
946 for (i = 0; i < 256; i++)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
947 output[2][i] = output[1][i];
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
948 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
949
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
950 static inline void mix_stereo_to_mono(AC3DecodeContext *ctx)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
951 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
952 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
953 float (*output)[BLOCK_SIZE] = ctx->output;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
954
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
955 for (i = 0; i < 256; i++)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
956 output[1][i] += output[2][i];
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
957 memset(output[2], 0, sizeof(output[2]));
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
958 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
959
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
960 static inline void mix_3f_to_mono(AC3DecodeContext *ctx)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
961 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
962 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
963 float (*output)[BLOCK_SIZE] = ctx->output;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
964
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
965 for (i = 0; i < 256; i++)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
966 output[1][i] += (output[2][i] + output[3][i]);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
967 memset(output[2], 0, sizeof(output[2]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
968 memset(output[3], 0, sizeof(output[3]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
969 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
970
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
971 static inline void mix_3f_to_stereo(AC3DecodeContext *ctx)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
972 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
973 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
974 float (*output)[BLOCK_SIZE] = ctx->output;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
975
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
976 for (i = 0; i < 256; i++) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
977 output[1][i] += output[2][i];
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
978 output[2][i] += output[3][i];
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
979 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
980 memset(output[3], 0, sizeof(output[3]));
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
981 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
982
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
983 static inline void mix_2f_1r_to_mono(AC3DecodeContext *ctx)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
984 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
985 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
986 float (*output)[BLOCK_SIZE] = ctx->output;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
987
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
988 for (i = 0; i < 256; i++)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
989 output[1][i] += (output[2][i] + output[3][i]);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
990 memset(output[2], 0, sizeof(output[2]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
991 memset(output[3], 0, sizeof(output[3]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
992
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
993 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
994
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
995 static inline void mix_2f_1r_to_stereo(AC3DecodeContext *ctx)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
996 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
997 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
998 float (*output)[BLOCK_SIZE] = ctx->output;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
999
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1000 for (i = 0; i < 256; i++) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1001 output[1][i] += output[2][i];
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1002 output[2][i] += output[3][i];
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1003 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1004 memset(output[3], 0, sizeof(output[3]));
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1005 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1006
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1007 static inline void mix_2f_1r_to_dolby(AC3DecodeContext *ctx)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1008 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1009 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1010 float (*output)[BLOCK_SIZE] = ctx->output;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1011
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1012 for (i = 0; i < 256; i++) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1013 output[1][i] -= output[3][i];
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1014 output[2][i] += output[3][i];
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1015 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1016 memset(output[3], 0, sizeof(output[3]));
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1017 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1018
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1019 static inline void mix_3f_1r_to_mono(AC3DecodeContext *ctx)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1020 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1021 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1022 float (*output)[BLOCK_SIZE] = ctx->output;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1023
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1024 for (i = 0; i < 256; i++)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1025 output[1][i] = (output[2][i] + output[3][i] + output[4][i]);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1026 memset(output[2], 0, sizeof(output[2]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1027 memset(output[3], 0, sizeof(output[3]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1028 memset(output[4], 0, sizeof(output[4]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1029 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1030
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1031 static inline void mix_3f_1r_to_stereo(AC3DecodeContext *ctx)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1032 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1033 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1034 float (*output)[BLOCK_SIZE] = ctx->output;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1035
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1036 for (i = 0; i < 256; i++) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1037 output[1][i] += (output[2][i] + output[4][i]);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1038 output[2][i] += (output[3][i] + output[4][i]);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1039 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1040 memset(output[3], 0, sizeof(output[3]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1041 memset(output[4], 0, sizeof(output[4]));
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1042 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1043
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1044 static inline void mix_3f_1r_to_dolby(AC3DecodeContext *ctx)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1045 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1046 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1047 float (*output)[BLOCK_SIZE] = ctx->output;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1048
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1049 for (i = 0; i < 256; i++) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1050 output[1][i] += (output[2][i] - output[4][i]);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1051 output[2][i] += (output[3][i] + output[4][i]);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1052 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1053 memset(output[3], 0, sizeof(output[3]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1054 memset(output[4], 0, sizeof(output[4]));
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1055 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1056
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1057 static inline void mix_2f_2r_to_mono(AC3DecodeContext *ctx)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1058 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1059 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1060 float (*output)[BLOCK_SIZE] = ctx->output;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1061
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1062 for (i = 0; i < 256; i++)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1063 output[1][i] = (output[2][i] + output[3][i] + output[4][i]);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1064 memset(output[2], 0, sizeof(output[2]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1065 memset(output[3], 0, sizeof(output[3]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1066 memset(output[4], 0, sizeof(output[4]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1067 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1068
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1069 static inline void mix_2f_2r_to_stereo(AC3DecodeContext *ctx)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1070 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1071 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1072 float (*output)[BLOCK_SIZE] = ctx->output;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1073
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1074 for (i = 0; i < 256; i++) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1075 output[1][i] += output[3][i];
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1076 output[2][i] += output[4][i];
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1077 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1078 memset(output[3], 0, sizeof(output[3]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1079 memset(output[4], 0, sizeof(output[4]));
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1080 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1081
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1082 static inline void mix_2f_2r_to_dolby(AC3DecodeContext *ctx)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1083 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1084 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1085 float (*output)[BLOCK_SIZE] = ctx->output;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1086
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1087 for (i = 0; i < 256; i++) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1088 output[1][i] -= output[3][i];
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1089 output[2][i] += output[4][i];
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1090 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1091 memset(output[3], 0, sizeof(output[3]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1092 memset(output[4], 0, sizeof(output[4]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1093 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1094
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1095 static inline void mix_3f_2r_to_mono(AC3DecodeContext *ctx)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1096 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1097 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1098 float (*output)[BLOCK_SIZE] = ctx->output;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1099
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1100 for (i = 0; i < 256; i++)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1101 output[1][i] += (output[2][i] + output[3][i] + output[4][i] + output[5][i]);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1102 memset(output[2], 0, sizeof(output[2]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1103 memset(output[3], 0, sizeof(output[3]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1104 memset(output[4], 0, sizeof(output[4]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1105 memset(output[5], 0, sizeof(output[5]));
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1106 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1107
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1108 static inline void mix_3f_2r_to_stereo(AC3DecodeContext *ctx)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1109 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1110 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1111 float (*output)[BLOCK_SIZE] = ctx->output;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1112
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1113 for (i = 0; i < 256; i++) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1114 output[1][i] += (output[2][i] + output[4][i]);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1115 output[2][i] += (output[3][i] + output[5][i]);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1116 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1117 memset(output[3], 0, sizeof(output[3]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1118 memset(output[4], 0, sizeof(output[4]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1119 memset(output[5], 0, sizeof(output[5]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1120 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1121
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1122 static inline void mix_3f_2r_to_dolby(AC3DecodeContext *ctx)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1123 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1124 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1125 float (*output)[BLOCK_SIZE] = ctx->output;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1126
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1127 for (i = 0; i < 256; i++) {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1128 output[1][i] += (output[2][i] - output[4][i] - output[5][i]);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1129 output[2][i] += (output[3][i] + output[4][i] + output[5][i]);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1130 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1131 memset(output[3], 0, sizeof(output[3]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1132 memset(output[4], 0, sizeof(output[4]));
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1133 memset(output[5], 0, sizeof(output[5]));
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1134 }
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1135 /*********** END DOWNMIX FUNCTIONS ***********/
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1136
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1137 /* Downmix the output.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1138 * This function downmixes the output when the number of input
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1139 * channels is not equal to the number of output channels requested.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1140 */
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1141 static void do_downmix(AC3DecodeContext *ctx)
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1142 {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1143 int from = ctx->acmod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1144 int to = ctx->blkoutput;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1145
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1146 if (to == AC3_OUTPUT_UNMODIFIED)
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1147 return;
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1148
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1149 switch (from) {
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1150 case AC3_ACMOD_DUALMONO:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1151 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1152 case AC3_OUTPUT_MONO:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1153 mix_dualmono_to_mono(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1154 break;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1155 case AC3_OUTPUT_STEREO: /* We assume that sum of both mono channels is requested */
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1156 mix_dualmono_to_stereo(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1157 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1158 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1159 break;
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1160 case AC3_ACMOD_MONO:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1161 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1162 case AC3_OUTPUT_STEREO:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1163 upmix_mono_to_stereo(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1164 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1165 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1166 break;
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1167 case AC3_ACMOD_STEREO:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1168 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1169 case AC3_OUTPUT_MONO:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1170 mix_stereo_to_mono(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1171 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1172 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1173 break;
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1174 case AC3_ACMOD_3F:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1175 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1176 case AC3_OUTPUT_MONO:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1177 mix_3f_to_mono(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1178 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1179 case AC3_OUTPUT_STEREO:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1180 mix_3f_to_stereo(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1181 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1182 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1183 break;
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1184 case AC3_ACMOD_2F1R:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1185 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1186 case AC3_OUTPUT_MONO:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1187 mix_2f_1r_to_mono(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1188 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1189 case AC3_OUTPUT_STEREO:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1190 mix_2f_1r_to_stereo(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1191 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1192 case AC3_OUTPUT_DOLBY:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1193 mix_2f_1r_to_dolby(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1194 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1195 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1196 break;
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1197 case AC3_ACMOD_3F1R:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1198 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1199 case AC3_OUTPUT_MONO:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1200 mix_3f_1r_to_mono(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1201 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1202 case AC3_OUTPUT_STEREO:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1203 mix_3f_1r_to_stereo(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1204 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1205 case AC3_OUTPUT_DOLBY:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1206 mix_3f_1r_to_dolby(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1207 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1208 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1209 break;
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1210 case AC3_ACMOD_2F2R:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1211 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1212 case AC3_OUTPUT_MONO:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1213 mix_2f_2r_to_mono(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1214 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1215 case AC3_OUTPUT_STEREO:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1216 mix_2f_2r_to_stereo(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1217 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1218 case AC3_OUTPUT_DOLBY:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1219 mix_2f_2r_to_dolby(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1220 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1221 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1222 break;
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1223 case AC3_ACMOD_3F2R:
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1224 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1225 case AC3_OUTPUT_MONO:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1226 mix_3f_2r_to_mono(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1227 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1228 case AC3_OUTPUT_STEREO:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1229 mix_3f_2r_to_stereo(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1230 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1231 case AC3_OUTPUT_DOLBY:
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1232 mix_3f_2r_to_dolby(ctx);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1233 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1234 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1235 break;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1236 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1237 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1238
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1239 /* This function performs the imdct on 256 sample transform
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1240 * coefficients.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1241 */
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1242 static void do_imdct_256(AC3DecodeContext *ctx, int chindex)
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1243 {
5336
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1244 int i, k;
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1245 float x[128];
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1246 FFTComplex z[2][64];
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1247 float *o_ptr = ctx->tmp_output;
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1248
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1249 for(i=0; i<2; i++) {
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1250 /* de-interleave coefficients */
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1251 for(k=0; k<128; k++) {
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1252 x[k] = ctx->transform_coeffs[chindex][2*k+i];
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1253 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1254
5336
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1255 /* run standard IMDCT */
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1256 ctx->imdct_256.fft.imdct_calc(&ctx->imdct_256, o_ptr, x, ctx->tmp_imdct);
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1257
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1258 /* reverse the post-rotation & reordering from standard IMDCT */
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1259 for(k=0; k<32; k++) {
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1260 z[i][32+k].re = -o_ptr[128+2*k];
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1261 z[i][32+k].im = -o_ptr[2*k];
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1262 z[i][31-k].re = o_ptr[2*k+1];
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1263 z[i][31-k].im = o_ptr[128+2*k+1];
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1264 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1265 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1266
5336
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1267 /* apply AC-3 post-rotation & reordering */
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1268 for(k=0; k<64; k++) {
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1269 o_ptr[ 2*k ] = -z[0][ k].im;
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1270 o_ptr[ 2*k+1] = z[0][63-k].re;
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1271 o_ptr[128+2*k ] = -z[0][ k].re;
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1272 o_ptr[128+2*k+1] = z[0][63-k].im;
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1273 o_ptr[256+2*k ] = -z[1][ k].re;
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1274 o_ptr[256+2*k+1] = z[1][63-k].im;
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1275 o_ptr[384+2*k ] = z[1][ k].im;
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1276 o_ptr[384+2*k+1] = -z[1][63-k].re;
5322
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1277 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1278 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1279
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1280 /* IMDCT Transform. */
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1281 static inline void do_imdct(AC3DecodeContext *ctx)
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1282 {
5336
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1283 int ch;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1284
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1285 if (ctx->blkoutput & AC3_OUTPUT_LFEON) {
5336
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1286 ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output,
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1287 ctx->transform_coeffs[0], ctx->tmp_imdct);
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1288 }
5336
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1289 for (ch=1; ch<=ctx->nfchans; ch++) {
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1290 if ((ctx->blksw >> (ch-1)) & 1)
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1291 do_imdct_256(ctx, ch);
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1292 else
5336
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1293 ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output,
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1294 ctx->transform_coeffs[ch],
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1295 ctx->tmp_imdct);
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1296
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1297 ctx->dsp.vector_fmul_add_add(ctx->output[ch], ctx->tmp_output,
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1298 ctx->window, ctx->delay[ch], 384, 256, 1);
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1299 ctx->dsp.vector_fmul_reverse(ctx->delay[ch], ctx->tmp_output+256,
cc3f5a28aa2a fix the 256-point MDCT
jbr
parents: 5335
diff changeset
1300 ctx->window, 256);
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1301 }
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1302 }
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1303
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1304 /* Parse the audio block from ac3 bitstream.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1305 * This function extract the audio block from the ac3 bitstream
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1306 * and produces the output for the block. This function must
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1307 * be called for each of the six audio block in the ac3 bitstream.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1308 */
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1309 static int ac3_parse_audio_block(AC3DecodeContext *ctx, int blk)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1310 {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1311 int nfchans = ctx->nfchans;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1312 int acmod = ctx->acmod;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1313 int i, bnd, rbnd, seg, grpsize;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1314 GetBitContext *gb = &ctx->gb;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1315 int bit_alloc_flags = 0;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1316 uint8_t *dexps;
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1317 int mstrcplco, cplcoexp, cplcomant;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1318 int dynrng, chbwcod, ngrps, cplabsexp, skipl;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1319
5312
2c875e6274d5 AC-3 decoder, soc revision 52, Aug 16 22:45:07 2006 UTC by cloud9
jbr
parents: 5311
diff changeset
1320 ctx->blksw = 0;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1321 for (i = 0; i < nfchans; i++) /*block switch flag */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1322 ctx->blksw |= get_bits1(gb) << i;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1323
5312
2c875e6274d5 AC-3 decoder, soc revision 52, Aug 16 22:45:07 2006 UTC by cloud9
jbr
parents: 5311
diff changeset
1324 ctx->dithflag = 0;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1325 for (i = 0; i < nfchans; i++) /* dithering flag */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1326 ctx->dithflag |= get_bits1(gb) << i;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1327
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1328 if (get_bits1(gb)) { /* dynamic range */
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1329 dynrng = get_sbits(gb, 8);
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
1330 ctx->dynrng = ((((dynrng & 0x1f) | 0x20) << 13) * scale_factors[3 - (dynrng >> 5)]);
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1331 } else if(blk == 0) {
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1332 ctx->dynrng = 1.0;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1333 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1334
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1335 if(acmod == AC3_ACMOD_DUALMONO) { /* dynamic range 1+1 mode */
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1336 if(get_bits1(gb)) {
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1337 dynrng = get_sbits(gb, 8);
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
1338 ctx->dynrng2 = ((((dynrng & 0x1f) | 0x20) << 13) * scale_factors[3 - (dynrng >> 5)]);
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1339 } else if(blk == 0) {
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1340 ctx->dynrng2 = 1.0;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1341 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1342 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1343
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1344 get_downmix_coeffs(ctx);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1345
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1346 if (get_bits1(gb)) { /* coupling strategy */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1347 ctx->cplinu = get_bits1(gb);
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1348 ctx->cplbndstrc = 0;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1349 ctx->chincpl = 0;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1350 if (ctx->cplinu) { /* coupling in use */
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1351 for (i = 0; i < nfchans; i++)
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1352 ctx->chincpl |= get_bits1(gb) << i;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1353
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1354 if (acmod == 0x02)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1355 ctx->phsflginu = get_bits1(gb); //phase flag in use
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1356
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1357 ctx->cplbegf = get_bits(gb, 4);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1358 ctx->cplendf = get_bits(gb, 4);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1359
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1360 if (3 + ctx->cplendf - ctx->cplbegf < 0) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1361 av_log(NULL, AV_LOG_ERROR, "cplendf = %d < cplbegf = %d\n", ctx->cplendf, ctx->cplbegf);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1362 return -1;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1363 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1364
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1365 ctx->ncplbnd = ctx->ncplsubnd = 3 + ctx->cplendf - ctx->cplbegf;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1366 ctx->cplstrtmant = ctx->cplbegf * 12 + 37;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1367 ctx->cplendmant = ctx->cplendf * 12 + 73;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1368 for (i = 0; i < ctx->ncplsubnd - 1; i++) /* coupling band structure */
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1369 if (get_bits1(gb)) {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1370 ctx->cplbndstrc |= 1 << i;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1371 ctx->ncplbnd--;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1372 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1373 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1374 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1375
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1376 if (ctx->cplinu) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1377 ctx->cplcoe = 0;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1378
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1379 for (i = 0; i < nfchans; i++)
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1380 if ((ctx->chincpl) >> i & 1)
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1381 if (get_bits1(gb)) { /* coupling co-ordinates */
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1382 ctx->cplcoe |= 1 << i;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1383 mstrcplco = 3 * get_bits(gb, 2);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1384 for (bnd = 0; bnd < ctx->ncplbnd; bnd++) {
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1385 cplcoexp = get_bits(gb, 4);
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1386 cplcomant = get_bits(gb, 4);
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1387 if (cplcoexp == 15)
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1388 cplcomant <<= 14;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1389 else
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1390 cplcomant = (cplcomant | 0x10) << 13;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1391 ctx->cplco[i][bnd] = cplcomant * scale_factors[cplcoexp + mstrcplco];
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1392 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1393 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1394
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1395 if (acmod == 0x02 && ctx->phsflginu && (ctx->cplcoe & 1 || ctx->cplcoe & 2))
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1396 for (bnd = 0; bnd < ctx->ncplbnd; bnd++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1397 if (get_bits1(gb))
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1398 ctx->cplco[1][bnd] = -ctx->cplco[1][bnd];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1399 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1400
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1401 if (acmod == 0x02) {/* rematrixing */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1402 ctx->rematstr = get_bits1(gb);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1403 if (ctx->rematstr) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1404 ctx->rematflg = 0;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1405
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1406 if (!(ctx->cplinu) || ctx->cplbegf > 2)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1407 for (rbnd = 0; rbnd < 4; rbnd++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1408 ctx->rematflg |= get_bits1(gb) << rbnd;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1409 if (ctx->cplbegf > 0 && ctx->cplbegf <= 2 && ctx->cplinu)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1410 for (rbnd = 0; rbnd < 3; rbnd++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1411 ctx->rematflg |= get_bits1(gb) << rbnd;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1412 if (ctx->cplbegf == 0 && ctx->cplinu)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1413 for (rbnd = 0; rbnd < 2; rbnd++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1414 ctx->rematflg |= get_bits1(gb) << rbnd;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1415 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1416 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1417
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1418 ctx->cplexpstr = EXP_REUSE;
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1419 ctx->lfeexpstr = EXP_REUSE;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1420 if (ctx->cplinu) /* coupling exponent strategy */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1421 ctx->cplexpstr = get_bits(gb, 2);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1422 for (i = 0; i < nfchans; i++) /* channel exponent strategy */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1423 ctx->chexpstr[i] = get_bits(gb, 2);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1424 if (ctx->lfeon) /* lfe exponent strategy */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1425 ctx->lfeexpstr = get_bits1(gb);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1426
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1427 for (i = 0; i < nfchans; i++) /* channel bandwidth code */
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1428 if (ctx->chexpstr[i] != EXP_REUSE) {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1429 if ((ctx->chincpl >> i) & 1)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1430 ctx->endmant[i] = ctx->cplstrtmant;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1431 else {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1432 chbwcod = get_bits(gb, 6);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1433 if (chbwcod > 60) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1434 av_log(NULL, AV_LOG_ERROR, "chbwcod = %d > 60", chbwcod);
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1435 return -1;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1436 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1437 ctx->endmant[i] = chbwcod * 3 + 73;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1438 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1439 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1440
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1441 if (ctx->cplexpstr != EXP_REUSE) {/* coupling exponents */
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1442 bit_alloc_flags = 64;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1443 cplabsexp = get_bits(gb, 4) << 1;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1444 ngrps = (ctx->cplendmant - ctx->cplstrtmant) / (3 << (ctx->cplexpstr - 1));
5375
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
1445 decode_exponents(gb, ctx->cplexpstr, ngrps, cplabsexp, ctx->dcplexps + ctx->cplstrtmant);
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1446 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1447
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1448 for (i = 0; i < nfchans; i++) /* fbw channel exponents */
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1449 if (ctx->chexpstr[i] != EXP_REUSE) {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1450 bit_alloc_flags |= 1 << i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1451 grpsize = 3 << (ctx->chexpstr[i] - 1);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1452 ngrps = (ctx->endmant[i] + grpsize - 4) / grpsize;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1453 dexps = ctx->dexps[i];
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1454 dexps[0] = get_bits(gb, 4);
5375
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
1455 decode_exponents(gb, ctx->chexpstr[i], ngrps, dexps[0], dexps + 1);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1456 skip_bits(gb, 2); /* skip gainrng */
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1457 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1458
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1459 if (ctx->lfeexpstr != EXP_REUSE) { /* lfe exponents */
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1460 bit_alloc_flags |= 32;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1461 ctx->dlfeexps[0] = get_bits(gb, 4);
5375
7659a1acfba4 new implementation of exponent decoding
jbr
parents: 5374
diff changeset
1462 decode_exponents(gb, ctx->lfeexpstr, 2, ctx->dlfeexps[0], ctx->dlfeexps + 1);
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1463 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1464
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1465 if (get_bits1(gb)) { /* bit allocation information */
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1466 bit_alloc_flags = 127;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1467 ctx->sdcycod = get_bits(gb, 2);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1468 ctx->fdcycod = get_bits(gb, 2);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1469 ctx->sgaincod = get_bits(gb, 2);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1470 ctx->dbpbcod = get_bits(gb, 2);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1471 ctx->floorcod = get_bits(gb, 3);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1472 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1473
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1474 if (get_bits1(gb)) { /* snroffset */
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1475 bit_alloc_flags = 127;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1476 ctx->csnroffst = get_bits(gb, 6);
5323
4ba6d8132f36 AC-3 decoder, soc revision 109, Sep 22 22:42:54 2006 UTC by banan
jbr
parents: 5322
diff changeset
1477 if (ctx->cplinu) { /* coupling fine snr offset and fast gain code */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1478 ctx->cplfsnroffst = get_bits(gb, 4);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1479 ctx->cplfgaincod = get_bits(gb, 3);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1480 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1481 for (i = 0; i < nfchans; i++) { /* channel fine snr offset and fast gain code */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1482 ctx->fsnroffst[i] = get_bits(gb, 4);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1483 ctx->fgaincod[i] = get_bits(gb, 3);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1484 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1485 if (ctx->lfeon) { /* lfe fine snr offset and fast gain code */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1486 ctx->lfefsnroffst = get_bits(gb, 4);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1487 ctx->lfefgaincod = get_bits(gb, 3);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1488 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1489 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1490
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1491 if (ctx->cplinu && get_bits1(gb)) { /* coupling leak information */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1492 bit_alloc_flags |= 64;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1493 ctx->cplfleak = get_bits(gb, 3);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1494 ctx->cplsleak = get_bits(gb, 3);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1495 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1496
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1497 if (get_bits1(gb)) { /* delta bit allocation information */
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1498 bit_alloc_flags = 127;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1499
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1500 if (ctx->cplinu) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1501 ctx->cpldeltbae = get_bits(gb, 2);
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1502 if (ctx->cpldeltbae == DBA_RESERVED) {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1503 av_log(NULL, AV_LOG_ERROR, "coupling delta bit allocation strategy reserved\n");
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1504 return -1;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1505 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1506 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1507
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1508 for (i = 0; i < nfchans; i++) {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1509 ctx->deltbae[i] = get_bits(gb, 2);
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1510 if (ctx->deltbae[i] == DBA_RESERVED) {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1511 av_log(NULL, AV_LOG_ERROR, "delta bit allocation strategy reserved\n");
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1512 return -1;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1513 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1514 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1515
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1516 if (ctx->cplinu)
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1517 if (ctx->cpldeltbae == DBA_NEW) { /*coupling delta offset, len and bit allocation */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1518 ctx->cpldeltnseg = get_bits(gb, 3);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1519 for (seg = 0; seg <= ctx->cpldeltnseg; seg++) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1520 ctx->cpldeltoffst[seg] = get_bits(gb, 5);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1521 ctx->cpldeltlen[seg] = get_bits(gb, 4);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1522 ctx->cpldeltba[seg] = get_bits(gb, 3);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1523 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1524 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1525
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1526 for (i = 0; i < nfchans; i++)
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1527 if (ctx->deltbae[i] == DBA_NEW) {/*channel delta offset, len and bit allocation */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1528 ctx->deltnseg[i] = get_bits(gb, 3);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1529 for (seg = 0; seg <= ctx->deltnseg[i]; seg++) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1530 ctx->deltoffst[i][seg] = get_bits(gb, 5);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1531 ctx->deltlen[i][seg] = get_bits(gb, 4);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1532 ctx->deltba[i][seg] = get_bits(gb, 3);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1533 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1534 }
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1535 } else if(blk == 0) {
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1536 if(ctx->cplinu)
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1537 ctx->cpldeltbae = DBA_NONE;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1538 for(i=0; i<nfchans; i++) {
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1539 ctx->deltbae[i] = DBA_NONE;
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1540 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1541 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1542
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1543 if (bit_alloc_flags) {
5374
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1544 /* set bit allocation parameters */
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1545 ctx->bit_alloc_params.sdecay = ff_sdecaytab[ctx->sdcycod];
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1546 ctx->bit_alloc_params.fdecay = ff_fdecaytab[ctx->fdcycod];
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1547 ctx->bit_alloc_params.sgain = ff_sgaintab[ctx->sgaincod];
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1548 ctx->bit_alloc_params.dbknee = ff_dbkneetab[ctx->dbpbcod];
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1549 ctx->bit_alloc_params.floor = ff_floortab[ctx->floorcod];
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1550 ctx->bit_alloc_params.cplfleak = ctx->cplfleak;
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1551 ctx->bit_alloc_params.cplsleak = ctx->cplsleak;
5335
8ecef197b08e use shared ac3 bit allocation function
jbr
parents: 5334
diff changeset
1552
5374
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1553 if (ctx->chincpl && (bit_alloc_flags & 64))
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1554 do_bit_allocation(ctx, 5);
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1555 for (i = 0; i < nfchans; i++)
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1556 if ((bit_alloc_flags >> i) & 1)
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1557 do_bit_allocation(ctx, i);
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1558 if (ctx->lfeon && (bit_alloc_flags & 32))
eb7a01d0fe2c cosmetics: indentation
jbr
parents: 5373
diff changeset
1559 do_bit_allocation(ctx, 6);
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1560 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1561
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1562 if (get_bits1(gb)) { /* unused dummy data */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1563 skipl = get_bits(gb, 9);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1564 while(skipl--)
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1565 skip_bits(gb, 8);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1566 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1567 /* unpack the transform coefficients
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1568 * * this also uncouples channels if coupling is in use.
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1569 */
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1570 if (get_transform_coeffs(ctx)) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1571 av_log(NULL, AV_LOG_ERROR, "Error in routine get_transform_coeffs\n");
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1572 return -1;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1573 }
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1574
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1575 /* recover coefficients if rematrixing is in use */
5312
2c875e6274d5 AC-3 decoder, soc revision 52, Aug 16 22:45:07 2006 UTC by cloud9
jbr
parents: 5311
diff changeset
1576 if (ctx->rematflg)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1577 do_rematrixing(ctx);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1578
5318
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1579 do_downmix(ctx);
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1580
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1581 do_imdct(ctx);
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1582
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1583 return 0;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1584 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1585
5318
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1586 static inline int16_t convert(int32_t i)
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1587 {
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1588 if (i > 0x43c07fff)
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1589 return 32767;
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1590 else if (i <= 0x43bf8000)
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1591 return -32768;
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1592 else
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1593 return (i - 0x43c00000);
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1594 }
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1595
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1596 /* Decode ac3 frame.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1597 *
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1598 * @param avctx Pointer to AVCodecContext
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1599 * @param data Pointer to pcm smaples
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1600 * @param data_size Set to number of pcm samples produced by decoding
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1601 * @param buf Data to be decoded
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1602 * @param buf_size Size of the buffer
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1603 */
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1604 static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1605 {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1606 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1607 int16_t *out_samples = (int16_t *)data;
5318
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1608 int i, j, k, start;
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1609 int32_t *int_ptr[6];
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1610
5318
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1611 for (i = 0; i < 6; i++)
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1612 int_ptr[i] = (int32_t *)(&ctx->output[i]);
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1613
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1614 //Initialize the GetBitContext with the start of valid AC3 Frame.
5385
bc14cca988aa don't need to synchronize in the decoder. the parser does that already.
jbr
parents: 5384
diff changeset
1615 init_get_bits(&ctx->gb, buf, buf_size * 8);
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1616
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1617 //Parse the syncinfo.
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1618 if (ac3_parse_header(ctx)) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1619 av_log(avctx, AV_LOG_ERROR, "\n");
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1620 *data_size = 0;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1621 return buf_size;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1622 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1623
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1624 avctx->sample_rate = ctx->sampling_rate;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1625 avctx->bit_rate = ctx->bit_rate;
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1626
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1627 if (avctx->channels == 0) {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1628 ctx->blkoutput |= AC3_OUTPUT_UNMODIFIED;
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1629 if (ctx->lfeon)
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1630 ctx->blkoutput |= AC3_OUTPUT_LFEON;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1631 avctx->channels = ctx->nfchans + ctx->lfeon;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1632 }
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1633 else if (avctx->channels == 1)
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1634 ctx->blkoutput |= AC3_OUTPUT_MONO;
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1635 else if (avctx->channels == 2) {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1636 if (ctx->dsurmod == 0x02)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1637 ctx->blkoutput |= AC3_OUTPUT_DOLBY;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1638 else
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1639 ctx->blkoutput |= AC3_OUTPUT_STEREO;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1640 }
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1641 else {
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1642 if (avctx->channels < (ctx->nfchans + ctx->lfeon))
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1643 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);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1644 ctx->blkoutput |= AC3_OUTPUT_UNMODIFIED;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1645 if (ctx->lfeon)
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1646 ctx->blkoutput |= AC3_OUTPUT_LFEON;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1647 avctx->channels = ctx->nfchans + ctx->lfeon;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1648 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1649
5318
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1650 //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);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1651
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1652 //Parse the Audio Blocks.
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1653 for (i = 0; i < NB_BLOCKS; i++) {
5386
d6347c3cb329 Use shared AC-3 header parsing. Move some initializations to block parsing function.
jbr
parents: 5385
diff changeset
1654 if (ac3_parse_audio_block(ctx, i)) {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1655 av_log(avctx, AV_LOG_ERROR, "error parsing the audio block\n");
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1656 *data_size = 0;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1657 return ctx->frame_size;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1658 }
5318
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1659 start = (ctx->blkoutput & AC3_OUTPUT_LFEON) ? 0 : 1;
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1660 for (k = 0; k < BLOCK_SIZE; k++)
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1661 for (j = start; j <= avctx->channels; j++)
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1662 *(out_samples++) = convert(int_ptr[j][k]);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1663 }
5331
b24bcdd0ae86 move some common values to ac3.h and utilize them
jbr
parents: 5330
diff changeset
1664 *data_size = NB_BLOCKS * BLOCK_SIZE * avctx->channels * sizeof (int16_t);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1665 return ctx->frame_size;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1666 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1667
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1668 /* Uninitialize ac3 decoder.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1669 */
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1670 static int ac3_decode_end(AVCodecContext *avctx)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1671 {
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1672 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data;
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1673 ff_mdct_end(&ctx->imdct_512);
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1674 ff_mdct_end(&ctx->imdct_256);
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1675
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1676 return 0;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1677 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1678
5334
d406baea3275 no need for the decoder to have the license as a prefix
jbr
parents: 5333
diff changeset
1679 AVCodec ac3_decoder = {
5315
31033309ebc9 AC-3 decoder, soc revision 55, Aug 17 12:25:24 2006 UTC by cloud9
jbr
parents: 5314
diff changeset
1680 .name = "ac3",
31033309ebc9 AC-3 decoder, soc revision 55, Aug 17 12:25:24 2006 UTC by cloud9
jbr
parents: 5314
diff changeset
1681 .type = CODEC_TYPE_AUDIO,
31033309ebc9 AC-3 decoder, soc revision 55, Aug 17 12:25:24 2006 UTC by cloud9
jbr
parents: 5314
diff changeset
1682 .id = CODEC_ID_AC3,
31033309ebc9 AC-3 decoder, soc revision 55, Aug 17 12:25:24 2006 UTC by cloud9
jbr
parents: 5314
diff changeset
1683 .priv_data_size = sizeof (AC3DecodeContext),
31033309ebc9 AC-3 decoder, soc revision 55, Aug 17 12:25:24 2006 UTC by cloud9
jbr
parents: 5314
diff changeset
1684 .init = ac3_decode_init,
31033309ebc9 AC-3 decoder, soc revision 55, Aug 17 12:25:24 2006 UTC by cloud9
jbr
parents: 5314
diff changeset
1685 .close = ac3_decode_end,
31033309ebc9 AC-3 decoder, soc revision 55, Aug 17 12:25:24 2006 UTC by cloud9
jbr
parents: 5314
diff changeset
1686 .decode = ac3_decode_frame,
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1687 };
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1688