annotate ac3dec.c @ 5328:5f83f09bd748 libavcodec

revise license header for simplicity and consistency
author jbr
date Sat, 14 Jul 2007 18:53:56 +0000
parents 923aacd40ee8
children 06e7dda51f65
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).
5316
a09b700fcfca AC-3 decoder, soc revision 56, Aug 17 14:21:58 2006 UTC by cloud9
jbr
parents: 5315
diff changeset
6 *
5323
4ba6d8132f36 AC-3 decoder, soc revision 109, Sep 22 22:42:54 2006 UTC by banan
jbr
parents: 5322
diff changeset
7 * For exponent decoding the code is inspired by the code in liba52 by
4ba6d8132f36 AC-3 decoder, soc revision 109, Sep 22 22:42:54 2006 UTC by banan
jbr
parents: 5322
diff changeset
8 * Michel Lespinasse and Aaron Holtzman.
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
a09b700fcfca AC-3 decoder, soc revision 56, Aug 17 14:21:58 2006 UTC by cloud9
jbr
parents: 5315
diff changeset
10 *
5328
5f83f09bd748 revise license header for simplicity and consistency
jbr
parents: 5326
diff changeset
11 * The Mersenne Twister is based on code written by Makoto Matsumoto and
5f83f09bd748 revise license header for simplicity and consistency
jbr
parents: 5326
diff changeset
12 * Takuji Nishimura.
5316
a09b700fcfca AC-3 decoder, soc revision 56, Aug 17 14:21:58 2006 UTC by cloud9
jbr
parents: 5315
diff changeset
13 *
5328
5f83f09bd748 revise license header for simplicity and consistency
jbr
parents: 5326
diff changeset
14 * 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
15 *
5328
5f83f09bd748 revise license header for simplicity and consistency
jbr
parents: 5326
diff changeset
16 * FFmpeg is free software; you can redistribute it and/or
5f83f09bd748 revise license header for simplicity and consistency
jbr
parents: 5326
diff changeset
17 * modify it 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
18 * 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
19 * 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
20 *
5328
5f83f09bd748 revise license header for simplicity and consistency
jbr
parents: 5326
diff changeset
21 * 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
22 * 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
23 * 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
24 * 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
25 *
5326
923aacd40ee8 make ac3dec.c GPL until violations are fixed
jbr
parents: 5325
diff changeset
26 * 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
27 * 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
28 * 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
29 */
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
30
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
31 #include <stdio.h>
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
32 #include <stddef.h>
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
33 #include <math.h>
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
34 #include <string.h>
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
35
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
36 #define ALT_BITSTREAM_READER
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
37
5315
31033309ebc9 AC-3 decoder, soc revision 55, Aug 17 12:25:24 2006 UTC by cloud9
jbr
parents: 5314
diff changeset
38 #include "avcodec.h"
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
39 #include "ac3tab.h"
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
40 #include "bitstream.h"
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
41 #include "dsputil.h"
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
42
5325
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
43 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
44
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
45 /* 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
46 * 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
47 */
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
48 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
49
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
50 static int16_t psdtab[25];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
51
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
52 static int8_t exp_1[128];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
53 static int8_t exp_2[128];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
54 static int8_t exp_3[128];
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
55
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 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
57 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
58 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
59
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
60 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
61 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
62 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
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 l7_quantizers[7];
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 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
67 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
68
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
69 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
70
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
71 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
72
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
73 /* 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
74 #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
75 #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
76 #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
77 #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
78 #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
79 #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
80
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
81 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
82 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
83
0d963101e0d7 AC-3 decoder, soc revision 402, Jul 14 13:45:14 2007 UTC by jbr
jbr
parents: 5324
diff changeset
84 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
85
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
86 #define N 512 /* constant for IMDCT Block size */
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
87
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
88 #define MAX_CHANNELS 6
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
89 #define BLOCK_SIZE 256
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
90 #define AUDIO_BLOCKS 6
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
91
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
92 /* Exponent strategies. */
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
93 #define AC3_EXPSTR_D15 0x01
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
94 #define AC3_EXPSTR_D25 0x02
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
95 #define AC3_EXPSTR_D45 0x03
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
96 #define AC3_EXPSTR_REUSE 0x00
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
97
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
98 /* Bit allocation strategies. */
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
99 #define AC3_DBASTR_NEW 0x01
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
100 #define AC3_DBASTR_NONE 0x02
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
101 #define AC3_DBASTR_RESERVED 0x03
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
102 #define AC3_DBASTR_REUSE 0x00
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
103
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
104 /* 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
105 #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
106 #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
107 #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
108 #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
109 #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
110
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
111 #define AC3_INPUT_DUALMONO 0x00
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
112 #define AC3_INPUT_MONO 0x01
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
113 #define AC3_INPUT_STEREO 0x02
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
114 #define AC3_INPUT_3F 0x03
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
115 #define AC3_INPUT_2F_1R 0x04
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
116 #define AC3_INPUT_3F_1R 0x05
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
117 #define AC3_INPUT_2F_2R 0x06
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
118 #define AC3_INPUT_3F_2R 0x07
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
119
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
120 /* Mersenne Twister */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
121 #define NMT 624
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
122 #define MMT 397
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
123 #define MATRIX_A 0x9908b0df
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
124 #define UPPER_MASK 0x80000000
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
125 #define LOWER_MASK 0x7fffffff
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
126
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
127
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
128 typedef struct {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
129 uint32_t mt[NMT];
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
130 int mti;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
131 } dither_state;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
132 /* Mersenne Twister */
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
133
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
134 typedef struct {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
135 uint16_t crc1;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
136 uint8_t fscod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
137
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
138 uint8_t acmod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
139 uint8_t cmixlev;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
140 uint8_t surmixlev;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
141 uint8_t dsurmod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
142
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
143 uint8_t blksw;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
144 uint8_t dithflag;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
145 uint8_t cplinu;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
146 uint8_t chincpl;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
147 uint8_t phsflginu;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
148 uint8_t cplbegf;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
149 uint8_t cplendf;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
150 uint8_t cplcoe;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
151 uint32_t cplbndstrc;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
152 uint8_t rematstr;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
153 uint8_t rematflg;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
154 uint8_t cplexpstr;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
155 uint8_t lfeexpstr;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
156 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
157 uint8_t sdcycod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
158 uint8_t fdcycod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
159 uint8_t sgaincod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
160 uint8_t dbpbcod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
161 uint8_t floorcod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
162 uint8_t csnroffst;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
163 uint8_t cplfsnroffst;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
164 uint8_t cplfgaincod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
165 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
166 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
167 uint8_t lfefsnroffst;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
168 uint8_t lfefgaincod;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
169 uint8_t cplfleak;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
170 uint8_t cplsleak;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
171 uint8_t cpldeltbae;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
172 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
173 uint8_t cpldeltnseg;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
174 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
175 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
176 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
177 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
178 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
179 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
180 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
181
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
182 /* Derived Attributes. */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
183 int sampling_rate;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
184 int bit_rate;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
185 int frame_size;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
186
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
187 int nfchans; //number of channels
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
188 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
189
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
190 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
191 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
192 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
193 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
194 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
195 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
196 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
197 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
198 int endmant[5]; //channel end mantissas
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
199
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
200 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
201 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
202 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
203 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
204 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
205 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
206
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
207 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
208
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
209 DECLARE_ALIGNED_16(float, transform_coeffs[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
210
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
211 /* For IMDCT. */
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
212 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
213 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
214 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
215
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
216 DECLARE_ALIGNED_16(float, output[MAX_CHANNELS][BLOCK_SIZE]); //output after imdct transform and windowing
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
217 DECLARE_ALIGNED_16(float, delay[MAX_CHANNELS][BLOCK_SIZE]); //delay - added to the next block
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
218 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
219 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
220 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
221
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
222 /* Miscellaneous. */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
223 GetBitContext gb;
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
224 dither_state 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
225 } AC3DecodeContext;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
226
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 /* BEGIN Mersenne Twister Code. */
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
229 static void dither_seed(dither_state *state, uint32_t seed)
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
230 {
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
231 static const uint32_t mag01[2] = { 0x00, MATRIX_A };
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
232 uint32_t y;
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
233 int kk;
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
234
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
235 if (seed == 0)
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
236 seed = 0x7ba05e; //default seed to my birthday!
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
237
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
238 state->mt[0] = seed;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
239 for (state->mti = 1; state->mti < NMT; state->mti++)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
240 state->mt[state->mti] = ((69069 * state->mt[state->mti - 1]) + 1);
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
241
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
242 for (kk = 0; kk < NMT - MMT; kk++) {
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
243 y = (state->mt[kk] & UPPER_MASK) | (state->mt[kk + 1] & LOWER_MASK);
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
244 state->mt[kk] = state->mt[kk + MMT] ^ (y >> 1) ^ mag01[y & 0x01];
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
245 }
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
246 for (;kk < NMT - 1; kk++) {
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
247 y = (state->mt[kk] & UPPER_MASK) | (state->mt[kk + 1] & LOWER_MASK);
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
248 state->mt[kk] = state->mt[kk + (MMT - NMT)] ^ (y >> 1) ^ mag01[y & 0x01];
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
249 }
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
250 y = (state->mt[NMT - 1] & UPPER_MASK) | (state->mt[0] & LOWER_MASK);
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
251 state->mt[NMT - 1] = state->mt[MMT - 1] ^ (y >> 1) ^ mag01[y & 0x01];
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
252
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
253 state->mti = 0;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
254 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
255
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
256 static int16_t dither_int16(dither_state *state)
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
257 {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
258 uint32_t y;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
259
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
260 if (state->mti >= NMT)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
261 state->mti = 0;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
262
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
263 y = state->mt[state->mti++];
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
264 y ^= (y >> 11);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
265 y ^= ((y << 7) & 0x9d2c5680);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
266 y ^= ((y << 15) & 0xefc60000);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
267 y ^= (y >> 18);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
268
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
269 return ((y << 16) >> 16);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
270 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
271 /* END Mersenne Twister */
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
272
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
273 /*********** 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
274 /**
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
275 * 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
276 */
5320
3348a76efb67 AC-3 decoder, soc revision 70, Aug 31 18:04:23 2006 UTC by banan
jbr
parents: 5319
diff changeset
277 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
278 {
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
279 int i, j;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
280 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
281 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
282 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
283
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
284 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
285 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
286 bessel = 1.0;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
287 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
288 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
289 sum += bessel;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
290 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
291 }
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
292
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
293 sum++;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
294 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
295 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
296 }
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
297
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
298 /*
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
299 * Generate quantizer tables.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
300 */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
301 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
302 {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
303 int i;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
304
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
305 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
306 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
307 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
308
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
309 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
310 {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
311 int i, j;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
312 int16_t v;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
313
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
314 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
315 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
316 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
317 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
318 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
319
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
320 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
321 quantizers[i] = 0;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
322 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
323
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
324 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
325 {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
326 int i, j;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
327 int16_t v;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
328
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
329 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
330 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
331 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
332 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
333 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
334
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
335 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
336 quantizers[i] = 0;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
337
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
338 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
339
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
340 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
341 {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
342 int i, j;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
343
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
344 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
345 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
346 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
347
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
348 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
349 quantizers[i] = 0;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
350 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
351
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
352 /*
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
353 * 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
354 */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
355 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
356 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
357 int i, j, k, l, v;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
358 /* compute bndtab and masktab from bandsz */
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
359 k = 0;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
360 l = 0;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
361 for(i=0;i<50;i++) {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
362 bndtab[i] = l;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
363 v = bndsz[i];
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
364 for(j=0;j<v;j++) masktab[k++]=i;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
365 l += v;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
366 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
367 masktab[253] = masktab[254] = masktab[255] = 0;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
368 bndtab[50] = 0;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
369
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
370 /* PSD Table For Mapping Exponents To PSD. */
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
371 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
372 psdtab[i] = 3072 - (i << 7);
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
373
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
374 /* Exponent Decoding Tables */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
375 for (i = 0; i < 5; i++) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
376 v = i - 2;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
377 for (j = 0; j < 25; j++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
378 exp_1[i * 25 + j] = v;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
379 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
380
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
381 for (i = 0; i < 25; i++) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
382 v = (i % 5) - 2;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
383 for (j = 0; j < 5; j++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
384 exp_2[i * 5 + j] = v;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
385 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
386
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
387 for (i = 0; i < 25; i++) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
388 v = -2;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
389 for (j = 0; j < 5; j++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
390 exp_3[i * 5 + j] = v++;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
391 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
392
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
393 for (i = 125; i < 128; i++)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
394 exp_1[i] = exp_2[i] = exp_3[i] = 25;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
395 /* End Exponent Decoding Tables */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
396
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
397 /* Quantizer ungrouping tables. */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
398 // 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
399 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
400 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
401 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
402
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
403 //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
404 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
405 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
406 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
407
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
408 //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
409 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
410
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
411 //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
412 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
413 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
414
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
415 //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
416 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
417 /* 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
418
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
419 //generate scale factors
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
420 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
421 scale_factors[i] = pow(2.0, -(i + 15));
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
422 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
423
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
424
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
425 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
426 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
427 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
428
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
429 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
430 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
431 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
432 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
433 dsputil_init(&ctx->dsp, avctx);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
434 dither_seed(&ctx->dith_state, 0);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
435
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
436 return 0;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
437 }
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
438 /*********** 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
439
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
440 /* Synchronize to ac3 bitstream.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
441 * This function searches for the syncword '0xb77'.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
442 *
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
443 * @param buf Pointer to "probable" ac3 bitstream buffer
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
444 * @param buf_size Size of buffer
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
445 * @return Returns the position where syncword is found, -1 if no syncword is found
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
446 */
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
447 static int ac3_synchronize(uint8_t *buf, int buf_size)
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
448 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
449 int i;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
450
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
451 for (i = 0; i < buf_size - 1; i++)
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
452 if (buf[i] == 0x0b && buf[i + 1] == 0x77)
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
453 return i;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
454
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
455 return -1;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
456 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
457
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
458 /* Parse the 'sync_info' 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
459 * This function extracts the sync_info from ac3 bitstream.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
460 * 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
461 * 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
462 *
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
463 * @param ctx AC3DecodeContext
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
464 * @return Returns framesize, returns 0 if fscod, frmsizecod or bsid is not valid
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
465 */
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
466 static int ac3_parse_sync_info(AC3DecodeContext *ctx)
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
467 {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
468 GetBitContext *gb = &ctx->gb;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
469 int frmsizecod, bsid;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
470
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
471 skip_bits(gb, 16); //skip the sync_word, sync_info->sync_word = get_bits(gb, 16);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
472 ctx->crc1 = get_bits(gb, 16);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
473 ctx->fscod = 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
474 if (ctx->fscod == 0x03)
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
475 return 0;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
476 frmsizecod = 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
477 if (frmsizecod >= 38)
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
478 return 0;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
479 ctx->sampling_rate = ac3_freqs[ctx->fscod];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
480 ctx->bit_rate = ac3_bitratetab[frmsizecod >> 1];
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
481
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
482 /* we include it here in order to determine validity of ac3 frame */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
483 bsid = 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
484 if (bsid > 0x08)
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
485 return 0;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
486 skip_bits(gb, 3); //skip the bsmod, bsi->bsmod = get_bits(gb, 3);
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
487
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
488 switch (ctx->fscod) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
489 case 0x00:
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
490 ctx->frame_size = 4 * ctx->bit_rate;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
491 return ctx->frame_size;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
492 case 0x01:
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
493 ctx->frame_size = 2 * (320 * ctx->bit_rate / 147 + (frmsizecod & 1));
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
494 return ctx->frame_size;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
495 case 0x02:
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
496 ctx->frame_size = 6 * ctx->bit_rate;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
497 return ctx->frame_size;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
498 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
499
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
500 /* never reached */
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
501 return 0;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
502 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
503
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
504 /* Parse bsi from ac3 bitstream.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
505 * This function extracts the bitstream information (bsi) from ac3 bitstream.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
506 *
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
507 * @param ctx AC3DecodeContext after processed by ac3_parse_sync_info
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
508 */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
509 static void ac3_parse_bsi(AC3DecodeContext *ctx)
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
510 {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
511 GetBitContext *gb = &ctx->gb;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
512 int i;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
513
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
514 ctx->cmixlev = 0;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
515 ctx->surmixlev = 0;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
516 ctx->dsurmod = 0;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
517 ctx->nfchans = 0;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
518 ctx->cpldeltbae = AC3_DBASTR_NONE;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
519 ctx->cpldeltnseg = 0;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
520 for (i = 0; i < 5; i++) {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
521 ctx->deltbae[i] = AC3_DBASTR_NONE;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
522 ctx->deltnseg[i] = 0;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
523 }
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
524 ctx->dynrng = 1.0;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
525 ctx->dynrng2 = 1.0;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
526
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
527 ctx->acmod = 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
528 ctx->nfchans = nfchans_tbl[ctx->acmod];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
529
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
530 if (ctx->acmod & 0x01 && ctx->acmod != 0x01)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
531 ctx->cmixlev = 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
532 if (ctx->acmod & 0x04)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
533 ctx->surmixlev = 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
534 if (ctx->acmod == 0x02)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
535 ctx->dsurmod = 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
536
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
537 ctx->lfeon = get_bits1(gb);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
538
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
539 i = !(ctx->acmod);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
540 do {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
541 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
542 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
543 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
544 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
545 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
546 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
547 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
548 } while (i--);
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
549
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
550 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
551
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
552 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
553 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
554 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
555 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
556
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
557 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
558 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
559 do {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
560 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
561 } while(i--);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
562 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
563 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
564
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
565 /* Decodes the grouped exponents.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
566 * 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
567 * 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
568 *
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
569 * @param gb GetBitContext which points to start of coded exponents
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
570 * @param expstr Exponent coding strategy
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
571 * @param ngrps Number of grouped exponetns
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
572 * @param absexp Absolute exponent
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
573 * @param dexps Decoded exponents are stored in dexps
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
574 * @return Returns 0 if exponents are decoded successfully, -1 if error occurs
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
575 */
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
576 static int decode_exponents(GetBitContext *gb, int expstr, int ngrps, 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
577 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
578 int exps;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
579
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
580 while (ngrps--) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
581 exps = get_bits(gb, 7);
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
582
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
583 absexp += exp_1[exps];
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
584 if (absexp > 24) {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
585 av_log(NULL, AV_LOG_ERROR, "Absolute Exponent > 24, ngrp = %d\n", ngrps);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
586 return -ngrps;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
587 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
588 switch (expstr) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
589 case AC3_EXPSTR_D45:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
590 *(dexps++) = absexp;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
591 *(dexps++) = absexp;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
592 case AC3_EXPSTR_D25:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
593 *(dexps++) = absexp;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
594 case AC3_EXPSTR_D15:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
595 *(dexps++) = absexp;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
596 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
597
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
598 absexp += exp_2[exps];
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
599 if (absexp > 24) {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
600 av_log(NULL, AV_LOG_ERROR, "Absolute Exponent > 24, ngrp = %d\n", ngrps);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
601 return -ngrps;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
602 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
603 switch (expstr) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
604 case AC3_EXPSTR_D45:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
605 *(dexps++) = absexp;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
606 *(dexps++) = absexp;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
607 case AC3_EXPSTR_D25:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
608 *(dexps++) = absexp;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
609 case AC3_EXPSTR_D15:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
610 *(dexps++) = absexp;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
611 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
612
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
613 absexp += exp_3[exps];
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
614 if (absexp > 24) {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
615 av_log(NULL, AV_LOG_ERROR, "Absolute Exponent > 24, ngrp = %d\n", ngrps);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
616 return -ngrps;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
617 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
618 switch (expstr) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
619 case AC3_EXPSTR_D45:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
620 *(dexps++) = absexp;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
621 *(dexps++) = absexp;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
622 case AC3_EXPSTR_D25:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
623 *(dexps++) = absexp;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
624 case AC3_EXPSTR_D15:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
625 *(dexps++) = absexp;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
626 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
627 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
628
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
629 return 0;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
630 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
631
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
632 /*********** HELPER FUNCTIONS FOR BIT ALLOCATION ***********/
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
633 static inline int logadd(int a, int b)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
634 {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
635 int c = a - b;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
636 int address;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
637
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
638 address = FFMIN((ABS(c) >> 1), 255);
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
639
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
640 if (c >= 0)
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
641 return (a + latab[address]);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
642 else
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
643 return (b + latab[address]);
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
644 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
645
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
646 static inline int calc_lowcomp(int a, int b0, int b1, int bin)
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
647 {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
648 if (bin < 7) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
649 if ((b0 + 256) == b1)
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
650 a = 384;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
651 else if (b0 > b1)
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
652 a = FFMAX(0, (a - 64));
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
653 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
654 else if (bin < 20) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
655 if ((b0 + 256) == b1)
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
656 a = 320;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
657 else if (b0 > b1)
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
658 a = FFMAX(0, (a - 64));
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
659 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
660 else
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
661 a = FFMAX(0, (a - 128));
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
662
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
663 return a;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
664 }
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
665 /*********** END HELPER FUNCTIONS FOR BIT ALLOCATION ***********/
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
666
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
667 /* Performs bit allocation.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
668 * 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
669 */
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
670 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
671 {
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
672 int16_t psd[256], bndpsd[50], excite[50], mask[50], delta;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
673 int sdecay, fdecay, sgain, dbknee, floor;
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
674 int lowcomp = 0, fgain = 0, snroffset = 0, fastleak = 0, slowleak = 0, do_delta = 0;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
675 int start = 0, end = 0, bin = 0, i = 0, j = 0, k = 0, lastbin = 0, bndstrt = 0;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
676 int bndend = 0, begin = 0, deltnseg = 0, band = 0, seg = 0, address = 0;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
677 int fscod = ctx->fscod;
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
678 uint8_t *deltoffst = 0, *deltlen = 0, *deltba = 0;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
679 uint8_t *exps = 0, *bap = 0;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
680
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
681 /* initialization */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
682 sdecay = sdecaytab[ctx->sdcycod];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
683 fdecay = fdecaytab[ctx->fdcycod];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
684 sgain = sgaintab[ctx->sgaincod];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
685 dbknee = dbkneetab[ctx->dbpbcod];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
686 floor = floortab[ctx->floorcod];
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
687
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
688 if (chnl == 5) {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
689 start = ctx->cplstrtmant;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
690 end = ctx->cplendmant;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
691 fgain = fgaintab[ctx->cplfgaincod];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
692 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->cplfsnroffst) << 2;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
693 fastleak = (ctx->cplfleak << 8) + 768;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
694 slowleak = (ctx->cplsleak << 8) + 768;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
695 exps = ctx->dcplexps;
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
696 bap = ctx->cplbap;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
697 if (ctx->cpldeltbae == AC3_DBASTR_NEW || ctx->deltbae == AC3_DBASTR_REUSE) {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
698 do_delta = 1;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
699 deltnseg = ctx->cpldeltnseg;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
700 deltoffst = ctx->cpldeltoffst;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
701 deltlen = ctx->cpldeltlen;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
702 deltba = ctx->cpldeltba;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
703 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
704 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
705 else if (chnl == 6) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
706 start = 0;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
707 end = 7;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
708 lowcomp = 0;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
709 fastleak = 0;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
710 slowleak = 0;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
711 fgain = fgaintab[ctx->lfefgaincod];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
712 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->lfefsnroffst) << 2;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
713 exps = ctx->dlfeexps;
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
714 bap = ctx->lfebap;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
715 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
716 else {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
717 start = 0;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
718 end = ctx->endmant[chnl];
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
719 lowcomp = 0;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
720 fastleak = 0;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
721 slowleak = 0;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
722 fgain = fgaintab[ctx->fgaincod[chnl]];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
723 snroffset = (((ctx->csnroffst - 15) << 4) + ctx->fsnroffst[chnl]) << 2;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
724 exps = ctx->dexps[chnl];
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
725 bap = ctx->bap[chnl];
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
726 if (ctx->deltbae[chnl] == AC3_DBASTR_NEW || ctx->deltbae[chnl] == AC3_DBASTR_REUSE) {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
727 do_delta = 1;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
728 deltnseg = ctx->deltnseg[chnl];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
729 deltoffst = ctx->deltoffst[chnl];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
730 deltlen = ctx->deltlen[chnl];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
731 deltba = ctx->deltba[chnl];
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
732 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
733 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
734
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
735 for (bin = start; bin < end; bin++) /* exponent mapping into psd */
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
736 psd[bin] = psdtab[exps[bin]];
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
737
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
738 /* psd integration */
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
739 j = start;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
740 k = masktab[start];
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
741 do {
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
742 lastbin = FFMIN((bndtab[k] + bndsz[k]), end);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
743 bndpsd[k] = psd[j];
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
744 j++;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
745 for (i = j; i < lastbin; i++) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
746 bndpsd[k] = logadd(bndpsd[k], psd[j]);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
747 j++;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
748 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
749 k++;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
750 } while (end > lastbin);
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
751
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
752 /* compute the excite function */
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
753 bndstrt = masktab[start];
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
754 bndend = masktab[end - 1] + 1;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
755 if (bndstrt == 0) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
756 lowcomp = calc_lowcomp(lowcomp, bndpsd[0], bndpsd[1], 0);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
757 excite[0] = bndpsd[0] - fgain - lowcomp;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
758 lowcomp = calc_lowcomp(lowcomp, bndpsd[1], bndpsd[2], 1);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
759 excite[1] = bndpsd[1] - fgain - lowcomp;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
760 begin = 7;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
761 for (bin = 2; bin < 7; bin++) {
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
762 if ((bndend != 7) || (bin != 6))
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
763 lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin + 1], bin);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
764 fastleak = bndpsd[bin] - fgain;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
765 slowleak = bndpsd[bin] - sgain;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
766 excite[bin] = fastleak - lowcomp;
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
767 if ((bndend != 7) || (bin != 6))
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
768 if (bndpsd[bin] <= bndpsd[bin + 1]) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
769 begin = bin + 1;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
770 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
771 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
772 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
773 for (bin = begin; bin < FFMIN(bndend, 22); bin++) {
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
774 if ((bndend != 7) || (bin != 6))
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
775 lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin + 1], bin);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
776 fastleak -= fdecay;
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
777 fastleak = FFMAX(fastleak, (bndpsd[bin] - fgain));
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
778 slowleak -= sdecay;
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
779 slowleak = FFMAX(slowleak, (bndpsd[bin] - sgain));
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
780 excite[bin] = FFMAX((fastleak - lowcomp), slowleak);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
781 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
782 begin = 22;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
783 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
784 else {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
785 begin = bndstrt;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
786 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
787 for (bin = begin; bin < bndend; bin++) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
788 fastleak -= fdecay;
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
789 fastleak = FFMAX(fastleak, (bndpsd[bin] - fgain));
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
790 slowleak -= sdecay;
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
791 slowleak = FFMAX(slowleak, (bndpsd[bin] - sgain));
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
792 excite[bin] = FFMAX(fastleak, slowleak);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
793 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
794
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
795 /* compute the masking curve */
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
796 for (bin = bndstrt; bin < bndend; bin++) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
797 if (bndpsd[bin] < dbknee)
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
798 excite[bin] += ((dbknee - bndpsd[bin]) >> 2);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
799 mask[bin] = FFMAX(excite[bin], hth[bin][fscod]);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
800 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
801
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
802 /* apply the delta bit allocation */
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
803 if (do_delta) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
804 band = 0;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
805 for (seg = 0; seg < deltnseg + 1; seg++) {
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
806 band += deltoffst[seg];
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
807 if (deltba[seg] >= 4)
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
808 delta = (deltba[seg] - 3) << 7;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
809 else
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
810 delta = (deltba[seg] - 4) << 7;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
811 for (k = 0; k < deltlen[seg]; k++) {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
812 mask[band] += delta;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
813 band++;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
814 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
815 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
816 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
817
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
818 /*compute the bit allocation */
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
819 i = start;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
820 j = masktab[start];
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
821 do {
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
822 lastbin = FFMIN((bndtab[j] + bndsz[j]), end);
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
823 mask[j] -= snroffset;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
824 mask[j] -= floor;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
825 if (mask[j] < 0)
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
826 mask[j] = 0;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
827 mask[j] &= 0x1fe0;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
828 mask[j] += floor;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
829 for (k = i; k < lastbin; k++) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
830 address = (psd[i] - mask[j]) >> 5;
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
831 address = FFMIN(63, (FFMAX(0, address)));
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
832 bap[i] = baptab[address];
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
833 i++;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
834 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
835 j++;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
836 } while (end > lastbin);
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
837 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
838
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
839 /* Check if snroffsets are zero. */
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
840 static int is_snr_offsets_zero(AC3DecodeContext *ctx)
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
841 {
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
842 int i;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
843
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
844 if ((ctx->csnroffst) || (ctx->cplinu && ctx->cplfsnroffst) ||
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
845 (ctx->lfeon && ctx->lfefsnroffst))
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
846 return 0;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
847
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
848 for (i = 0; i < ctx->nfchans; i++)
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
849 if (ctx->fsnroffst[i])
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
850 return 0;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
851
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
852 return 1;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
853 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
854
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
855 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
856 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
857 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
858 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
859 int l3ptr;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
860 int l5ptr;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
861 int l11ptr;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
862 } mant_groups;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
863
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
864 #define TRANSFORM_COEFF(tc, m, e, f) (tc) = (m) * (f)[(e)]
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
865
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
866 /* 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
867 * 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
868 * 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
869 * 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
870 */
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
871 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
872 {
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
873 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
874 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
875 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
876 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
877 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
878
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
879 cplbndstrc = ctx->cplbndstrc;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
880 start = ctx->cplstrtmant;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
881 bnd = 0;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
882
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
883 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
884 end = start + 12;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
885 while (cplbndstrc & 1) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
886 end += 12;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
887 cplbndstrc >>= 1;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
888 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
889 cplbndstrc >>= 1;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
890 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
891 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
892 bnd++;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
893
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
894 while (start < end) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
895 tbap = bap[start];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
896 switch(tbap) {
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
897 case 0:
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
898 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
899 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
900 if ((ctx->dithflag >> ch) & 1) {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
901 TRANSFORM_COEFF(cplcoeff, dither_int16(&ctx->dith_state), exps[start], scale_factors);
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
902 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
903 } else
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
904 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
905 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
906 start++;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
907 continue;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
908 case 1:
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
909 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
910 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
911 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
912 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
913 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
914 m->l3ptr = 0;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
915 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
916 TRANSFORM_COEFF(cplcoeff, m->l3_quantizers[m->l3ptr++], exps[start], scale_factors);
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
917 break;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
918
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
919 case 2:
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
920 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
921 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
922 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
923 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
924 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
925 m->l5ptr = 0;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
926 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
927 TRANSFORM_COEFF(cplcoeff, m->l5_quantizers[m->l5ptr++], exps[start], scale_factors);
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
928 break;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
929
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
930 case 3:
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
931 TRANSFORM_COEFF(cplcoeff, l7_quantizers[get_bits(gb, 3)], exps[start], scale_factors);
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
932 break;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
933
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
934 case 4:
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
935 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
936 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
937 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
938 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
939 m->l11ptr = 0;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
940 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
941 TRANSFORM_COEFF(cplcoeff, m->l11_quantizers[m->l11ptr++], exps[start], scale_factors);
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
942 break;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
943
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
944 case 5:
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
945 TRANSFORM_COEFF(cplcoeff, l15_quantizers[get_bits(gb, 4)], exps[start], scale_factors);
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
946 break;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
947
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
948 default:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
949 TRANSFORM_COEFF(cplcoeff, get_sbits(gb, qntztab[tbap]) << (16 - qntztab[tbap]),
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
950 exps[start], scale_factors);
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
951 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
952 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
953 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
954 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
955 start++;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
956 }
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
957 }
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
958
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
959 return 0;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
960 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
961
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
962 /* 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
963 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
964 {
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
965 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
966 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
967 uint8_t *exps;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
968 uint8_t *bap;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
969 float *coeffs;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
970 float factors[25];
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
971
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
972 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
973 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
974
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
975 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
976 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
977 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
978 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
979 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
980 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
981 } 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
982 dithflag = 0;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
983 exps = ctx->dlfeexps;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
984 bap = ctx->lfebap;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
985 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
986 end = 7;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
987 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
988
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
989
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
990 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
991 tbap = bap[i];
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
992 switch (tbap) {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
993 case 0:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
994 if (!dithflag) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
995 coeffs[i] = 0;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
996 continue;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
997 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
998 else {
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
999 TRANSFORM_COEFF(coeffs[i], dither_int16(&ctx->dith_state), exps[i], factors);
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1000 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
1001 continue;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1002 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1003
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1004 case 1:
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1005 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
1006 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
1007 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
1008 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
1009 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
1010 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
1011 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1012 TRANSFORM_COEFF(coeffs[i], m->l3_quantizers[m->l3ptr++], exps[i], factors);
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1013 continue;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1014
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1015 case 2:
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1016 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
1017 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
1018 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
1019 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
1020 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
1021 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
1022 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1023 TRANSFORM_COEFF(coeffs[i], m->l5_quantizers[m->l5ptr++], exps[i], factors);
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1024 continue;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1025
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1026 case 3:
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1027 TRANSFORM_COEFF(coeffs[i], l7_quantizers[get_bits(gb, 3)], exps[i], factors);
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1028 continue;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1029
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1030 case 4:
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1031 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
1032 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
1033 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
1034 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
1035 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
1036 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1037 TRANSFORM_COEFF(coeffs[i], m->l11_quantizers[m->l11ptr++], exps[i], factors);
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1038 continue;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1039
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1040 case 5:
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1041 TRANSFORM_COEFF(coeffs[i], l15_quantizers[get_bits(gb, 4)], exps[i], factors);
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1042 continue;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1043
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1044 default:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1045 TRANSFORM_COEFF(coeffs[i], get_sbits(gb, qntztab[tbap]) << (16 - qntztab[tbap]), exps[i], factors);
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1046 continue;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1047 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1048 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1049
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1050 return 0;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1051 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1052
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1053 /* 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
1054 * 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
1055 * 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
1056 */
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1057 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
1058 {
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1059 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
1060 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
1061 mant_groups m;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1062
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1063 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
1064
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1065 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
1066 /* 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
1067 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
1068 return -1;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1069 /* 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
1070 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
1071 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
1072 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
1073 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
1074 return -1;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1075 }
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1076 got_cplchan = 1;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1077 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1078 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
1079 } else
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1080 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
1081 do
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1082 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
1083 while(++end < 256);
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1084 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1085 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
1086 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
1087 return -1;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1088 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
1089 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
1090 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1091 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1092
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1093 return 0;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1094 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1095
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1096 /* Rematrixing routines. */
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1097 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
1098 {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1099 float tmp0, tmp1;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1100
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1101 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
1102 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
1103 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
1104 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
1105 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
1106 start++;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1107 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1108 }
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 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
1111 {
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1112 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
1113 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
1114
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1115 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
1116
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1117 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
1118 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
1119
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1120 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
1121 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
1122
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1123 bndend = bnd4;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1124 if (bndend > end) {
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1125 bndend = end;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1126 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
1127 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
1128 } else {
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1129 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
1130 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
1131 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
1132 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
1133 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1134 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1135
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1136 /* 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
1137 * 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
1138 * 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
1139 */
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1140 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
1141 {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1142 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
1143 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
1144 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
1145 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
1146 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
1147 int i;
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
1148
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
1149 if (!ctx->acmod) {
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
1150 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
1151 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
1152 } else {
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
1153 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
1154 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
1155 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1156
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1157 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
1158 return;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1159
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1160 switch (from) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1161 case AC3_INPUT_DUALMONO:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1162 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1163 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
1164 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
1165 nf = 0.5;
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1166 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
1167 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
1168 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1169 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1170 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1171 case AC3_INPUT_MONO:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1172 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1173 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
1174 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
1175 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
1176 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1177 }
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_INPUT_STEREO:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1180 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1181 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
1182 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
1183 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
1184 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
1185 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1186 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1187 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1188 case AC3_INPUT_3F:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1189 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1190 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
1191 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
1192 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
1193 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
1194 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
1195 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1196 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
1197 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
1198 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
1199 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
1200 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
1201 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1202 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1203 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1204 case AC3_INPUT_2F_1R:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1205 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1206 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
1207 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
1208 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
1209 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
1210 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
1211 break;
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_STEREO:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1213 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
1214 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
1215 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
1216 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
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:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1219 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
1220 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
1221 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
1222 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
1223 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1224 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1225 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1226 case AC3_INPUT_3F_1R:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1227 switch (to) {
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_MONO:
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1229 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
1230 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
1231 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
1232 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
1233 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
1234 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1235 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
1236 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
1237 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
1238 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
1239 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
1240 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
1241 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1242 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
1243 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
1244 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
1245 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
1246 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
1247 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
1248 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1249 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1250 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1251 case AC3_INPUT_2F_2R:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1252 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1253 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
1254 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
1255 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
1256 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
1257 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
1258 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
1259 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1260 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
1261 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
1262 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
1263 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
1264 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
1265 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
1266 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1267 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
1268 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
1269 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
1270 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
1271 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
1272 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
1273 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1274 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1275 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1276 case AC3_INPUT_3F_2R:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1277 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1278 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
1279 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
1280 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
1281 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
1282 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
1283 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
1284 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
1285 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1286 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
1287 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
1288 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
1289 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
1290 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
1291 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
1292 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
1293 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1294 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
1295 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
1296 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
1297 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
1298 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
1299 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
1300 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
1301 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1302 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1303 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1304 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1305 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1306
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1307 /*********** 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
1308 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
1309 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1310 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1311 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
1312
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1313 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
1314 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
1315 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
1316 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1317
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1318 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
1319 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1320 int i;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1321 float tmp;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1322 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
1323
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1324 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
1325 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
1326 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
1327 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1328 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1329
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1330 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
1331 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1332 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1333 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
1334
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1335 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
1336 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
1337 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1338
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1339 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
1340 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1341 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1342 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
1343
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1344 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
1345 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
1346 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
1347 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1348
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1349 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
1350 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1351 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1352 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
1353
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1354 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
1355 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
1356 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
1357 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
1358 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1359
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1360 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
1361 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1362 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1363 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
1364
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1365 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
1366 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
1367 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
1368 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1369 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
1370 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1371
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1372 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
1373 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1374 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1375 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
1376
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1377 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
1378 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
1379 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
1380 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
1381
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1382 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1383
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1384 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
1385 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1386 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1387 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
1388
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1389 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
1390 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
1391 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
1392 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1393 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
1394 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1395
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1396 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
1397 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1398 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1399 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
1400
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1401 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
1402 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
1403 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
1404 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1405 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
1406 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1407
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1408 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
1409 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1410 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1411 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
1412
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1413 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
1414 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
1415 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
1416 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
1417 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
1418 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1419
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1420 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
1421 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1422 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1423 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
1424
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1425 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
1426 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
1427 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
1428 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1429 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
1430 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
1431 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1432
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1433 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
1434 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1435 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1436 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
1437
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1438 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
1439 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
1440 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
1441 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1442 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
1443 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
1444 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1445
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1446 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
1447 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1448 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1449 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
1450
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1451 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
1452 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
1453 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
1454 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
1455 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
1456 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1457
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1458 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
1459 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1460 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1461 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
1462
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1463 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
1464 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
1465 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
1466 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1467 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
1468 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
1469 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1470
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1471 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
1472 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1473 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1474 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
1475
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1476 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
1477 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
1478 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
1479 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1480 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
1481 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
1482 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1483
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1484 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
1485 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1486 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1487 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
1488
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1489 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
1490 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
1491 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
1492 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
1493 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
1494 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
1495 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
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 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
1498 {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1499 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1500 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
1501
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1502 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
1503 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
1504 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
1505 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1506 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
1507 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
1508 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
1509 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1510
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1511 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
1512 {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1513 int i;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1514 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
1515
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1516 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
1517 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
1518 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
1519 }
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1520 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
1521 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
1522 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
1523 }
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1524 /*********** END DOWNMIX FUNCTIONS ***********/
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1525
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1526 /* Downmix the output.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1527 * 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
1528 * 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
1529 */
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1530 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
1531 {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1532 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
1533 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
1534
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1535 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
1536 return;
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1537
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1538 switch (from) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1539 case AC3_INPUT_DUALMONO:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1540 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1541 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
1542 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
1543 break;
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1544 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
1545 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
1546 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1547 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1548 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1549 case AC3_INPUT_MONO:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1550 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1551 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
1552 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
1553 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1554 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1555 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1556 case AC3_INPUT_STEREO:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1557 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1558 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
1559 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
1560 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1561 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1562 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1563 case AC3_INPUT_3F:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1564 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1565 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
1566 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
1567 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1568 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
1569 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
1570 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1571 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1572 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1573 case AC3_INPUT_2F_1R:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1574 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1575 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
1576 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
1577 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1578 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
1579 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
1580 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1581 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
1582 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
1583 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1584 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1585 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1586 case AC3_INPUT_3F_1R:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1587 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1588 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
1589 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
1590 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1591 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
1592 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
1593 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1594 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
1595 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
1596 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1597 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1598 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1599 case AC3_INPUT_2F_2R:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1600 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1601 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
1602 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
1603 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1604 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
1605 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
1606 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1607 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
1608 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
1609 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1610 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1611 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1612 case AC3_INPUT_3F_2R:
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1613 switch (to) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1614 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
1615 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
1616 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1617 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
1618 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
1619 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1620 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
1621 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
1622 break;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1623 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1624 break;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1625 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1626 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1627
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1628 static void dump_floats(const char *name, int prec, const float *tab, int n)
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1629 {
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1630 int i;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1631
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1632 av_log(NULL, AV_LOG_INFO, "%s[%d]:\n", name, n);
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1633 for(i=0;i<n;i++) {
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1634 if ((i & 7) == 0)
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1635 av_log(NULL, AV_LOG_INFO, "%4d: ", i);
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1636 av_log(NULL, AV_LOG_INFO, " %8.*f", prec, tab[i]);
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1637 if ((i & 7) == 7)
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1638 av_log(NULL, AV_LOG_INFO, "\n");
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1639 }
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1640 if ((i & 7) != 0)
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1641 av_log(NULL, AV_LOG_INFO, "\n");
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1642 }
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1643
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1644 /* 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
1645 * coefficients.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1646 */
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1647 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
1648 {
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1649 int k;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1650 float x1[128], x2[128];
5322
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1651 float *o_ptr, *d_ptr, *w;
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1652 FFTComplex *ptr1, *ptr2;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1653
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1654 for (k = 0; k < N / 4; k++) {
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1655 x1[k] = ctx->transform_coeffs[chindex][2 * k];
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1656 x2[k] = ctx->transform_coeffs[chindex][2 * k + 1];
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1657 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1658
5324
33e13333dc4d AC-3 decoder, soc revision 148, Sep 28 18:38:27 2006 UTC by banan
jbr
parents: 5323
diff changeset
1659 ctx->imdct_256.fft.imdct_calc(&ctx->imdct_256, ctx->tmp_output, x1, ctx->tmp_imdct);
33e13333dc4d AC-3 decoder, soc revision 148, Sep 28 18:38:27 2006 UTC by banan
jbr
parents: 5323
diff changeset
1660 ctx->imdct_256.fft.imdct_calc(&ctx->imdct_256, ctx->tmp_output + 256, x2, ctx->tmp_imdct);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1661
5322
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1662 o_ptr = ctx->output[chindex];
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1663 d_ptr = ctx->delay[chindex];
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1664 ptr1 = (FFTComplex *)ctx->tmp_output;
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1665 ptr2 = (FFTComplex *)ctx->tmp_output + 256;
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1666 w = ctx->window;
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1667
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1668 for (k = 0; k < N / 8; k++)
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1669 {
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1670 o_ptr[2 * k] = -ptr1[k].im * w[2 * k] + d_ptr[2 * k] + 384.0;
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1671 o_ptr[2 * k + 1] = ptr1[N / 8 - k - 1].re * w[2 * k + 1] + 384.0;
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1672 o_ptr[N / 4 + 2 * k] = -ptr1[k].re * w[N / 4 + 2 * k] + d_ptr[N / 4 + 2 * k] + 384.0;
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1673 o_ptr[N / 4 + 2 * k + 1] = ptr1[N / 8 - k - 1].im * w[N / 4 + 2 * k + 1] + d_ptr[N / 4 + 2 * k + 1] + 384.0;
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1674 d_ptr[2 * k] = ptr2[k].re * w[k / 2 - 2 * k - 1];
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1675 d_ptr[2 * k + 1] = -ptr2[N / 8 - k - 1].im * w[N / 2 - 2 * k - 2];
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1676 d_ptr[N / 4 + 2 * k] = ptr2[k].im * w[N / 4 - 2 * k - 1];
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1677 d_ptr[N / 4 + 2 * k + 1] = -ptr2[N / 8 - k - 1].re * w[N / 4 - 2 * k - 2];
b55b8c792066 AC-3 decoder, soc revision 72, Sep 7 04:20:00 2006 UTC by cloud9
jbr
parents: 5321
diff changeset
1678 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1679 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1680
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1681 /* This function performs the imdct on 512 sample transform
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1682 * coefficients.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1683 */
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1684 static void do_imdct_512(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
1685 {
5317
6d81881f257f AC-3 decoder, soc revision 57, Aug 19 12:44:38 2006 UTC by cloud9
jbr
parents: 5316
diff changeset
1686 float *ptr;
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1687
5324
33e13333dc4d AC-3 decoder, soc revision 148, Sep 28 18:38:27 2006 UTC by banan
jbr
parents: 5323
diff changeset
1688 ctx->imdct_512.fft.imdct_calc(&ctx->imdct_512, ctx->tmp_output,
33e13333dc4d AC-3 decoder, soc revision 148, Sep 28 18:38:27 2006 UTC by banan
jbr
parents: 5323
diff changeset
1689 ctx->transform_coeffs[chindex], ctx->tmp_imdct);
5317
6d81881f257f AC-3 decoder, soc revision 57, Aug 19 12:44:38 2006 UTC by cloud9
jbr
parents: 5316
diff changeset
1690 ptr = ctx->output[chindex];
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
1691 ctx->dsp.vector_fmul_add_add(ptr, ctx->tmp_output, ctx->window, ctx->delay[chindex], 384, BLOCK_SIZE, 1);
5317
6d81881f257f AC-3 decoder, soc revision 57, Aug 19 12:44:38 2006 UTC by cloud9
jbr
parents: 5316
diff changeset
1692 ptr = ctx->delay[chindex];
5319
40af705cef7e AC-3 decoder, soc revision 69, Aug 31 07:12:56 2006 UTC by cloud9
jbr
parents: 5318
diff changeset
1693 ctx->dsp.vector_fmul_reverse(ptr, ctx->tmp_output + 256, ctx->window, BLOCK_SIZE);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1694 }
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1695
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1696 /* IMDCT Transform. */
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1697 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
1698 {
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1699 int i;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1700
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1701 if (ctx->blkoutput & AC3_OUTPUT_LFEON) {
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1702 do_imdct_512(ctx, 0);
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1703 }
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1704 for (i = 0; i < ctx->nfchans; i++) {
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1705 if ((ctx->blksw >> i) & 1)
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1706 do_imdct_256(ctx, i + 1);
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1707 else
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1708 do_imdct_512(ctx, i + 1);
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1709 }
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1710 }
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1711
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
1712 /* 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
1713 * 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
1714 * 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
1715 * 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
1716 */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1717 static int ac3_parse_audio_block(AC3DecodeContext * ctx)
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1718 {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1719 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
1720 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
1721 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
1722 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
1723 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
1724 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
1725 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
1726 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
1727
5312
2c875e6274d5 AC-3 decoder, soc revision 52, Aug 16 22:45:07 2006 UTC by cloud9
jbr
parents: 5311
diff changeset
1728 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
1729 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
1730 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
1731
5312
2c875e6274d5 AC-3 decoder, soc revision 52, Aug 16 22:45:07 2006 UTC by cloud9
jbr
parents: 5311
diff changeset
1732 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
1733 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
1734 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
1735
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1736 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
1737 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
1738 ctx->dynrng = ((((dynrng & 0x1f) | 0x20) << 13) * scale_factors[3 - (dynrng >> 5)]);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1739 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1740
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1741 if (acmod == 0x00 && get_bits1(gb)) { /* dynamic range 1+1 mode */
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
1742 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
1743 ctx->dynrng2 = ((((dynrng & 0x1f) | 0x20) << 13) * scale_factors[3 - (dynrng >> 5)]);
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1744 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1745
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1746 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
1747
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1748 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
1749 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
1750 ctx->cplbndstrc = 0;
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1751 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
1752 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
1753 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
1754 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
1755
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1756 if (acmod == 0x02)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1757 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
1758
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1759 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
1760 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
1761
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1762 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
1763 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
1764 return -1;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1765 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1766
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1767 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
1768 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
1769 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
1770 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
1771 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
1772 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
1773 ctx->ncplbnd--;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1774 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1775 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1776 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1777
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1778 if (ctx->cplinu) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1779 ctx->cplcoe = 0;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1780
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1781 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
1782 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
1783 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
1784 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
1785 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
1786 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
1787 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
1788 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
1789 if (cplcoexp == 15)
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1790 cplcomant <<= 14;
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1791 else
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1792 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
1793 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
1794 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1795 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1796
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1797 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
1798 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
1799 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
1800 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
1801 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1802
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1803 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
1804 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
1805 if (ctx->rematstr) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1806 ctx->rematflg = 0;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1807
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1808 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
1809 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
1810 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
1811 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
1812 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
1813 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
1814 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
1815 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
1816 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
1817 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1818 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1819
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1820 ctx->cplexpstr = AC3_EXPSTR_REUSE;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1821 ctx->lfeexpstr = AC3_EXPSTR_REUSE;
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1822 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
1823 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
1824 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
1825 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
1826 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
1827 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
1828
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1829 for (i = 0; i < nfchans; i++) /* channel bandwidth code */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1830 if (ctx->chexpstr[i] != AC3_EXPSTR_REUSE) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1831 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
1832 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
1833 else {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1834 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
1835 if (chbwcod > 60) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1836 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
1837 return -1;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1838 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1839 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
1840 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1841 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1842
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1843 if (ctx->cplexpstr != AC3_EXPSTR_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
1844 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
1845 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
1846 ngrps = (ctx->cplendmant - ctx->cplstrtmant) / (3 << (ctx->cplexpstr - 1));
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1847 if (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
1848 av_log(NULL, AV_LOG_ERROR, "error decoding coupling exponents\n");
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1849 return -1;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1850 }
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1851 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1852
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1853 for (i = 0; i < nfchans; i++) /* fbw channel exponents */
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1854 if (ctx->chexpstr[i] != AC3_EXPSTR_REUSE) {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1855 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
1856 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
1857 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
1858 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
1859 dexps[0] = get_bits(gb, 4);
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1860 if (decode_exponents(gb, ctx->chexpstr[i], ngrps, dexps[0], dexps + 1)) {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1861 av_log(NULL, AV_LOG_ERROR, "error decoding channel %d exponents\n", i);
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1862 return -1;
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1863 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1864 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
1865 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1866
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1867 if (ctx->lfeexpstr != AC3_EXPSTR_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
1868 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
1869 ctx->dlfeexps[0] = 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
1870 if (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
1871 av_log(NULL, AV_LOG_ERROR, "error decoding lfe exponents\n");
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1872 return -1;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1873 }
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1874 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1875
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1876 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
1877 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
1878 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
1879 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
1880 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
1881 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
1882 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
1883 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1884
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1885 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
1886 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
1887 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
1888 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
1889 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
1890 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
1891 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1892 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
1893 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
1894 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
1895 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1896 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
1897 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
1898 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
1899 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1900 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1901
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1902 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
1903 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
1904 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
1905 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
1906 }
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1907
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1908 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
1909 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
1910
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1911 if (ctx->cplinu) {
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1912 ctx->cpldeltbae = 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
1913 if (ctx->cpldeltbae == AC3_DBASTR_RESERVED) {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1914 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
1915 return -1;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1916 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1917 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1918
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1919 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
1920 ctx->deltbae[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
1921 if (ctx->deltbae[i] == AC3_DBASTR_RESERVED) {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1922 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
1923 return -1;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1924 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1925 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1926
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1927 if (ctx->cplinu)
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1928 if (ctx->cpldeltbae == AC3_DBASTR_NEW) { /*coupling delta offset, len and bit allocation */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1929 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
1930 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
1931 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
1932 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
1933 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
1934 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1935 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1936
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1937 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
1938 if (ctx->deltbae[i] == AC3_DBASTR_NEW) {/*channel delta offset, len and bit allocation */
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1939 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
1940 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
1941 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
1942 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
1943 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
1944 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1945 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1946 }
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1947
5310
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1948 if (bit_alloc_flags) {
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1949 if (is_snr_offsets_zero(ctx)) {
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1950 memset(ctx->cplbap, 0, sizeof (ctx->cplbap));
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1951 memset(ctx->lfebap, 0, sizeof (ctx->lfebap));
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1952 for (i = 0; i < nfchans; i++)
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1953 memset(ctx->bap[i], 0, sizeof(ctx->bap[i]));
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1954 } else {
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1955 if (ctx->chincpl && (bit_alloc_flags & 64))
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1956 do_bit_allocation(ctx, 5);
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1957 for (i = 0; i < nfchans; i++)
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1958 if ((bit_alloc_flags >> i) & 1)
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1959 do_bit_allocation(ctx, i);
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1960 if (ctx->lfeon && (bit_alloc_flags & 32))
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1961 do_bit_allocation(ctx, 6);
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1962 }
9aa9197034d7 AC-3 decoder, soc revision 40, Aug 9 00:10:14 2006 UTC by cloud9
jbr
parents: 5309
diff changeset
1963 }
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
1964
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1965 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
1966 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
1967 while(skipl--)
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
1968 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
1969 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1970 /* 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
1971 * * 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
1972 */
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1973 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
1974 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
1975 return -1;
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1976 }
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1977 /*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
1978 dump_floats("channel transform coefficients", 10, ctx->transform_coeffs[i + 1], BLOCK_SIZE);*/
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1979
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1980 /* 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
1981 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
1982 do_rematrixing(ctx);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1983
5318
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1984 do_downmix(ctx);
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1985
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1986 do_imdct(ctx);
5307
1bcccd2de20d AC-3 decoder, soc revision 33, Jul 17 12:13:40 2006 UTC by cloud9
jbr
parents: 5306
diff changeset
1987 /*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
1988 dump_floats("channel output", 10, ctx->output[i + 1], BLOCK_SIZE);*/
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
1989
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1990 return 0;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
1991 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
1992
5318
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1993 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
1994 {
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1995 if (i > 0x43c07fff)
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1996 return 32767;
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1997 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
1998 return -32768;
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
1999 else
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
2000 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
2001 }
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
2002
5308
82b41f5a86ef AC-3 decoder, soc revision 34, Jul 18 14:27:54 2006 UTC by cloud9
jbr
parents: 5307
diff changeset
2003 static int frame_count = 0;
82b41f5a86ef AC-3 decoder, soc revision 34, Jul 18 14:27:54 2006 UTC by cloud9
jbr
parents: 5307
diff changeset
2004
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
2005 /* Decode ac3 frame.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
2006 *
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
2007 * @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
2008 * @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
2009 * @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
2010 * @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
2011 * @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
2012 */
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
2013 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
2014 {
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
2015 AC3DecodeContext *ctx = (AC3DecodeContext *)avctx->priv_data;
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2016 int frame_start;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
2017 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
2018 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
2019 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
2020
5318
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
2021 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
2022 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
2023
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
2024 //av_log(NULL, AV_LOG_INFO, "decoding frame %d buf_size = %d\n", frame_count++, buf_size);
5308
82b41f5a86ef AC-3 decoder, soc revision 34, Jul 18 14:27:54 2006 UTC by cloud9
jbr
parents: 5307
diff changeset
2025
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2026 //Synchronize the frame.
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2027 frame_start = ac3_synchronize(buf, buf_size);
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2028 if (frame_start == -1) {
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2029 av_log(avctx, AV_LOG_ERROR, "frame is not synchronized\n");
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2030 *data_size = 0;
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
2031 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
2032 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
2033
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2034 //Initialize the GetBitContext with the start of valid AC3 Frame.
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2035 init_get_bits(&(ctx->gb), buf + frame_start, (buf_size - frame_start) * 8);
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
2036
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2037 //Parse the syncinfo.
5305
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
2038 //If 'fscod' or 'bsid' is not valid the decoder shall mute as per the standard.
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
2039 if (!ac3_parse_sync_info(ctx)) {
5892b4a6380b AC-3 decoder, soc revision 31, Jul 14 23:53:28 2006 UTC by cloud9
jbr
parents: 5304
diff changeset
2040 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
2041 *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
2042 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
2043 }
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
2044
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2045 //Parse the BSI.
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2046 //If 'bsid' is not valid decoder shall not decode the audio as per the standard.
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
2047 ac3_parse_bsi(ctx);
5303
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
2048
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
2049 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
2050 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
2051
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2052 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
2053 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
2054 if (ctx->lfeon)
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
2055 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
2056 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
2057 }
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
2058 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
2059 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
2060 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
2061 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
2062 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
2063 else
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
2064 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
2065 }
5311
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
2066 else {
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
2067 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
2068 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
2069 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
2070 if (ctx->lfeon)
7742d5411c9d AC-3 decoder, soc revision 48, Aug 16 11:27:49 2006 UTC by cloud9
jbr
parents: 5310
diff changeset
2071 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
2072 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
2073 }
b8821ff5c30d AC-3 decoder, soc revision 9, Jun 14 03:52:02 2006 UTC by cloud9
jbr
parents:
diff changeset
2074
5318
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
2075 //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
2076
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2077 //Parse the Audio Blocks.
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
2078 for (i = 0; i < AUDIO_BLOCKS; i++) {
5309
0662a270aab7 AC-3 decoder, soc revision 38, Aug 7 00:03:00 2006 UTC by cloud9
jbr
parents: 5308
diff changeset
2079 if (ac3_parse_audio_block(ctx)) {
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2080 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
2081 *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
2082 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
2083 }
5318
ef4ef249ca72 AC-3 decoder, soc revision 58, Aug 19 14:20:45 2006 UTC by cloud9
jbr
parents: 5317
diff changeset
2084 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
2085 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
2086 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
2087 *(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
2088 }
5306
abc5c130b448 AC-3 decoder, soc revision 32, Jul 17 09:37:32 2006 UTC by cloud9
jbr
parents: 5305
diff changeset
2089 *data_size = AUDIO_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
2090 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
2091 }
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2092
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
2093 /* Uninitialize ac3 decoder.
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
2094 */
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
2095 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
2096 {
5321
fcb2a52c88fe AC-3 decoder, soc revision 71, Sep 4 09:47:12 2006 UTC by cloud9
jbr
parents: 5320
diff changeset
2097 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
2098 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
2099 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
2100
5304
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2101 return 0;
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2102 }
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2103
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2104 AVCodec lgpl_ac3_decoder = {
5315
31033309ebc9 AC-3 decoder, soc revision 55, Aug 17 12:25:24 2006 UTC by cloud9
jbr
parents: 5314
diff changeset
2105 .name = "ac3",
31033309ebc9 AC-3 decoder, soc revision 55, Aug 17 12:25:24 2006 UTC by cloud9
jbr
parents: 5314
diff changeset
2106 .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
2107 .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
2108 .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
2109 .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
2110 .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
2111 .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
2112 };
eff51058fe13 AC-3 decoder, soc revision 26, Jul 5 04:55:15 2006 UTC by cloud9
jbr
parents: 5303
diff changeset
2113