13453
|
1 /*
|
|
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR and PS decoding
|
|
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
|
|
4 **
|
|
5 ** This program is free software; you can redistribute it and/or modify
|
|
6 ** it under the terms of the GNU General Public License as published by
|
|
7 ** the Free Software Foundation; either version 2 of the License, or
|
|
8 ** (at your option) any later version.
|
|
9 **
|
|
10 ** This program is distributed in the hope that it will be useful,
|
|
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 ** GNU General Public License for more details.
|
|
14 **
|
|
15 ** You should have received a copy of the GNU General Public License
|
|
16 ** along with this program; if not, write to the Free Software
|
|
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
18 **
|
|
19 ** Any non-GPL usage of this software or parts of this software is strictly
|
|
20 ** forbidden.
|
|
21 **
|
|
22 ** Commercial non-GPL licensing of this software is possible.
|
|
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
|
|
24 **
|
|
25 ** Initially modified for use with MPlayer by Diego Biurrun on 2004/09/24
|
|
26 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
|
|
27 **/
|
|
28
|
|
29 #include "common.h"
|
|
30
|
|
31 #ifdef PS_DEC
|
|
32
|
|
33 #include "bits.h"
|
|
34 #include "ps_dec.h"
|
|
35
|
|
36 /* type definitaions */
|
|
37 typedef const int8_t (*ps_huff_tab)[2];
|
|
38
|
|
39 /* static data tables */
|
|
40 static const uint8_t nr_iid_par_tab[] = {
|
|
41 10, 20, 34, 10, 20, 34, 0, 0
|
|
42 };
|
|
43 static const uint8_t nr_ipdopd_par_tab[] = {
|
|
44 5, 11, 17, 5, 11, 17, 0, 0
|
|
45 };
|
|
46 static const uint8_t nr_icc_par_tab[] = {
|
|
47 10, 20, 34, 10, 20, 34, 0, 0
|
|
48 };
|
|
49 static const uint8_t num_env_tab[][4] = {
|
|
50 { 0, 1, 2, 4 },
|
|
51 { 1, 2, 3, 4 }
|
|
52 };
|
|
53
|
|
54 /* binary lookup huffman tables */
|
|
55 static const int8_t f_huff_iid_def[][2] = {
|
|
56 { /*0*/ -31, 1 }, /* index 0: 1 bits: x */
|
|
57 { 2, 3 }, /* index 1: 2 bits: 1x */
|
|
58 { /*1*/ -30, /*-1*/ -32 }, /* index 2: 3 bits: 10x */
|
|
59 { 4, 5 }, /* index 3: 3 bits: 11x */
|
|
60 { /*2*/ -29, /*-2*/ -33 }, /* index 4: 4 bits: 110x */
|
|
61 { 6, 7 }, /* index 5: 4 bits: 111x */
|
|
62 { /*3*/ -28, /*-3*/ -34 }, /* index 6: 5 bits: 1110x */
|
|
63 { 8, 9 }, /* index 7: 5 bits: 1111x */
|
|
64 { /*-4*/ -35, /*4*/ -27 }, /* index 8: 6 bits: 11110x */
|
|
65 { /*5*/ -26, 10 }, /* index 9: 6 bits: 11111x */
|
|
66 { /*-5*/ -36, 11 }, /* index 10: 7 bits: 111111x */
|
|
67 { /*6*/ -25, 12 }, /* index 11: 8 bits: 1111111x */
|
|
68 { /*-6*/ -37, 13 }, /* index 12: 9 bits: 11111111x */
|
|
69 { /*-7*/ -38, 14 }, /* index 13: 10 bits: 111111111x */
|
|
70 { /*7*/ -24, 15 }, /* index 14: 11 bits: 1111111111x */
|
|
71 { 16, 17 }, /* index 15: 12 bits: 11111111111x */
|
|
72 { /*8*/ -23, /*-8*/ -39 }, /* index 16: 13 bits: 111111111110x */
|
|
73 { 18, 19 }, /* index 17: 13 bits: 111111111111x */
|
|
74 { /*9*/ -22, /*10*/ -21 }, /* index 18: 14 bits: 1111111111110x */
|
|
75 { 20, 21 }, /* index 19: 14 bits: 1111111111111x */
|
|
76 { /*-9*/ -40, /*11*/ -20 }, /* index 20: 15 bits: 11111111111110x */
|
|
77 { 22, 23 }, /* index 21: 15 bits: 11111111111111x */
|
|
78 { /*-10*/ -41, 24 }, /* index 22: 16 bits: 111111111111110x */
|
|
79 { 25, 26 }, /* index 23: 16 bits: 111111111111111x */
|
|
80 { /*-11*/ -42, /*-14*/ -45 }, /* index 24: 17 bits: 1111111111111101x */
|
|
81 { /*-13*/ -44, /*-12*/ -43 }, /* index 25: 17 bits: 1111111111111110x */
|
|
82 { /*12*/ -19, 27 }, /* index 26: 17 bits: 1111111111111111x */
|
|
83 { /*13*/ -18, /*14*/ -17 } /* index 27: 18 bits: 11111111111111111x */
|
|
84 };
|
|
85
|
|
86 static const int8_t t_huff_iid_def[][2] = {
|
|
87 { /*0*/ -31, 1 }, /* index 0: 1 bits: x */
|
|
88 { /*-1*/ -32, 2 }, /* index 1: 2 bits: 1x */
|
|
89 { /*1*/ -30, 3 }, /* index 2: 3 bits: 11x */
|
|
90 { /*-2*/ -33, 4 }, /* index 3: 4 bits: 111x */
|
|
91 { /*2*/ -29, 5 }, /* index 4: 5 bits: 1111x */
|
|
92 { /*-3*/ -34, 6 }, /* index 5: 6 bits: 11111x */
|
|
93 { /*3*/ -28, 7 }, /* index 6: 7 bits: 111111x */
|
|
94 { /*-4*/ -35, 8 }, /* index 7: 8 bits: 1111111x */
|
|
95 { /*4*/ -27, 9 }, /* index 8: 9 bits: 11111111x */
|
|
96 { /*-5*/ -36, 10 }, /* index 9: 10 bits: 111111111x */
|
|
97 { /*5*/ -26, 11 }, /* index 10: 11 bits: 1111111111x */
|
|
98 { /*-6*/ -37, 12 }, /* index 11: 12 bits: 11111111111x */
|
|
99 { /*6*/ -25, 13 }, /* index 12: 13 bits: 111111111111x */
|
|
100 { /*7*/ -24, 14 }, /* index 13: 14 bits: 1111111111111x */
|
|
101 { /*-7*/ -38, 15 }, /* index 14: 15 bits: 11111111111111x */
|
|
102 { 16, 17 }, /* index 15: 16 bits: 111111111111111x */
|
|
103 { /*8*/ -23, /*-8*/ -39 }, /* index 16: 17 bits: 1111111111111110x */
|
|
104 { 18, 19 }, /* index 17: 17 bits: 1111111111111111x */
|
|
105 { 20, 21 }, /* index 18: 18 bits: 11111111111111110x */
|
|
106 { 22, 23 }, /* index 19: 18 bits: 11111111111111111x */
|
|
107 { /*9*/ -22, /*-14*/ -45 }, /* index 20: 19 bits: 111111111111111100x */
|
|
108 { /*-13*/ -44, /*-12*/ -43 }, /* index 21: 19 bits: 111111111111111101x */
|
|
109 { 24, 25 }, /* index 22: 19 bits: 111111111111111110x */
|
|
110 { 26, 27 }, /* index 23: 19 bits: 111111111111111111x */
|
|
111 { /*-11*/ -42, /*-10*/ -41 }, /* index 24: 20 bits: 1111111111111111100x */
|
|
112 { /*-9*/ -40, /*10*/ -21 }, /* index 25: 20 bits: 1111111111111111101x */
|
|
113 { /*11*/ -20, /*12*/ -19 }, /* index 26: 20 bits: 1111111111111111110x */
|
|
114 { /*13*/ -18, /*14*/ -17 } /* index 27: 20 bits: 1111111111111111111x */
|
|
115 };
|
|
116
|
|
117 static const int8_t f_huff_iid_fine[][2] = {
|
|
118 { 1, /*0*/ -31 }, /* index 0: 1 bits: x */
|
|
119 { 2, 3 }, /* index 1: 2 bits: 0x */
|
|
120 { 4, /*-1*/ -32 }, /* index 2: 3 bits: 00x */
|
|
121 { /*1*/ -30, 5 }, /* index 3: 3 bits: 01x */
|
|
122 { /*-2*/ -33, /*2*/ -29 }, /* index 4: 4 bits: 000x */
|
|
123 { 6, 7 }, /* index 5: 4 bits: 011x */
|
|
124 { /*-3*/ -34, /*3*/ -28 }, /* index 6: 5 bits: 0110x */
|
|
125 { 8, 9 }, /* index 7: 5 bits: 0111x */
|
|
126 { /*-4*/ -35, /*4*/ -27 }, /* index 8: 6 bits: 01110x */
|
|
127 { 10, 11 }, /* index 9: 6 bits: 01111x */
|
|
128 { /*-5*/ -36, /*5*/ -26 }, /* index 10: 7 bits: 011110x */
|
|
129 { 12, 13 }, /* index 11: 7 bits: 011111x */
|
|
130 { /*-6*/ -37, /*6*/ -25 }, /* index 12: 8 bits: 0111110x */
|
|
131 { 14, 15 }, /* index 13: 8 bits: 0111111x */
|
|
132 { /*7*/ -24, 16 }, /* index 14: 9 bits: 01111110x */
|
|
133 { 17, 18 }, /* index 15: 9 bits: 01111111x */
|
|
134 { 19, /*-8*/ -39 }, /* index 16: 10 bits: 011111101x */
|
|
135 { /*8*/ -23, 20 }, /* index 17: 10 bits: 011111110x */
|
|
136 { 21, /*-7*/ -38 }, /* index 18: 10 bits: 011111111x */
|
|
137 { /*10*/ -21, 22 }, /* index 19: 11 bits: 0111111010x */
|
|
138 { 23, /*-9*/ -40 }, /* index 20: 11 bits: 0111111101x */
|
|
139 { /*9*/ -22, 24 }, /* index 21: 11 bits: 0111111110x */
|
|
140 { /*-11*/ -42, /*11*/ -20 }, /* index 22: 12 bits: 01111110101x */
|
|
141 { 25, 26 }, /* index 23: 12 bits: 01111111010x */
|
|
142 { 27, /*-10*/ -41 }, /* index 24: 12 bits: 01111111101x */
|
|
143 { 28, /*-12*/ -43 }, /* index 25: 13 bits: 011111110100x */
|
|
144 { /*12*/ -19, 29 }, /* index 26: 13 bits: 011111110101x */
|
|
145 { 30, 31 }, /* index 27: 13 bits: 011111111010x */
|
|
146 { 32, /*-14*/ -45 }, /* index 28: 14 bits: 0111111101000x */
|
|
147 { /*14*/ -17, 33 }, /* index 29: 14 bits: 0111111101011x */
|
|
148 { 34, /*-13*/ -44 }, /* index 30: 14 bits: 0111111110100x */
|
|
149 { /*13*/ -18, 35 }, /* index 31: 14 bits: 0111111110101x */
|
|
150 { 36, 37 }, /* index 32: 15 bits: 01111111010000x */
|
|
151 { 38, /*-15*/ -46 }, /* index 33: 15 bits: 01111111010111x */
|
|
152 { /*15*/ -16, 39 }, /* index 34: 15 bits: 01111111101000x */
|
|
153 { 40, 41 }, /* index 35: 15 bits: 01111111101011x */
|
|
154 { 42, 43 }, /* index 36: 16 bits: 011111110100000x */
|
|
155 { /*-17*/ -48, /*17*/ -14 }, /* index 37: 16 bits: 011111110100001x */
|
|
156 { 44, 45 }, /* index 38: 16 bits: 011111110101110x */
|
|
157 { 46, 47 }, /* index 39: 16 bits: 011111111010001x */
|
|
158 { 48, 49 }, /* index 40: 16 bits: 011111111010110x */
|
|
159 { /*-16*/ -47, /*16*/ -15 }, /* index 41: 16 bits: 011111111010111x */
|
|
160 { /*-21*/ -52, /*21*/ -10 }, /* index 42: 17 bits: 0111111101000000x */
|
|
161 { /*-19*/ -50, /*19*/ -12 }, /* index 43: 17 bits: 0111111101000001x */
|
|
162 { /*-18*/ -49, /*18*/ -13 }, /* index 44: 17 bits: 0111111101011100x */
|
|
163 { 50, 51 }, /* index 45: 17 bits: 0111111101011101x */
|
|
164 { 52, 53 }, /* index 46: 17 bits: 0111111110100010x */
|
|
165 { 54, 55 }, /* index 47: 17 bits: 0111111110100011x */
|
|
166 { 56, 57 }, /* index 48: 17 bits: 0111111110101100x */
|
|
167 { 58, 59 }, /* index 49: 17 bits: 0111111110101101x */
|
|
168 { /*-26*/ -57, /*-25*/ -56 }, /* index 50: 18 bits: 01111111010111010x */
|
|
169 { /*-28*/ -59, /*-27*/ -58 }, /* index 51: 18 bits: 01111111010111011x */
|
|
170 { /*-22*/ -53, /*22*/ -9 }, /* index 52: 18 bits: 01111111101000100x */
|
|
171 { /*-24*/ -55, /*-23*/ -54 }, /* index 53: 18 bits: 01111111101000101x */
|
|
172 { /*25*/ -6, /*26*/ -5 }, /* index 54: 18 bits: 01111111101000110x */
|
|
173 { /*23*/ -8, /*24*/ -7 }, /* index 55: 18 bits: 01111111101000111x */
|
|
174 { /*29*/ -2, /*30*/ -1 }, /* index 56: 18 bits: 01111111101011000x */
|
|
175 { /*27*/ -4, /*28*/ -3 }, /* index 57: 18 bits: 01111111101011001x */
|
|
176 { /*-30*/ -61, /*-29*/ -60 }, /* index 58: 18 bits: 01111111101011010x */
|
|
177 { /*-20*/ -51, /*20*/ -11 } /* index 59: 18 bits: 01111111101011011x */
|
|
178 };
|
|
179
|
|
180 static const int8_t t_huff_iid_fine[][2] = {
|
|
181 { 1, /*0*/ -31 }, /* index 0: 1 bits: x */
|
|
182 { /*1*/ -30, 2 }, /* index 1: 2 bits: 0x */
|
|
183 { 3, /*-1*/ -32 }, /* index 2: 3 bits: 01x */
|
|
184 { 4, 5 }, /* index 3: 4 bits: 010x */
|
|
185 { 6, 7 }, /* index 4: 5 bits: 0100x */
|
|
186 { /*-2*/ -33, /*2*/ -29 }, /* index 5: 5 bits: 0101x */
|
|
187 { 8, /*-3*/ -34 }, /* index 6: 6 bits: 01000x */
|
|
188 { /*3*/ -28, 9 }, /* index 7: 6 bits: 01001x */
|
|
189 { /*-4*/ -35, /*4*/ -27 }, /* index 8: 7 bits: 010000x */
|
|
190 { 10, 11 }, /* index 9: 7 bits: 010011x */
|
|
191 { /*5*/ -26, 12 }, /* index 10: 8 bits: 0100110x */
|
|
192 { 13, 14 }, /* index 11: 8 bits: 0100111x */
|
|
193 { /*-6*/ -37, /*6*/ -25 }, /* index 12: 9 bits: 01001101x */
|
|
194 { 15, 16 }, /* index 13: 9 bits: 01001110x */
|
|
195 { 17, /*-5*/ -36 }, /* index 14: 9 bits: 01001111x */
|
|
196 { 18, /*-7*/ -38 }, /* index 15: 10 bits: 010011100x */
|
|
197 { /*7*/ -24, 19 }, /* index 16: 10 bits: 010011101x */
|
|
198 { 20, 21 }, /* index 17: 10 bits: 010011110x */
|
|
199 { /*9*/ -22, 22 }, /* index 18: 11 bits: 0100111000x */
|
|
200 { 23, 24 }, /* index 19: 11 bits: 0100111011x */
|
|
201 { /*-8*/ -39, /*8*/ -23 }, /* index 20: 11 bits: 0100111100x */
|
|
202 { 25, 26 }, /* index 21: 11 bits: 0100111101x */
|
|
203 { /*11*/ -20, 27 }, /* index 22: 12 bits: 01001110001x */
|
|
204 { 28, 29 }, /* index 23: 12 bits: 01001110110x */
|
|
205 { /*-10*/ -41, /*10*/ -21 }, /* index 24: 12 bits: 01001110111x */
|
|
206 { 30, 31 }, /* index 25: 12 bits: 01001111010x */
|
|
207 { 32, /*-9*/ -40 }, /* index 26: 12 bits: 01001111011x */
|
|
208 { 33, /*-13*/ -44 }, /* index 27: 13 bits: 010011100011x */
|
|
209 { /*13*/ -18, 34 }, /* index 28: 13 bits: 010011101100x */
|
|
210 { 35, 36 }, /* index 29: 13 bits: 010011101101x */
|
|
211 { 37, /*-12*/ -43 }, /* index 30: 13 bits: 010011110100x */
|
|
212 { /*12*/ -19, 38 }, /* index 31: 13 bits: 010011110101x */
|
|
213 { 39, /*-11*/ -42 }, /* index 32: 13 bits: 010011110110x */
|
|
214 { 40, 41 }, /* index 33: 14 bits: 0100111000110x */
|
|
215 { 42, 43 }, /* index 34: 14 bits: 0100111011001x */
|
|
216 { 44, 45 }, /* index 35: 14 bits: 0100111011010x */
|
|
217 { 46, /*-15*/ -46 }, /* index 36: 14 bits: 0100111011011x */
|
|
218 { /*15*/ -16, 47 }, /* index 37: 14 bits: 0100111101000x */
|
|
219 { /*-14*/ -45, /*14*/ -17 }, /* index 38: 14 bits: 0100111101011x */
|
|
220 { 48, 49 }, /* index 39: 14 bits: 0100111101100x */
|
|
221 { /*-21*/ -52, /*-20*/ -51 }, /* index 40: 15 bits: 01001110001100x */
|
|
222 { /*18*/ -13, /*19*/ -12 }, /* index 41: 15 bits: 01001110001101x */
|
|
223 { /*-19*/ -50, /*-18*/ -49 }, /* index 42: 15 bits: 01001110110010x */
|
|
224 { 50, 51 }, /* index 43: 15 bits: 01001110110011x */
|
|
225 { 52, 53 }, /* index 44: 15 bits: 01001110110100x */
|
|
226 { 54, 55 }, /* index 45: 15 bits: 01001110110101x */
|
|
227 { 56, /*-17*/ -48 }, /* index 46: 15 bits: 01001110110110x */
|
|
228 { /*17*/ -14, 57 }, /* index 47: 15 bits: 01001111010001x */
|
|
229 { 58, /*-16*/ -47 }, /* index 48: 15 bits: 01001111011000x */
|
|
230 { /*16*/ -15, 59 }, /* index 49: 15 bits: 01001111011001x */
|
|
231 { /*-26*/ -57, /*26*/ -5 }, /* index 50: 16 bits: 010011101100110x */
|
|
232 { /*-28*/ -59, /*-27*/ -58 }, /* index 51: 16 bits: 010011101100111x */
|
|
233 { /*29*/ -2, /*30*/ -1 }, /* index 52: 16 bits: 010011101101000x */
|
|
234 { /*27*/ -4, /*28*/ -3 }, /* index 53: 16 bits: 010011101101001x */
|
|
235 { /*-30*/ -61, /*-29*/ -60 }, /* index 54: 16 bits: 010011101101010x */
|
|
236 { /*-25*/ -56, /*25*/ -6 }, /* index 55: 16 bits: 010011101101011x */
|
|
237 { /*-24*/ -55, /*24*/ -7 }, /* index 56: 16 bits: 010011101101100x */
|
|
238 { /*-23*/ -54, /*23*/ -8 }, /* index 57: 16 bits: 010011110100011x */
|
|
239 { /*-22*/ -53, /*22*/ -9 }, /* index 58: 16 bits: 010011110110000x */
|
|
240 { /*20*/ -11, /*21*/ -10 } /* index 59: 16 bits: 010011110110011x */
|
|
241 };
|
|
242
|
|
243 static const int8_t f_huff_icc[][2] = {
|
|
244 { /*0*/ -31, 1 }, /* index 0: 1 bits: x */
|
|
245 { /*1*/ -30, 2 }, /* index 1: 2 bits: 1x */
|
|
246 { /*-1*/ -32, 3 }, /* index 2: 3 bits: 11x */
|
|
247 { /*2*/ -29, 4 }, /* index 3: 4 bits: 111x */
|
|
248 { /*-2*/ -33, 5 }, /* index 4: 5 bits: 1111x */
|
|
249 { /*3*/ -28, 6 }, /* index 5: 6 bits: 11111x */
|
|
250 { /*-3*/ -34, 7 }, /* index 6: 7 bits: 111111x */
|
|
251 { /*4*/ -27, 8 }, /* index 7: 8 bits: 1111111x */
|
|
252 { /*5*/ -26, 9 }, /* index 8: 9 bits: 11111111x */
|
|
253 { /*-4*/ -35, 10 }, /* index 9: 10 bits: 111111111x */
|
|
254 { /*6*/ -25, 11 }, /* index 10: 11 bits: 1111111111x */
|
|
255 { /*-5*/ -36, 12 }, /* index 11: 12 bits: 11111111111x */
|
|
256 { /*7*/ -24, 13 }, /* index 12: 13 bits: 111111111111x */
|
|
257 { /*-6*/ -37, /*-7*/ -38 } /* index 13: 14 bits: 1111111111111x */
|
|
258 };
|
|
259
|
|
260 static const int8_t t_huff_icc[][2] = {
|
|
261 { /*0*/ -31, 1 }, /* index 0: 1 bits: x */
|
|
262 { /*1*/ -30, 2 }, /* index 1: 2 bits: 1x */
|
|
263 { /*-1*/ -32, 3 }, /* index 2: 3 bits: 11x */
|
|
264 { /*2*/ -29, 4 }, /* index 3: 4 bits: 111x */
|
|
265 { /*-2*/ -33, 5 }, /* index 4: 5 bits: 1111x */
|
|
266 { /*3*/ -28, 6 }, /* index 5: 6 bits: 11111x */
|
|
267 { /*-3*/ -34, 7 }, /* index 6: 7 bits: 111111x */
|
|
268 { /*4*/ -27, 8 }, /* index 7: 8 bits: 1111111x */
|
|
269 { /*-4*/ -35, 9 }, /* index 8: 9 bits: 11111111x */
|
|
270 { /*5*/ -26, 10 }, /* index 9: 10 bits: 111111111x */
|
|
271 { /*-5*/ -36, 11 }, /* index 10: 11 bits: 1111111111x */
|
|
272 { /*6*/ -25, 12 }, /* index 11: 12 bits: 11111111111x */
|
|
273 { /*-6*/ -37, 13 }, /* index 12: 13 bits: 111111111111x */
|
|
274 { /*-7*/ -38, /*7*/ -24 } /* index 13: 14 bits: 1111111111111x */
|
|
275 };
|
|
276
|
|
277 static const int8_t f_huff_ipd[][2] = {
|
|
278 { 1, /*0*/ -31 }, /* index 0: 1 bits: x */
|
|
279 { 2, 3 }, /* index 1: 2 bits: 0x */
|
|
280 { /*1*/ -30, 4 }, /* index 2: 3 bits: 00x */
|
|
281 { 5, 6 }, /* index 3: 3 bits: 01x */
|
|
282 { /*4*/ -27, /*5*/ -26 }, /* index 4: 4 bits: 001x */
|
|
283 { /*3*/ -28, /*6*/ -25 }, /* index 5: 4 bits: 010x */
|
|
284 { /*2*/ -29, /*7*/ -24 } /* index 6: 4 bits: 011x */
|
|
285 };
|
|
286
|
|
287 static const int8_t t_huff_ipd[][2] = {
|
|
288 { 1, /*0*/ -31 }, /* index 0: 1 bits: x */
|
|
289 { 2, 3 }, /* index 1: 2 bits: 0x */
|
|
290 { 4, 5 }, /* index 2: 3 bits: 00x */
|
|
291 { /*1*/ -30, /*7*/ -24 }, /* index 3: 3 bits: 01x */
|
|
292 { /*5*/ -26, 6 }, /* index 4: 4 bits: 000x */
|
|
293 { /*2*/ -29, /*6*/ -25 }, /* index 5: 4 bits: 001x */
|
|
294 { /*4*/ -27, /*3*/ -28 } /* index 6: 5 bits: 0001x */
|
|
295 };
|
|
296
|
|
297 static const int8_t f_huff_opd[][2] = {
|
|
298 { 1, /*0*/ -31 }, /* index 0: 1 bits: x */
|
|
299 { 2, 3 }, /* index 1: 2 bits: 0x */
|
|
300 { /*7*/ -24, /*1*/ -30 }, /* index 2: 3 bits: 00x */
|
|
301 { 4, 5 }, /* index 3: 3 bits: 01x */
|
|
302 { /*3*/ -28, /*6*/ -25 }, /* index 4: 4 bits: 010x */
|
|
303 { /*2*/ -29, 6 }, /* index 5: 4 bits: 011x */
|
|
304 { /*5*/ -26, /*4*/ -27 } /* index 6: 5 bits: 0111x */
|
|
305 };
|
|
306
|
|
307 static const int8_t t_huff_opd[][2] = {
|
|
308 { 1, /*0*/ -31 }, /* index 0: 1 bits: x */
|
|
309 { 2, 3 }, /* index 1: 2 bits: 0x */
|
|
310 { 4, 5 }, /* index 2: 3 bits: 00x */
|
|
311 { /*1*/ -30, /*7*/ -24 }, /* index 3: 3 bits: 01x */
|
|
312 { /*5*/ -26, 6 }, /* index 4: 4 bits: 000x */
|
|
313 { /*2*/ -29, /*6*/ -25 }, /* index 5: 4 bits: 001x */
|
|
314 { /*4*/ -27, /*3*/ -28 } /* index 6: 5 bits: 0001x */
|
|
315 };
|
|
316
|
|
317 /* static function declarations */
|
|
318 static uint16_t ps_extension(ps_info *ps, bitfile *ld,
|
|
319 const uint8_t ps_extension_id,
|
|
320 const uint16_t num_bits_left);
|
|
321 static void huff_data(bitfile *ld, const uint8_t dt, const uint8_t nr_par,
|
|
322 ps_huff_tab t_huff, ps_huff_tab f_huff, int8_t *par);
|
|
323 static INLINE int8_t ps_huff_dec(bitfile *ld, ps_huff_tab t_huff);
|
|
324
|
|
325
|
|
326 uint16_t ps_data(ps_info *ps, bitfile *ld)
|
|
327 {
|
|
328 uint8_t tmp, n;
|
|
329 uint16_t bits = (uint16_t)faad_get_processed_bits(ld);
|
|
330
|
|
331 /* check for new PS header */
|
|
332 if (faad_get1bit(ld
|
|
333 DEBUGVAR(1,1000,"ps_data(): enable_ps_header")))
|
|
334 {
|
|
335 ps->use34hybrid_bands = 0;
|
|
336
|
|
337 /* Inter-channel Intensity Difference (IID) parameters enabled */
|
|
338 ps->enable_iid = (uint8_t)faad_get1bit(ld
|
|
339 DEBUGVAR(1,1001,"ps_data(): enable_iid"));
|
|
340
|
|
341 if (ps->enable_iid)
|
|
342 {
|
|
343 ps->iid_mode = (uint8_t)faad_getbits(ld, 3
|
|
344 DEBUGVAR(1,1002,"ps_data(): iid_mode"));
|
|
345
|
|
346 ps->nr_iid_par = nr_iid_par_tab[ps->iid_mode];
|
|
347 ps->nr_ipdopd_par = nr_ipdopd_par_tab[ps->iid_mode];
|
|
348
|
|
349 if (ps->iid_mode == 2 || ps->iid_mode == 5)
|
|
350 ps->use34hybrid_bands = 1;
|
|
351
|
|
352 /* IPD freq res equal to IID freq res */
|
|
353 ps->ipd_mode = ps->iid_mode;
|
|
354 }
|
|
355
|
|
356 /* Inter-channel Coherence (ICC) parameters enabled */
|
|
357 ps->enable_icc = (uint8_t)faad_get1bit(ld
|
|
358 DEBUGVAR(1,1003,"ps_data(): enable_icc"));
|
|
359
|
|
360 if (ps->enable_icc)
|
|
361 {
|
|
362 ps->icc_mode = (uint8_t)faad_getbits(ld, 3
|
|
363 DEBUGVAR(1,1004,"ps_data(): icc_mode"));
|
|
364
|
|
365 ps->nr_icc_par = nr_icc_par_tab[ps->icc_mode];
|
|
366
|
|
367 if (ps->icc_mode == 2 || ps->icc_mode == 5)
|
|
368 ps->use34hybrid_bands = 1;
|
|
369 }
|
|
370
|
|
371 /* PS extension layer enabled */
|
|
372 ps->enable_ext = (uint8_t)faad_get1bit(ld
|
|
373 DEBUGVAR(1,1005,"ps_data(): enable_ext"));
|
|
374 }
|
|
375
|
|
376 ps->frame_class = (uint8_t)faad_get1bit(ld
|
|
377 DEBUGVAR(1,1006,"ps_data(): frame_class"));
|
|
378 tmp = (uint8_t)faad_getbits(ld, 2
|
|
379 DEBUGVAR(1,1007,"ps_data(): num_env_idx"));
|
|
380
|
|
381 ps->num_env = num_env_tab[ps->frame_class][tmp];
|
|
382
|
|
383 if (ps->frame_class)
|
|
384 {
|
|
385 for (n = 1; n < ps->num_env+1; n++)
|
|
386 {
|
|
387 ps->border_position[n] = (uint8_t)faad_getbits(ld, 5
|
|
388 DEBUGVAR(1,1008,"ps_data(): border_position"));
|
|
389 }
|
|
390 }
|
|
391
|
|
392 if (ps->enable_iid)
|
|
393 {
|
|
394 for (n = 0; n < ps->num_env; n++)
|
|
395 {
|
|
396 ps->iid_dt[n] = (uint8_t)faad_get1bit(ld
|
|
397 DEBUGVAR(1,1009,"ps_data(): iid_dt"));
|
|
398
|
|
399 /* iid_data */
|
|
400 if (ps->iid_mode < 3)
|
|
401 {
|
|
402 huff_data(ld, ps->iid_dt[n], ps->nr_iid_par, t_huff_iid_def,
|
|
403 f_huff_iid_def, ps->iid_index[n]);
|
|
404 } else {
|
|
405 huff_data(ld, ps->iid_dt[n], ps->nr_iid_par, t_huff_iid_fine,
|
|
406 f_huff_iid_fine, ps->iid_index[n]);
|
|
407 }
|
|
408 }
|
|
409 }
|
|
410
|
|
411 if (ps->enable_icc)
|
|
412 {
|
|
413 for (n = 0; n < ps->num_env; n++)
|
|
414 {
|
|
415 ps->icc_dt[n] = (uint8_t)faad_get1bit(ld
|
|
416 DEBUGVAR(1,1010,"ps_data(): icc_dt"));
|
|
417
|
|
418 /* icc_data */
|
|
419 huff_data(ld, ps->icc_dt[n], ps->nr_icc_par, t_huff_icc,
|
|
420 f_huff_icc, ps->icc_index[n]);
|
|
421 }
|
|
422 }
|
|
423
|
|
424 if (ps->enable_ext)
|
|
425 {
|
|
426 uint16_t num_bits_left;
|
|
427 uint16_t cnt = (uint16_t)faad_getbits(ld, 4
|
|
428 DEBUGVAR(1,1011,"ps_data(): ps_extension_size"));
|
|
429 if (cnt == 15)
|
|
430 {
|
|
431 cnt += (uint16_t)faad_getbits(ld, 8
|
|
432 DEBUGVAR(1,1012,"ps_data(): esc_count"));
|
|
433 }
|
|
434
|
|
435 num_bits_left = 8 * cnt;
|
|
436 while (num_bits_left > 7)
|
|
437 {
|
|
438 uint8_t ps_extension_id = (uint8_t)faad_getbits(ld, 2
|
|
439 DEBUGVAR(1,1013,"ps_data(): ps_extension_size"));
|
|
440
|
|
441 num_bits_left -= 2;
|
|
442 num_bits_left -= ps_extension(ps, ld, ps_extension_id, num_bits_left);
|
|
443 }
|
|
444
|
|
445 faad_getbits(ld, num_bits_left
|
|
446 DEBUGVAR(1,1014,"ps_data(): fill_bits"));
|
|
447 }
|
|
448
|
|
449 bits = (uint16_t)faad_get_processed_bits(ld) - bits;
|
|
450
|
|
451 ps->ps_data_available = 1;
|
|
452
|
|
453 return bits;
|
|
454 }
|
|
455
|
|
456 static uint16_t ps_extension(ps_info *ps, bitfile *ld,
|
|
457 const uint8_t ps_extension_id,
|
|
458 const uint16_t num_bits_left)
|
|
459 {
|
|
460 uint8_t n;
|
|
461 uint16_t bits = (uint16_t)faad_get_processed_bits(ld);
|
|
462
|
|
463 if (ps_extension_id == 0)
|
|
464 {
|
|
465 ps->enable_ipdopd = (uint8_t)faad_get1bit(ld
|
|
466 DEBUGVAR(1,1015,"ps_extension(): enable_ipdopd"));
|
|
467
|
|
468 if (ps->enable_ipdopd)
|
|
469 {
|
|
470 for (n = 0; n < ps->num_env; n++)
|
|
471 {
|
|
472 ps->ipd_dt[n] = (uint8_t)faad_get1bit(ld
|
|
473 DEBUGVAR(1,1016,"ps_extension(): ipd_dt"));
|
|
474
|
|
475 /* ipd_data */
|
|
476 huff_data(ld, ps->ipd_dt[n], ps->nr_ipdopd_par, t_huff_ipd,
|
|
477 f_huff_ipd, ps->ipd_index[n]);
|
|
478
|
|
479 ps->opd_dt[n] = (uint8_t)faad_get1bit(ld
|
|
480 DEBUGVAR(1,1017,"ps_extension(): opd_dt"));
|
|
481
|
|
482 /* opd_data */
|
|
483 huff_data(ld, ps->opd_dt[n], ps->nr_ipdopd_par, t_huff_opd,
|
|
484 f_huff_opd, ps->opd_index[n]);
|
|
485 }
|
|
486 }
|
|
487 faad_get1bit(ld
|
|
488 DEBUGVAR(1,1018,"ps_extension(): reserved_ps"));
|
|
489 }
|
|
490
|
|
491 /* return number of bits read */
|
|
492 bits = (uint16_t)faad_get_processed_bits(ld) - bits;
|
|
493
|
|
494 return bits;
|
|
495 }
|
|
496
|
|
497 /* read huffman data coded in either the frequency or the time direction */
|
|
498 static void huff_data(bitfile *ld, const uint8_t dt, const uint8_t nr_par,
|
|
499 ps_huff_tab t_huff, ps_huff_tab f_huff, int8_t *par)
|
|
500 {
|
|
501 uint8_t n;
|
|
502
|
|
503 if (dt)
|
|
504 {
|
|
505 /* coded in time direction */
|
|
506 for (n = 0; n < nr_par; n++)
|
|
507 {
|
|
508 par[n] = ps_huff_dec(ld, t_huff);
|
|
509 }
|
|
510 } else {
|
|
511 /* coded in frequency direction */
|
|
512 par[0] = ps_huff_dec(ld, f_huff);
|
|
513
|
|
514 for (n = 1; n < nr_par; n++)
|
|
515 {
|
|
516 par[n] = ps_huff_dec(ld, f_huff);
|
|
517 }
|
|
518 }
|
|
519 }
|
|
520
|
|
521 /* binary search huffman decoding */
|
|
522 static INLINE int8_t ps_huff_dec(bitfile *ld, ps_huff_tab t_huff)
|
|
523 {
|
|
524 uint8_t bit;
|
|
525 int16_t index = 0;
|
|
526
|
|
527 while (index >= 0)
|
|
528 {
|
|
529 bit = (uint8_t)faad_get1bit(ld);
|
|
530 index = t_huff[index][bit];
|
|
531 }
|
|
532
|
|
533 return index + 31;
|
|
534 }
|
|
535
|
|
536 #endif
|