2 |
- |
1 |
/*
|
|
|
2 |
* libmad - MPEG audio decoder library
|
|
|
3 |
* Copyright (C) 2000-2004 Underbit Technologies, Inc.
|
|
|
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 |
* $Id: layer3.c,v 1.43 2004/01/23 09:41:32 rob Exp $
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
# ifdef HAVE_CONFIG_H
|
|
|
23 |
# include "config.h"
|
|
|
24 |
# endif
|
|
|
25 |
|
|
|
26 |
# include "global.h"
|
|
|
27 |
|
|
|
28 |
# include "fixed.h"
|
|
|
29 |
# include "bit.h"
|
|
|
30 |
# include "stream.h"
|
|
|
31 |
# include "frame.h"
|
|
|
32 |
# include "huffman.h"
|
|
|
33 |
# include "layer3.h"
|
|
|
34 |
|
|
|
35 |
#define CHAR_BIT 8 /* duh */
|
|
|
36 |
|
|
|
37 |
/* --- Layer III ----------------------------------------------------------- */
|
|
|
38 |
|
|
|
39 |
enum {
|
|
|
40 |
count1table_select = 0x01,
|
|
|
41 |
scalefac_scale = 0x02,
|
|
|
42 |
preflag = 0x04,
|
|
|
43 |
mixed_block_flag = 0x08
|
|
|
44 |
};
|
|
|
45 |
|
|
|
46 |
enum {
|
|
|
47 |
I_STEREO = 0x1,
|
|
|
48 |
MS_STEREO = 0x2
|
|
|
49 |
};
|
|
|
50 |
|
|
|
51 |
struct sideinfo {
|
|
|
52 |
unsigned int main_data_begin;
|
|
|
53 |
unsigned int private_bits;
|
|
|
54 |
|
|
|
55 |
unsigned char scfsi[2];
|
|
|
56 |
|
|
|
57 |
struct granule {
|
|
|
58 |
struct channel {
|
|
|
59 |
/* from side info */
|
|
|
60 |
unsigned short part2_3_length;
|
|
|
61 |
unsigned short big_values;
|
|
|
62 |
unsigned short global_gain;
|
|
|
63 |
unsigned short scalefac_compress;
|
|
|
64 |
|
|
|
65 |
unsigned char flags;
|
|
|
66 |
unsigned char block_type;
|
|
|
67 |
unsigned char table_select[3];
|
|
|
68 |
unsigned char subblock_gain[3];
|
|
|
69 |
unsigned char region0_count;
|
|
|
70 |
unsigned char region1_count;
|
|
|
71 |
|
|
|
72 |
/* from main_data */
|
|
|
73 |
unsigned char scalefac[39]; /* scalefac_l and/or scalefac_s */
|
|
|
74 |
} ch[2];
|
|
|
75 |
} gr[2];
|
|
|
76 |
};
|
|
|
77 |
|
|
|
78 |
/*
|
|
|
79 |
* scalefactor bit lengths
|
|
|
80 |
* derived from section 2.4.2.7 of ISO/IEC 11172-3
|
|
|
81 |
*/
|
|
|
82 |
static
|
|
|
83 |
struct {
|
|
|
84 |
unsigned char slen1;
|
|
|
85 |
unsigned char slen2;
|
|
|
86 |
} const sflen_table[16] = {
|
|
|
87 |
{ 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 },
|
|
|
88 |
{ 3, 0 }, { 1, 1 }, { 1, 2 }, { 1, 3 },
|
|
|
89 |
{ 2, 1 }, { 2, 2 }, { 2, 3 }, { 3, 1 },
|
|
|
90 |
{ 3, 2 }, { 3, 3 }, { 4, 2 }, { 4, 3 }
|
|
|
91 |
};
|
|
|
92 |
|
|
|
93 |
/*
|
|
|
94 |
* number of LSF scalefactor band values
|
|
|
95 |
* derived from section 2.4.3.2 of ISO/IEC 13818-3
|
|
|
96 |
*/
|
|
|
97 |
static
|
|
|
98 |
unsigned char const nsfb_table[6][3][4] = {
|
|
|
99 |
{ { 6, 5, 5, 5 },
|
|
|
100 |
{ 9, 9, 9, 9 },
|
|
|
101 |
{ 6, 9, 9, 9 } },
|
|
|
102 |
|
|
|
103 |
{ { 6, 5, 7, 3 },
|
|
|
104 |
{ 9, 9, 12, 6 },
|
|
|
105 |
{ 6, 9, 12, 6 } },
|
|
|
106 |
|
|
|
107 |
{ { 11, 10, 0, 0 },
|
|
|
108 |
{ 18, 18, 0, 0 },
|
|
|
109 |
{ 15, 18, 0, 0 } },
|
|
|
110 |
|
|
|
111 |
{ { 7, 7, 7, 0 },
|
|
|
112 |
{ 12, 12, 12, 0 },
|
|
|
113 |
{ 6, 15, 12, 0 } },
|
|
|
114 |
|
|
|
115 |
{ { 6, 6, 6, 3 },
|
|
|
116 |
{ 12, 9, 9, 6 },
|
|
|
117 |
{ 6, 12, 9, 6 } },
|
|
|
118 |
|
|
|
119 |
{ { 8, 8, 5, 0 },
|
|
|
120 |
{ 15, 12, 9, 0 },
|
|
|
121 |
{ 6, 18, 9, 0 } }
|
|
|
122 |
};
|
|
|
123 |
|
|
|
124 |
/*
|
|
|
125 |
* MPEG-1 scalefactor band widths
|
|
|
126 |
* derived from Table B.8 of ISO/IEC 11172-3
|
|
|
127 |
*/
|
|
|
128 |
static
|
|
|
129 |
unsigned char const sfb_48000_long[] = {
|
|
|
130 |
4, 4, 4, 4, 4, 4, 6, 6, 6, 8, 10,
|
|
|
131 |
12, 16, 18, 22, 28, 34, 40, 46, 54, 54, 192
|
|
|
132 |
};
|
|
|
133 |
|
|
|
134 |
static
|
|
|
135 |
unsigned char const sfb_44100_long[] = {
|
|
|
136 |
4, 4, 4, 4, 4, 4, 6, 6, 8, 8, 10,
|
|
|
137 |
12, 16, 20, 24, 28, 34, 42, 50, 54, 76, 158
|
|
|
138 |
};
|
|
|
139 |
|
|
|
140 |
static
|
|
|
141 |
unsigned char const sfb_32000_long[] = {
|
|
|
142 |
4, 4, 4, 4, 4, 4, 6, 6, 8, 10, 12,
|
|
|
143 |
16, 20, 24, 30, 38, 46, 56, 68, 84, 102, 26
|
|
|
144 |
};
|
|
|
145 |
|
|
|
146 |
static
|
|
|
147 |
unsigned char const sfb_48000_short[] = {
|
|
|
148 |
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
|
|
|
149 |
6, 6, 6, 6, 6, 10, 10, 10, 12, 12, 12, 14, 14,
|
|
|
150 |
14, 16, 16, 16, 20, 20, 20, 26, 26, 26, 66, 66, 66
|
|
|
151 |
};
|
|
|
152 |
|
|
|
153 |
static
|
|
|
154 |
unsigned char const sfb_44100_short[] = {
|
|
|
155 |
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
|
|
|
156 |
6, 6, 8, 8, 8, 10, 10, 10, 12, 12, 12, 14, 14,
|
|
|
157 |
14, 18, 18, 18, 22, 22, 22, 30, 30, 30, 56, 56, 56
|
|
|
158 |
};
|
|
|
159 |
|
|
|
160 |
static
|
|
|
161 |
unsigned char const sfb_32000_short[] = {
|
|
|
162 |
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 6,
|
|
|
163 |
6, 6, 8, 8, 8, 12, 12, 12, 16, 16, 16, 20, 20,
|
|
|
164 |
20, 26, 26, 26, 34, 34, 34, 42, 42, 42, 12, 12, 12
|
|
|
165 |
};
|
|
|
166 |
|
|
|
167 |
static
|
|
|
168 |
unsigned char const sfb_48000_mixed[] = {
|
|
|
169 |
/* long */ 4, 4, 4, 4, 4, 4, 6, 6,
|
|
|
170 |
/* short */ 4, 4, 4, 6, 6, 6, 6, 6, 6, 10,
|
|
|
171 |
10, 10, 12, 12, 12, 14, 14, 14, 16, 16,
|
|
|
172 |
16, 20, 20, 20, 26, 26, 26, 66, 66, 66
|
|
|
173 |
};
|
|
|
174 |
|
|
|
175 |
static
|
|
|
176 |
unsigned char const sfb_44100_mixed[] = {
|
|
|
177 |
/* long */ 4, 4, 4, 4, 4, 4, 6, 6,
|
|
|
178 |
/* short */ 4, 4, 4, 6, 6, 6, 8, 8, 8, 10,
|
|
|
179 |
10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
|
|
|
180 |
18, 22, 22, 22, 30, 30, 30, 56, 56, 56
|
|
|
181 |
};
|
|
|
182 |
|
|
|
183 |
static
|
|
|
184 |
unsigned char const sfb_32000_mixed[] = {
|
|
|
185 |
/* long */ 4, 4, 4, 4, 4, 4, 6, 6,
|
|
|
186 |
/* short */ 4, 4, 4, 6, 6, 6, 8, 8, 8, 12,
|
|
|
187 |
12, 12, 16, 16, 16, 20, 20, 20, 26, 26,
|
|
|
188 |
26, 34, 34, 34, 42, 42, 42, 12, 12, 12
|
|
|
189 |
};
|
|
|
190 |
|
|
|
191 |
/*
|
|
|
192 |
* MPEG-2 scalefactor band widths
|
|
|
193 |
* derived from Table B.2 of ISO/IEC 13818-3
|
|
|
194 |
*/
|
|
|
195 |
static
|
|
|
196 |
unsigned char const sfb_24000_long[] = {
|
|
|
197 |
6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
|
|
|
198 |
18, 22, 26, 32, 38, 46, 54, 62, 70, 76, 36
|
|
|
199 |
};
|
|
|
200 |
|
|
|
201 |
static
|
|
|
202 |
unsigned char const sfb_22050_long[] = {
|
|
|
203 |
6, 6, 6, 6, 6, 6, 8, 10, 12, 14, 16,
|
|
|
204 |
20, 24, 28, 32, 38, 46, 52, 60, 68, 58, 54
|
|
|
205 |
};
|
|
|
206 |
|
|
|
207 |
# define sfb_16000_long sfb_22050_long
|
|
|
208 |
|
|
|
209 |
static
|
|
|
210 |
unsigned char const sfb_24000_short[] = {
|
|
|
211 |
4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8,
|
|
|
212 |
8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
|
|
|
213 |
18, 24, 24, 24, 32, 32, 32, 44, 44, 44, 12, 12, 12
|
|
|
214 |
};
|
|
|
215 |
|
|
|
216 |
static
|
|
|
217 |
unsigned char const sfb_22050_short[] = {
|
|
|
218 |
4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 6,
|
|
|
219 |
6, 6, 8, 8, 8, 10, 10, 10, 14, 14, 14, 18, 18,
|
|
|
220 |
18, 26, 26, 26, 32, 32, 32, 42, 42, 42, 18, 18, 18
|
|
|
221 |
};
|
|
|
222 |
|
|
|
223 |
static
|
|
|
224 |
unsigned char const sfb_16000_short[] = {
|
|
|
225 |
4, 4, 4, 4, 4, 4, 4, 4, 4, 6, 6, 6, 8,
|
|
|
226 |
8, 8, 10, 10, 10, 12, 12, 12, 14, 14, 14, 18, 18,
|
|
|
227 |
18, 24, 24, 24, 30, 30, 30, 40, 40, 40, 18, 18, 18
|
|
|
228 |
};
|
|
|
229 |
|
|
|
230 |
static
|
|
|
231 |
unsigned char const sfb_24000_mixed[] = {
|
|
|
232 |
/* long */ 6, 6, 6, 6, 6, 6,
|
|
|
233 |
/* short */ 6, 6, 6, 8, 8, 8, 10, 10, 10, 12,
|
|
|
234 |
12, 12, 14, 14, 14, 18, 18, 18, 24, 24,
|
|
|
235 |
24, 32, 32, 32, 44, 44, 44, 12, 12, 12
|
|
|
236 |
};
|
|
|
237 |
|
|
|
238 |
static
|
|
|
239 |
unsigned char const sfb_22050_mixed[] = {
|
|
|
240 |
/* long */ 6, 6, 6, 6, 6, 6,
|
|
|
241 |
/* short */ 6, 6, 6, 6, 6, 6, 8, 8, 8, 10,
|
|
|
242 |
10, 10, 14, 14, 14, 18, 18, 18, 26, 26,
|
|
|
243 |
26, 32, 32, 32, 42, 42, 42, 18, 18, 18
|
|
|
244 |
};
|
|
|
245 |
|
|
|
246 |
static
|
|
|
247 |
unsigned char const sfb_16000_mixed[] = {
|
|
|
248 |
/* long */ 6, 6, 6, 6, 6, 6,
|
|
|
249 |
/* short */ 6, 6, 6, 8, 8, 8, 10, 10, 10, 12,
|
|
|
250 |
12, 12, 14, 14, 14, 18, 18, 18, 24, 24,
|
|
|
251 |
24, 30, 30, 30, 40, 40, 40, 18, 18, 18
|
|
|
252 |
};
|
|
|
253 |
|
|
|
254 |
/*
|
|
|
255 |
* MPEG 2.5 scalefactor band widths
|
|
|
256 |
* derived from public sources
|
|
|
257 |
*/
|
|
|
258 |
# define sfb_12000_long sfb_16000_long
|
|
|
259 |
# define sfb_11025_long sfb_12000_long
|
|
|
260 |
|
|
|
261 |
static
|
|
|
262 |
unsigned char const sfb_8000_long[] = {
|
|
|
263 |
12, 12, 12, 12, 12, 12, 16, 20, 24, 28, 32,
|
|
|
264 |
40, 48, 56, 64, 76, 90, 2, 2, 2, 2, 2
|
|
|
265 |
};
|
|
|
266 |
|
|
|
267 |
# define sfb_12000_short sfb_16000_short
|
|
|
268 |
# define sfb_11025_short sfb_12000_short
|
|
|
269 |
|
|
|
270 |
static
|
|
|
271 |
unsigned char const sfb_8000_short[] = {
|
|
|
272 |
8, 8, 8, 8, 8, 8, 8, 8, 8, 12, 12, 12, 16,
|
|
|
273 |
16, 16, 20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36,
|
|
|
274 |
36, 2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26
|
|
|
275 |
};
|
|
|
276 |
|
|
|
277 |
# define sfb_12000_mixed sfb_16000_mixed
|
|
|
278 |
# define sfb_11025_mixed sfb_12000_mixed
|
|
|
279 |
|
|
|
280 |
/* the 8000 Hz short block scalefactor bands do not break after
|
|
|
281 |
the first 36 frequency lines, so this is probably wrong */
|
|
|
282 |
static
|
|
|
283 |
unsigned char const sfb_8000_mixed[] = {
|
|
|
284 |
/* long */ 12, 12, 12,
|
|
|
285 |
/* short */ 4, 4, 4, 8, 8, 8, 12, 12, 12, 16, 16, 16,
|
|
|
286 |
20, 20, 20, 24, 24, 24, 28, 28, 28, 36, 36, 36,
|
|
|
287 |
2, 2, 2, 2, 2, 2, 2, 2, 2, 26, 26, 26
|
|
|
288 |
};
|
|
|
289 |
|
|
|
290 |
static
|
|
|
291 |
struct {
|
|
|
292 |
unsigned char const *l;
|
|
|
293 |
unsigned char const *s;
|
|
|
294 |
unsigned char const *m;
|
|
|
295 |
} const sfbwidth_table[9] = {
|
|
|
296 |
{ sfb_48000_long, sfb_48000_short, sfb_48000_mixed },
|
|
|
297 |
{ sfb_44100_long, sfb_44100_short, sfb_44100_mixed },
|
|
|
298 |
{ sfb_32000_long, sfb_32000_short, sfb_32000_mixed },
|
|
|
299 |
{ sfb_24000_long, sfb_24000_short, sfb_24000_mixed },
|
|
|
300 |
{ sfb_22050_long, sfb_22050_short, sfb_22050_mixed },
|
|
|
301 |
{ sfb_16000_long, sfb_16000_short, sfb_16000_mixed },
|
|
|
302 |
{ sfb_12000_long, sfb_12000_short, sfb_12000_mixed },
|
|
|
303 |
{ sfb_11025_long, sfb_11025_short, sfb_11025_mixed },
|
|
|
304 |
{ sfb_8000_long, sfb_8000_short, sfb_8000_mixed }
|
|
|
305 |
};
|
|
|
306 |
|
|
|
307 |
/*
|
|
|
308 |
* scalefactor band preemphasis (used only when preflag is set)
|
|
|
309 |
* derived from Table B.6 of ISO/IEC 11172-3
|
|
|
310 |
*/
|
|
|
311 |
static
|
|
|
312 |
unsigned char const pretab[22] = {
|
|
|
313 |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0
|
|
|
314 |
};
|
|
|
315 |
|
|
|
316 |
/*
|
|
|
317 |
* table for requantization
|
|
|
318 |
*
|
|
|
319 |
* rq_table[x].mantissa * 2^(rq_table[x].exponent) = x^(4/3)
|
|
|
320 |
*/
|
|
|
321 |
static
|
|
|
322 |
struct fixedfloat {
|
|
|
323 |
unsigned long mantissa; // : 27;
|
|
|
324 |
unsigned short exponent; // : 5;
|
|
|
325 |
} const rq_table[8207] = {
|
|
|
326 |
# include "rq_table.dat"
|
|
|
327 |
};
|
|
|
328 |
|
|
|
329 |
/*
|
|
|
330 |
* fractional powers of two
|
|
|
331 |
* used for requantization and joint stereo decoding
|
|
|
332 |
*
|
|
|
333 |
* root_table[3 + x] = 2^(x/4)
|
|
|
334 |
*/
|
|
|
335 |
static
|
|
|
336 |
mad_fixed_t const root_table[7] = {
|
|
|
337 |
MAD_F(0x09837f05) /* 2^(-3/4) == 0.59460355750136 */,
|
|
|
338 |
MAD_F(0x0b504f33) /* 2^(-2/4) == 0.70710678118655 */,
|
|
|
339 |
MAD_F(0x0d744fcd) /* 2^(-1/4) == 0.84089641525371 */,
|
|
|
340 |
MAD_F(0x10000000) /* 2^( 0/4) == 1.00000000000000 */,
|
|
|
341 |
MAD_F(0x1306fe0a) /* 2^(+1/4) == 1.18920711500272 */,
|
|
|
342 |
MAD_F(0x16a09e66) /* 2^(+2/4) == 1.41421356237310 */,
|
|
|
343 |
MAD_F(0x1ae89f99) /* 2^(+3/4) == 1.68179283050743 */
|
|
|
344 |
};
|
|
|
345 |
|
|
|
346 |
/*
|
|
|
347 |
* coefficients for aliasing reduction
|
|
|
348 |
* derived from Table B.9 of ISO/IEC 11172-3
|
|
|
349 |
*
|
|
|
350 |
* c[] = { -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037 }
|
|
|
351 |
* cs[i] = 1 / sqrt(1 + c[i]^2)
|
|
|
352 |
* ca[i] = c[i] / sqrt(1 + c[i]^2)
|
|
|
353 |
*/
|
|
|
354 |
static
|
|
|
355 |
mad_fixed_t const cs[8] = {
|
|
|
356 |
+MAD_F(0x0db84a81) /* +0.857492926 */, +MAD_F(0x0e1b9d7f) /* +0.881741997 */,
|
|
|
357 |
+MAD_F(0x0f31adcf) /* +0.949628649 */, +MAD_F(0x0fbba815) /* +0.983314592 */,
|
|
|
358 |
+MAD_F(0x0feda417) /* +0.995517816 */, +MAD_F(0x0ffc8fc8) /* +0.999160558 */,
|
|
|
359 |
+MAD_F(0x0fff964c) /* +0.999899195 */, +MAD_F(0x0ffff8d3) /* +0.999993155 */
|
|
|
360 |
};
|
|
|
361 |
|
|
|
362 |
static
|
|
|
363 |
mad_fixed_t const ca[8] = {
|
|
|
364 |
-MAD_F(0x083b5fe7) /* -0.514495755 */, -MAD_F(0x078c36d2) /* -0.471731969 */,
|
|
|
365 |
-MAD_F(0x05039814) /* -0.313377454 */, -MAD_F(0x02e91dd1) /* -0.181913200 */,
|
|
|
366 |
-MAD_F(0x0183603a) /* -0.094574193 */, -MAD_F(0x00a7cb87) /* -0.040965583 */,
|
|
|
367 |
-MAD_F(0x003a2847) /* -0.014198569 */, -MAD_F(0x000f27b4) /* -0.003699975 */
|
|
|
368 |
};
|
|
|
369 |
|
|
|
370 |
/*
|
|
|
371 |
* IMDCT coefficients for short blocks
|
|
|
372 |
* derived from section 2.4.3.4.10.2 of ISO/IEC 11172-3
|
|
|
373 |
*
|
|
|
374 |
* imdct_s[i/even][k] = cos((PI / 24) * (2 * (i / 2) + 7) * (2 * k + 1))
|
|
|
375 |
* imdct_s[i /odd][k] = cos((PI / 24) * (2 * (6 + (i-1)/2) + 7) * (2 * k + 1))
|
|
|
376 |
*/
|
|
|
377 |
static
|
|
|
378 |
mad_fixed_t const imdct_s[6][6] = {
|
|
|
379 |
# include "imdct_s.dat"
|
|
|
380 |
};
|
|
|
381 |
|
|
|
382 |
# if !defined(ASO_IMDCT)
|
|
|
383 |
/*
|
|
|
384 |
* windowing coefficients for long blocks
|
|
|
385 |
* derived from section 2.4.3.4.10.3 of ISO/IEC 11172-3
|
|
|
386 |
*
|
|
|
387 |
* window_l[i] = sin((PI / 36) * (i + 1/2))
|
|
|
388 |
*/
|
|
|
389 |
static
|
|
|
390 |
mad_fixed_t const window_l[36] = {
|
|
|
391 |
MAD_F(0x00b2aa3e) /* 0.043619387 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
|
|
|
392 |
MAD_F(0x03768962) /* 0.216439614 */, MAD_F(0x04cfb0e2) /* 0.300705800 */,
|
|
|
393 |
MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x07635284) /* 0.461748613 */,
|
|
|
394 |
MAD_F(0x0898c779) /* 0.537299608 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
|
|
|
395 |
MAD_F(0x0acf37ad) /* 0.675590208 */, MAD_F(0x0bcbe352) /* 0.737277337 */,
|
|
|
396 |
MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x0d7e8807) /* 0.843391446 */,
|
|
|
397 |
|
|
|
398 |
MAD_F(0x0e313245) /* 0.887010833 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
|
|
|
399 |
MAD_F(0x0f426cb5) /* 0.953716951 */, MAD_F(0x0f9ee890) /* 0.976296007 */,
|
|
|
400 |
MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ffc19fd) /* 0.999048222 */,
|
|
|
401 |
MAD_F(0x0ffc19fd) /* 0.999048222 */, MAD_F(0x0fdcf549) /* 0.991444861 */,
|
|
|
402 |
MAD_F(0x0f9ee890) /* 0.976296007 */, MAD_F(0x0f426cb5) /* 0.953716951 */,
|
|
|
403 |
MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0e313245) /* 0.887010833 */,
|
|
|
404 |
|
|
|
405 |
MAD_F(0x0d7e8807) /* 0.843391446 */, MAD_F(0x0cb19346) /* 0.793353340 */,
|
|
|
406 |
MAD_F(0x0bcbe352) /* 0.737277337 */, MAD_F(0x0acf37ad) /* 0.675590208 */,
|
|
|
407 |
MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0898c779) /* 0.537299608 */,
|
|
|
408 |
MAD_F(0x07635284) /* 0.461748613 */, MAD_F(0x061f78aa) /* 0.382683432 */,
|
|
|
409 |
MAD_F(0x04cfb0e2) /* 0.300705800 */, MAD_F(0x03768962) /* 0.216439614 */,
|
|
|
410 |
MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x00b2aa3e) /* 0.043619387 */,
|
|
|
411 |
};
|
|
|
412 |
# endif /* ASO_IMDCT */
|
|
|
413 |
|
|
|
414 |
/*
|
|
|
415 |
* windowing coefficients for short blocks
|
|
|
416 |
* derived from section 2.4.3.4.10.3 of ISO/IEC 11172-3
|
|
|
417 |
*
|
|
|
418 |
* window_s[i] = sin((PI / 12) * (i + 1/2))
|
|
|
419 |
*/
|
|
|
420 |
static
|
|
|
421 |
mad_fixed_t const window_s[12] = {
|
|
|
422 |
MAD_F(0x0216a2a2) /* 0.130526192 */, MAD_F(0x061f78aa) /* 0.382683432 */,
|
|
|
423 |
MAD_F(0x09bd7ca0) /* 0.608761429 */, MAD_F(0x0cb19346) /* 0.793353340 */,
|
|
|
424 |
MAD_F(0x0ec835e8) /* 0.923879533 */, MAD_F(0x0fdcf549) /* 0.991444861 */,
|
|
|
425 |
MAD_F(0x0fdcf549) /* 0.991444861 */, MAD_F(0x0ec835e8) /* 0.923879533 */,
|
|
|
426 |
MAD_F(0x0cb19346) /* 0.793353340 */, MAD_F(0x09bd7ca0) /* 0.608761429 */,
|
|
|
427 |
MAD_F(0x061f78aa) /* 0.382683432 */, MAD_F(0x0216a2a2) /* 0.130526192 */,
|
|
|
428 |
};
|
|
|
429 |
|
|
|
430 |
/*
|
|
|
431 |
* coefficients for intensity stereo processing
|
|
|
432 |
* derived from section 2.4.3.4.9.3 of ISO/IEC 11172-3
|
|
|
433 |
*
|
|
|
434 |
* is_ratio[i] = tan(i * (PI / 12))
|
|
|
435 |
* is_table[i] = is_ratio[i] / (1 + is_ratio[i])
|
|
|
436 |
*/
|
|
|
437 |
static
|
|
|
438 |
mad_fixed_t const is_table[7] = {
|
|
|
439 |
MAD_F(0x00000000) /* 0.000000000 */,
|
|
|
440 |
MAD_F(0x0361962f) /* 0.211324865 */,
|
|
|
441 |
MAD_F(0x05db3d74) /* 0.366025404 */,
|
|
|
442 |
MAD_F(0x08000000) /* 0.500000000 */,
|
|
|
443 |
MAD_F(0x0a24c28c) /* 0.633974596 */,
|
|
|
444 |
MAD_F(0x0c9e69d1) /* 0.788675135 */,
|
|
|
445 |
MAD_F(0x10000000) /* 1.000000000 */
|
|
|
446 |
};
|
|
|
447 |
|
|
|
448 |
/*
|
|
|
449 |
* coefficients for LSF intensity stereo processing
|
|
|
450 |
* derived from section 2.4.3.2 of ISO/IEC 13818-3
|
|
|
451 |
*
|
|
|
452 |
* is_lsf_table[0][i] = (1 / sqrt(sqrt(2)))^(i + 1)
|
|
|
453 |
* is_lsf_table[1][i] = (1 / sqrt(2)) ^(i + 1)
|
|
|
454 |
*/
|
|
|
455 |
static
|
|
|
456 |
mad_fixed_t const is_lsf_table[2][15] = {
|
|
|
457 |
{
|
|
|
458 |
MAD_F(0x0d744fcd) /* 0.840896415 */,
|
|
|
459 |
MAD_F(0x0b504f33) /* 0.707106781 */,
|
|
|
460 |
MAD_F(0x09837f05) /* 0.594603558 */,
|
|
|
461 |
MAD_F(0x08000000) /* 0.500000000 */,
|
|
|
462 |
MAD_F(0x06ba27e6) /* 0.420448208 */,
|
|
|
463 |
MAD_F(0x05a8279a) /* 0.353553391 */,
|
|
|
464 |
MAD_F(0x04c1bf83) /* 0.297301779 */,
|
|
|
465 |
MAD_F(0x04000000) /* 0.250000000 */,
|
|
|
466 |
MAD_F(0x035d13f3) /* 0.210224104 */,
|
|
|
467 |
MAD_F(0x02d413cd) /* 0.176776695 */,
|
|
|
468 |
MAD_F(0x0260dfc1) /* 0.148650889 */,
|
|
|
469 |
MAD_F(0x02000000) /* 0.125000000 */,
|
|
|
470 |
MAD_F(0x01ae89fa) /* 0.105112052 */,
|
|
|
471 |
MAD_F(0x016a09e6) /* 0.088388348 */,
|
|
|
472 |
MAD_F(0x01306fe1) /* 0.074325445 */
|
|
|
473 |
}, {
|
|
|
474 |
MAD_F(0x0b504f33) /* 0.707106781 */,
|
|
|
475 |
MAD_F(0x08000000) /* 0.500000000 */,
|
|
|
476 |
MAD_F(0x05a8279a) /* 0.353553391 */,
|
|
|
477 |
MAD_F(0x04000000) /* 0.250000000 */,
|
|
|
478 |
MAD_F(0x02d413cd) /* 0.176776695 */,
|
|
|
479 |
MAD_F(0x02000000) /* 0.125000000 */,
|
|
|
480 |
MAD_F(0x016a09e6) /* 0.088388348 */,
|
|
|
481 |
MAD_F(0x01000000) /* 0.062500000 */,
|
|
|
482 |
MAD_F(0x00b504f3) /* 0.044194174 */,
|
|
|
483 |
MAD_F(0x00800000) /* 0.031250000 */,
|
|
|
484 |
MAD_F(0x005a827a) /* 0.022097087 */,
|
|
|
485 |
MAD_F(0x00400000) /* 0.015625000 */,
|
|
|
486 |
MAD_F(0x002d413d) /* 0.011048543 */,
|
|
|
487 |
MAD_F(0x00200000) /* 0.007812500 */,
|
|
|
488 |
MAD_F(0x0016a09e) /* 0.005524272 */
|
|
|
489 |
}
|
|
|
490 |
};
|
|
|
491 |
|
|
|
492 |
/*
|
|
|
493 |
* NAME: III_sideinfo()
|
|
|
494 |
* DESCRIPTION: decode frame side information from a bitstream
|
|
|
495 |
*/
|
|
|
496 |
static
|
|
|
497 |
enum mad_error III_sideinfo(struct mad_bitptr *ptr, unsigned int nch,
|
|
|
498 |
int lsf, struct sideinfo *si,
|
|
|
499 |
unsigned int *data_bitlen,
|
|
|
500 |
unsigned int *priv_bitlen)
|
|
|
501 |
{
|
|
|
502 |
unsigned int ngr, gr, ch, i;
|
|
|
503 |
enum mad_error result = MAD_ERROR_NONE;
|
|
|
504 |
|
|
|
505 |
*data_bitlen = 0;
|
|
|
506 |
*priv_bitlen = lsf ? ((nch == 1) ? 1 : 2) : ((nch == 1) ? 5 : 3);
|
|
|
507 |
|
|
|
508 |
si->main_data_begin = mad_bit_read(ptr, lsf ? 8 : 9);
|
|
|
509 |
si->private_bits = mad_bit_read(ptr, *priv_bitlen);
|
|
|
510 |
|
|
|
511 |
ngr = 1;
|
|
|
512 |
if (!lsf) {
|
|
|
513 |
ngr = 2;
|
|
|
514 |
|
|
|
515 |
for (ch = 0; ch < nch; ++ch)
|
|
|
516 |
si->scfsi[ch] = mad_bit_read(ptr, 4);
|
|
|
517 |
}
|
|
|
518 |
|
|
|
519 |
for (gr = 0; gr < ngr; ++gr) {
|
|
|
520 |
struct granule *granule = &si->gr[gr];
|
|
|
521 |
|
|
|
522 |
for (ch = 0; ch < nch; ++ch) {
|
|
|
523 |
struct channel *channel = &granule->ch[ch];
|
|
|
524 |
|
|
|
525 |
channel->part2_3_length = mad_bit_read(ptr, 12);
|
|
|
526 |
channel->big_values = mad_bit_read(ptr, 9);
|
|
|
527 |
channel->global_gain = mad_bit_read(ptr, 8);
|
|
|
528 |
channel->scalefac_compress = mad_bit_read(ptr, lsf ? 9 : 4);
|
|
|
529 |
|
|
|
530 |
*data_bitlen += channel->part2_3_length;
|
|
|
531 |
|
|
|
532 |
if (channel->big_values > 288 && result == 0)
|
|
|
533 |
result = MAD_ERROR_BADBIGVALUES;
|
|
|
534 |
|
|
|
535 |
channel->flags = 0;
|
|
|
536 |
|
|
|
537 |
/* window_switching_flag */
|
|
|
538 |
if (mad_bit_read(ptr, 1)) {
|
|
|
539 |
channel->block_type = mad_bit_read(ptr, 2);
|
|
|
540 |
|
|
|
541 |
if (channel->block_type == 0 && result == 0)
|
|
|
542 |
result = MAD_ERROR_BADBLOCKTYPE;
|
|
|
543 |
|
|
|
544 |
if (!lsf && channel->block_type == 2 && si->scfsi[ch] && result == 0)
|
|
|
545 |
result = MAD_ERROR_BADSCFSI;
|
|
|
546 |
|
|
|
547 |
channel->region0_count = 7;
|
|
|
548 |
channel->region1_count = 36;
|
|
|
549 |
|
|
|
550 |
if (mad_bit_read(ptr, 1))
|
|
|
551 |
channel->flags |= mixed_block_flag;
|
|
|
552 |
else if (channel->block_type == 2)
|
|
|
553 |
channel->region0_count = 8;
|
|
|
554 |
|
|
|
555 |
for (i = 0; i < 2; ++i)
|
|
|
556 |
channel->table_select[i] = mad_bit_read(ptr, 5);
|
|
|
557 |
|
|
|
558 |
# if defined(DEBUG)
|
|
|
559 |
channel->table_select[2] = 4; /* not used */
|
|
|
560 |
# endif
|
|
|
561 |
|
|
|
562 |
for (i = 0; i < 3; ++i)
|
|
|
563 |
channel->subblock_gain[i] = mad_bit_read(ptr, 3);
|
|
|
564 |
}
|
|
|
565 |
else {
|
|
|
566 |
channel->block_type = 0;
|
|
|
567 |
|
|
|
568 |
for (i = 0; i < 3; ++i)
|
|
|
569 |
channel->table_select[i] = mad_bit_read(ptr, 5);
|
|
|
570 |
|
|
|
571 |
channel->region0_count = mad_bit_read(ptr, 4);
|
|
|
572 |
channel->region1_count = mad_bit_read(ptr, 3);
|
|
|
573 |
}
|
|
|
574 |
|
|
|
575 |
/* [preflag,] scalefac_scale, count1table_select */
|
|
|
576 |
channel->flags |= mad_bit_read(ptr, lsf ? 2 : 3);
|
|
|
577 |
}
|
|
|
578 |
}
|
|
|
579 |
|
|
|
580 |
return result;
|
|
|
581 |
}
|
|
|
582 |
|
|
|
583 |
/*
|
|
|
584 |
* NAME: III_scalefactors_lsf()
|
|
|
585 |
* DESCRIPTION: decode channel scalefactors for LSF from a bitstream
|
|
|
586 |
*/
|
|
|
587 |
static
|
|
|
588 |
unsigned int III_scalefactors_lsf(struct mad_bitptr *ptr,
|
|
|
589 |
struct channel *channel,
|
|
|
590 |
struct channel *gr1ch, int mode_extension)
|
|
|
591 |
{
|
|
|
592 |
struct mad_bitptr start;
|
|
|
593 |
unsigned int scalefac_compress, index, slen[4], part, n, i;
|
|
|
594 |
unsigned char const *nsfb;
|
|
|
595 |
|
|
|
596 |
start = *ptr;
|
|
|
597 |
|
|
|
598 |
scalefac_compress = channel->scalefac_compress;
|
|
|
599 |
index = (channel->block_type == 2) ?
|
|
|
600 |
((channel->flags & mixed_block_flag) ? 2 : 1) : 0;
|
|
|
601 |
|
|
|
602 |
if (!((mode_extension & I_STEREO) && gr1ch)) {
|
|
|
603 |
if (scalefac_compress < 400) {
|
|
|
604 |
slen[0] = (scalefac_compress >> 4) / 5;
|
|
|
605 |
slen[1] = (scalefac_compress >> 4) % 5;
|
|
|
606 |
slen[2] = (scalefac_compress % 16) >> 2;
|
|
|
607 |
slen[3] = scalefac_compress % 4;
|
|
|
608 |
|
|
|
609 |
nsfb = nsfb_table[0][index];
|
|
|
610 |
}
|
|
|
611 |
else if (scalefac_compress < 500) {
|
|
|
612 |
scalefac_compress -= 400;
|
|
|
613 |
|
|
|
614 |
slen[0] = (scalefac_compress >> 2) / 5;
|
|
|
615 |
slen[1] = (scalefac_compress >> 2) % 5;
|
|
|
616 |
slen[2] = scalefac_compress % 4;
|
|
|
617 |
slen[3] = 0;
|
|
|
618 |
|
|
|
619 |
nsfb = nsfb_table[1][index];
|
|
|
620 |
}
|
|
|
621 |
else {
|
|
|
622 |
scalefac_compress -= 500;
|
|
|
623 |
|
|
|
624 |
slen[0] = scalefac_compress / 3;
|
|
|
625 |
slen[1] = scalefac_compress % 3;
|
|
|
626 |
slen[2] = 0;
|
|
|
627 |
slen[3] = 0;
|
|
|
628 |
|
|
|
629 |
channel->flags |= preflag;
|
|
|
630 |
|
|
|
631 |
nsfb = nsfb_table[2][index];
|
|
|
632 |
}
|
|
|
633 |
|
|
|
634 |
n = 0;
|
|
|
635 |
for (part = 0; part < 4; ++part) {
|
|
|
636 |
for (i = 0; i < nsfb[part]; ++i)
|
|
|
637 |
channel->scalefac[n++] = mad_bit_read(ptr, slen[part]);
|
|
|
638 |
}
|
|
|
639 |
|
|
|
640 |
while (n < 39)
|
|
|
641 |
channel->scalefac[n++] = 0;
|
|
|
642 |
}
|
|
|
643 |
else { /* (mode_extension & I_STEREO) && gr1ch (i.e. ch == 1) */
|
|
|
644 |
scalefac_compress >>= 1;
|
|
|
645 |
|
|
|
646 |
if (scalefac_compress < 180) {
|
|
|
647 |
slen[0] = scalefac_compress / 36;
|
|
|
648 |
slen[1] = (scalefac_compress % 36) / 6;
|
|
|
649 |
slen[2] = (scalefac_compress % 36) % 6;
|
|
|
650 |
slen[3] = 0;
|
|
|
651 |
|
|
|
652 |
nsfb = nsfb_table[3][index];
|
|
|
653 |
}
|
|
|
654 |
else if (scalefac_compress < 244) {
|
|
|
655 |
scalefac_compress -= 180;
|
|
|
656 |
|
|
|
657 |
slen[0] = (scalefac_compress % 64) >> 4;
|
|
|
658 |
slen[1] = (scalefac_compress % 16) >> 2;
|
|
|
659 |
slen[2] = scalefac_compress % 4;
|
|
|
660 |
slen[3] = 0;
|
|
|
661 |
|
|
|
662 |
nsfb = nsfb_table[4][index];
|
|
|
663 |
}
|
|
|
664 |
else {
|
|
|
665 |
scalefac_compress -= 244;
|
|
|
666 |
|
|
|
667 |
slen[0] = scalefac_compress / 3;
|
|
|
668 |
slen[1] = scalefac_compress % 3;
|
|
|
669 |
slen[2] = 0;
|
|
|
670 |
slen[3] = 0;
|
|
|
671 |
|
|
|
672 |
nsfb = nsfb_table[5][index];
|
|
|
673 |
}
|
|
|
674 |
|
|
|
675 |
n = 0;
|
|
|
676 |
for (part = 0; part < 4; ++part) {
|
|
|
677 |
unsigned int max, is_pos;
|
|
|
678 |
|
|
|
679 |
max = (1 << slen[part]) - 1;
|
|
|
680 |
|
|
|
681 |
for (i = 0; i < nsfb[part]; ++i) {
|
|
|
682 |
is_pos = mad_bit_read(ptr, slen[part]);
|
|
|
683 |
|
|
|
684 |
channel->scalefac[n] = is_pos;
|
|
|
685 |
gr1ch->scalefac[n++] = (is_pos == max);
|
|
|
686 |
}
|
|
|
687 |
}
|
|
|
688 |
|
|
|
689 |
while (n < 39) {
|
|
|
690 |
channel->scalefac[n] = 0;
|
|
|
691 |
gr1ch->scalefac[n++] = 0; /* apparently not illegal */
|
|
|
692 |
}
|
|
|
693 |
}
|
|
|
694 |
|
|
|
695 |
return mad_bit_length(&start, ptr);
|
|
|
696 |
}
|
|
|
697 |
|
|
|
698 |
/*
|
|
|
699 |
* NAME: III_scalefactors()
|
|
|
700 |
* DESCRIPTION: decode channel scalefactors of one granule from a bitstream
|
|
|
701 |
*/
|
|
|
702 |
static
|
|
|
703 |
unsigned int III_scalefactors(struct mad_bitptr *ptr, struct channel *channel,
|
|
|
704 |
struct channel const *gr0ch, unsigned int scfsi)
|
|
|
705 |
{
|
|
|
706 |
struct mad_bitptr start;
|
|
|
707 |
unsigned int slen1, slen2, sfbi;
|
|
|
708 |
|
|
|
709 |
start = *ptr;
|
|
|
710 |
|
|
|
711 |
slen1 = sflen_table[channel->scalefac_compress].slen1;
|
|
|
712 |
slen2 = sflen_table[channel->scalefac_compress].slen2;
|
|
|
713 |
|
|
|
714 |
if (channel->block_type == 2) {
|
|
|
715 |
unsigned int nsfb;
|
|
|
716 |
|
|
|
717 |
sfbi = 0;
|
|
|
718 |
|
|
|
719 |
nsfb = (channel->flags & mixed_block_flag) ? 8 + 3 * 3 : 6 * 3;
|
|
|
720 |
while (nsfb--)
|
|
|
721 |
channel->scalefac[sfbi++] = mad_bit_read(ptr, slen1);
|
|
|
722 |
|
|
|
723 |
nsfb = 6 * 3;
|
|
|
724 |
while (nsfb--)
|
|
|
725 |
channel->scalefac[sfbi++] = mad_bit_read(ptr, slen2);
|
|
|
726 |
|
|
|
727 |
nsfb = 1 * 3;
|
|
|
728 |
while (nsfb--)
|
|
|
729 |
channel->scalefac[sfbi++] = 0;
|
|
|
730 |
}
|
|
|
731 |
else { /* channel->block_type != 2 */
|
|
|
732 |
if (scfsi & 0x8) {
|
|
|
733 |
for (sfbi = 0; sfbi < 6; ++sfbi)
|
|
|
734 |
channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
|
|
|
735 |
}
|
|
|
736 |
else {
|
|
|
737 |
for (sfbi = 0; sfbi < 6; ++sfbi)
|
|
|
738 |
channel->scalefac[sfbi] = mad_bit_read(ptr, slen1);
|
|
|
739 |
}
|
|
|
740 |
|
|
|
741 |
if (scfsi & 0x4) {
|
|
|
742 |
for (sfbi = 6; sfbi < 11; ++sfbi)
|
|
|
743 |
channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
|
|
|
744 |
}
|
|
|
745 |
else {
|
|
|
746 |
for (sfbi = 6; sfbi < 11; ++sfbi)
|
|
|
747 |
channel->scalefac[sfbi] = mad_bit_read(ptr, slen1);
|
|
|
748 |
}
|
|
|
749 |
|
|
|
750 |
if (scfsi & 0x2) {
|
|
|
751 |
for (sfbi = 11; sfbi < 16; ++sfbi)
|
|
|
752 |
channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
|
|
|
753 |
}
|
|
|
754 |
else {
|
|
|
755 |
for (sfbi = 11; sfbi < 16; ++sfbi)
|
|
|
756 |
channel->scalefac[sfbi] = mad_bit_read(ptr, slen2);
|
|
|
757 |
}
|
|
|
758 |
|
|
|
759 |
if (scfsi & 0x1) {
|
|
|
760 |
for (sfbi = 16; sfbi < 21; ++sfbi)
|
|
|
761 |
channel->scalefac[sfbi] = gr0ch->scalefac[sfbi];
|
|
|
762 |
}
|
|
|
763 |
else {
|
|
|
764 |
for (sfbi = 16; sfbi < 21; ++sfbi)
|
|
|
765 |
channel->scalefac[sfbi] = mad_bit_read(ptr, slen2);
|
|
|
766 |
}
|
|
|
767 |
|
|
|
768 |
channel->scalefac[21] = 0;
|
|
|
769 |
}
|
|
|
770 |
|
|
|
771 |
return mad_bit_length(&start, ptr);
|
|
|
772 |
}
|
|
|
773 |
|
|
|
774 |
/*
|
|
|
775 |
* The Layer III formula for requantization and scaling is defined by
|
|
|
776 |
* section 2.4.3.4.7.1 of ISO/IEC 11172-3, as follows:
|
|
|
777 |
*
|
|
|
778 |
* long blocks:
|
|
|
779 |
* xr[i] = sign(is[i]) * abs(is[i])^(4/3) *
|
|
|
780 |
* 2^((1/4) * (global_gain - 210)) *
|
|
|
781 |
* 2^-(scalefac_multiplier *
|
|
|
782 |
* (scalefac_l[sfb] + preflag * pretab[sfb]))
|
|
|
783 |
*
|
|
|
784 |
* short blocks:
|
|
|
785 |
* xr[i] = sign(is[i]) * abs(is[i])^(4/3) *
|
|
|
786 |
* 2^((1/4) * (global_gain - 210 - 8 * subblock_gain[w])) *
|
|
|
787 |
* 2^-(scalefac_multiplier * scalefac_s[sfb][w])
|
|
|
788 |
*
|
|
|
789 |
* where:
|
|
|
790 |
* scalefac_multiplier = (scalefac_scale + 1) / 2
|
|
|
791 |
*
|
|
|
792 |
* The routines III_exponents() and III_requantize() facilitate this
|
|
|
793 |
* calculation.
|
|
|
794 |
*/
|
|
|
795 |
|
|
|
796 |
/*
|
|
|
797 |
* NAME: III_exponents()
|
|
|
798 |
* DESCRIPTION: calculate scalefactor exponents
|
|
|
799 |
*/
|
|
|
800 |
static
|
|
|
801 |
void III_exponents(struct channel const *channel,
|
|
|
802 |
unsigned char const *sfbwidth, signed int exponents[39])
|
|
|
803 |
{
|
|
|
804 |
signed int gain;
|
|
|
805 |
unsigned int scalefac_multiplier, sfbi;
|
|
|
806 |
|
|
|
807 |
gain = (signed int) channel->global_gain - 210;
|
|
|
808 |
scalefac_multiplier = (channel->flags & scalefac_scale) ? 2 : 1;
|
|
|
809 |
|
|
|
810 |
if (channel->block_type == 2) {
|
|
|
811 |
unsigned int l;
|
|
|
812 |
signed int gain0, gain1, gain2;
|
|
|
813 |
|
|
|
814 |
sfbi = l = 0;
|
|
|
815 |
|
|
|
816 |
if (channel->flags & mixed_block_flag) {
|
|
|
817 |
unsigned int premask;
|
|
|
818 |
|
|
|
819 |
premask = (channel->flags & preflag) ? ~0 : 0;
|
|
|
820 |
|
|
|
821 |
/* long block subbands 0-1 */
|
|
|
822 |
|
|
|
823 |
while (l < 36) {
|
|
|
824 |
exponents[sfbi] = gain -
|
|
|
825 |
(signed int) ((channel->scalefac[sfbi] + (pretab[sfbi] & premask)) <<
|
|
|
826 |
scalefac_multiplier);
|
|
|
827 |
|
|
|
828 |
l += sfbwidth[sfbi++];
|
|
|
829 |
}
|
|
|
830 |
}
|
|
|
831 |
|
|
|
832 |
/* this is probably wrong for 8000 Hz short/mixed blocks */
|
|
|
833 |
|
|
|
834 |
gain0 = gain - 8 * (signed int) channel->subblock_gain[0];
|
|
|
835 |
gain1 = gain - 8 * (signed int) channel->subblock_gain[1];
|
|
|
836 |
gain2 = gain - 8 * (signed int) channel->subblock_gain[2];
|
|
|
837 |
|
|
|
838 |
while (l < 576) {
|
|
|
839 |
exponents[sfbi + 0] = gain0 -
|
|
|
840 |
(signed int) (channel->scalefac[sfbi + 0] << scalefac_multiplier);
|
|
|
841 |
exponents[sfbi + 1] = gain1 -
|
|
|
842 |
(signed int) (channel->scalefac[sfbi + 1] << scalefac_multiplier);
|
|
|
843 |
exponents[sfbi + 2] = gain2 -
|
|
|
844 |
(signed int) (channel->scalefac[sfbi + 2] << scalefac_multiplier);
|
|
|
845 |
|
|
|
846 |
l += 3 * sfbwidth[sfbi];
|
|
|
847 |
sfbi += 3;
|
|
|
848 |
}
|
|
|
849 |
}
|
|
|
850 |
else { /* channel->block_type != 2 */
|
|
|
851 |
if (channel->flags & preflag) {
|
|
|
852 |
for (sfbi = 0; sfbi < 22; ++sfbi) {
|
|
|
853 |
exponents[sfbi] = gain -
|
|
|
854 |
(signed int) ((channel->scalefac[sfbi] + pretab[sfbi]) <<
|
|
|
855 |
scalefac_multiplier);
|
|
|
856 |
}
|
|
|
857 |
}
|
|
|
858 |
else {
|
|
|
859 |
for (sfbi = 0; sfbi < 22; ++sfbi) {
|
|
|
860 |
exponents[sfbi] = gain -
|
|
|
861 |
(signed int) (channel->scalefac[sfbi] << scalefac_multiplier);
|
|
|
862 |
}
|
|
|
863 |
}
|
|
|
864 |
}
|
|
|
865 |
}
|
|
|
866 |
|
|
|
867 |
/*
|
|
|
868 |
* NAME: III_requantize()
|
|
|
869 |
* DESCRIPTION: requantize one (positive) value
|
|
|
870 |
*/
|
|
|
871 |
static
|
|
|
872 |
mad_fixed_t III_requantize(unsigned int value, signed int exp)
|
|
|
873 |
{
|
|
|
874 |
mad_fixed_t requantized;
|
|
|
875 |
signed int frac;
|
|
|
876 |
struct fixedfloat const *power;
|
|
|
877 |
|
|
|
878 |
frac = exp % 4; /* assumes sign(frac) == sign(exp) */
|
|
|
879 |
exp /= 4;
|
|
|
880 |
|
|
|
881 |
power = &rq_table[value];
|
|
|
882 |
requantized = power->mantissa;
|
|
|
883 |
exp += power->exponent;
|
|
|
884 |
|
|
|
885 |
if (exp < 0) {
|
|
|
886 |
if (-exp >= sizeof(mad_fixed_t) * CHAR_BIT) {
|
|
|
887 |
/* underflow */
|
|
|
888 |
requantized = 0;
|
|
|
889 |
}
|
|
|
890 |
else {
|
|
|
891 |
requantized += 1L << (-exp - 1);
|
|
|
892 |
requantized >>= -exp;
|
|
|
893 |
}
|
|
|
894 |
}
|
|
|
895 |
else {
|
|
|
896 |
if (exp >= 5) {
|
|
|
897 |
/* overflow */
|
|
|
898 |
# if defined(DEBUG)
|
|
|
899 |
fprintf(stderr, "requantize overflow (%f * 2^%d)\n",
|
|
|
900 |
mad_f_todouble(requantized), exp);
|
|
|
901 |
# endif
|
|
|
902 |
requantized = MAD_F_MAX;
|
|
|
903 |
}
|
|
|
904 |
else
|
|
|
905 |
requantized <<= exp;
|
|
|
906 |
}
|
|
|
907 |
|
|
|
908 |
return frac ? mad_f_mul(requantized, root_table[3 + frac]) : requantized;
|
|
|
909 |
}
|
|
|
910 |
|
|
|
911 |
/* we must take care that sz >= bits and sz < sizeof(long) lest bits == 0 */
|
|
|
912 |
# define MASK(cache, sz, bits) \
|
|
|
913 |
(((cache) >> ((sz) - (bits))) & ((1 << (bits)) - 1))
|
|
|
914 |
# define MASK1BIT(cache, sz) \
|
|
|
915 |
((cache) & (1 << ((sz) - 1)))
|
|
|
916 |
|
|
|
917 |
/*
|
|
|
918 |
* NAME: III_huffdecode()
|
|
|
919 |
* DESCRIPTION: decode Huffman code words of one channel of one granule
|
|
|
920 |
*/
|
|
|
921 |
static
|
|
|
922 |
enum mad_error III_huffdecode(struct mad_bitptr *ptr, mad_fixed_t xr[576],
|
|
|
923 |
struct channel *channel,
|
|
|
924 |
unsigned char const *sfbwidth,
|
|
|
925 |
unsigned int part2_length)
|
|
|
926 |
{
|
|
|
927 |
signed int exponents[39], exp;
|
|
|
928 |
signed int const *expptr;
|
|
|
929 |
struct mad_bitptr peek;
|
|
|
930 |
signed int bits_left, cachesz;
|
|
|
931 |
register mad_fixed_t *xrptr;
|
|
|
932 |
mad_fixed_t const *sfbound;
|
|
|
933 |
register unsigned long bitcache;
|
|
|
934 |
|
|
|
935 |
bits_left = (signed) channel->part2_3_length - (signed) part2_length;
|
|
|
936 |
if (bits_left < 0)
|
|
|
937 |
return MAD_ERROR_BADPART3LEN;
|
|
|
938 |
|
|
|
939 |
III_exponents(channel, sfbwidth, exponents);
|
|
|
940 |
|
|
|
941 |
peek = *ptr;
|
|
|
942 |
mad_bit_skip(ptr, bits_left);
|
|
|
943 |
|
|
|
944 |
/* align bit reads to byte boundaries */
|
|
|
945 |
cachesz = mad_bit_bitsleft(&peek);
|
|
|
946 |
cachesz += ((32 - 1 - 24) + (24 - cachesz)) & ~7;
|
|
|
947 |
|
|
|
948 |
bitcache = mad_bit_read(&peek, cachesz);
|
|
|
949 |
bits_left -= cachesz;
|
|
|
950 |
|
|
|
951 |
xrptr = &xr[0];
|
|
|
952 |
|
|
|
953 |
/* big_values */
|
|
|
954 |
{
|
|
|
955 |
unsigned int region, rcount;
|
|
|
956 |
struct hufftable const *entry;
|
|
|
957 |
struct huffpair const *table;
|
|
|
958 |
unsigned int linbits, startbits, big_values, reqhits;
|
|
|
959 |
mad_fixed_t reqcache[16];
|
|
|
960 |
|
|
|
961 |
sfbound = xrptr + *sfbwidth++;
|
|
|
962 |
rcount = channel->region0_count + 1;
|
|
|
963 |
|
|
|
964 |
entry = &mad_huff_pair_table[channel->table_select[region = 0]];
|
|
|
965 |
table = entry->table;
|
|
|
966 |
linbits = entry->linbits;
|
|
|
967 |
startbits = entry->startbits;
|
|
|
968 |
|
|
|
969 |
if (table == 0)
|
|
|
970 |
return MAD_ERROR_BADHUFFTABLE;
|
|
|
971 |
|
|
|
972 |
expptr = &exponents[0];
|
|
|
973 |
exp = *expptr++;
|
|
|
974 |
reqhits = 0;
|
|
|
975 |
|
|
|
976 |
big_values = channel->big_values;
|
|
|
977 |
|
|
|
978 |
while (big_values-- && cachesz + bits_left > 0) {
|
|
|
979 |
struct huffpair const *pair;
|
|
|
980 |
unsigned int clumpsz, value;
|
|
|
981 |
register mad_fixed_t requantized;
|
|
|
982 |
|
|
|
983 |
if (xrptr == sfbound) {
|
|
|
984 |
sfbound += *sfbwidth++;
|
|
|
985 |
|
|
|
986 |
/* change table if region boundary */
|
|
|
987 |
|
|
|
988 |
if (--rcount == 0) {
|
|
|
989 |
if (region == 0)
|
|
|
990 |
rcount = channel->region1_count + 1;
|
|
|
991 |
else
|
|
|
992 |
rcount = 0; /* all remaining */
|
|
|
993 |
|
|
|
994 |
entry = &mad_huff_pair_table[channel->table_select[++region]];
|
|
|
995 |
table = entry->table;
|
|
|
996 |
linbits = entry->linbits;
|
|
|
997 |
startbits = entry->startbits;
|
|
|
998 |
|
|
|
999 |
if (table == 0)
|
|
|
1000 |
return MAD_ERROR_BADHUFFTABLE;
|
|
|
1001 |
}
|
|
|
1002 |
|
|
|
1003 |
if (exp != *expptr) {
|
|
|
1004 |
exp = *expptr;
|
|
|
1005 |
reqhits = 0;
|
|
|
1006 |
}
|
|
|
1007 |
|
|
|
1008 |
++expptr;
|
|
|
1009 |
}
|
|
|
1010 |
|
|
|
1011 |
if (cachesz < 21) {
|
|
|
1012 |
unsigned int bits;
|
|
|
1013 |
|
|
|
1014 |
bits = ((32 - 1 - 21) + (21 - cachesz)) & ~7;
|
|
|
1015 |
bitcache = (bitcache << bits) | mad_bit_read(&peek, bits);
|
|
|
1016 |
cachesz += bits;
|
|
|
1017 |
bits_left -= bits;
|
|
|
1018 |
}
|
|
|
1019 |
|
|
|
1020 |
/* hcod (0..19) */
|
|
|
1021 |
|
|
|
1022 |
clumpsz = startbits;
|
|
|
1023 |
pair = &table[MASK(bitcache, cachesz, clumpsz)];
|
|
|
1024 |
|
|
|
1025 |
while (!pair->final) {
|
|
|
1026 |
cachesz -= clumpsz;
|
|
|
1027 |
|
|
|
1028 |
clumpsz = pair->ptr.bits;
|
|
|
1029 |
pair = &table[pair->ptr.offset + MASK(bitcache, cachesz, clumpsz)];
|
|
|
1030 |
}
|
|
|
1031 |
|
|
|
1032 |
cachesz -= pair->value.hlen;
|
|
|
1033 |
|
|
|
1034 |
if (linbits) {
|
|
|
1035 |
/* x (0..14) */
|
|
|
1036 |
|
|
|
1037 |
value = pair->value.x;
|
|
|
1038 |
|
|
|
1039 |
switch (value) {
|
|
|
1040 |
case 0:
|
|
|
1041 |
xrptr[0] = 0;
|
|
|
1042 |
break;
|
|
|
1043 |
|
|
|
1044 |
case 15:
|
|
|
1045 |
if (cachesz < linbits + 2) {
|
|
|
1046 |
bitcache = (bitcache << 16) | mad_bit_read(&peek, 16);
|
|
|
1047 |
cachesz += 16;
|
|
|
1048 |
bits_left -= 16;
|
|
|
1049 |
}
|
|
|
1050 |
|
|
|
1051 |
value += MASK(bitcache, cachesz, linbits);
|
|
|
1052 |
cachesz -= linbits;
|
|
|
1053 |
|
|
|
1054 |
requantized = III_requantize(value, exp);
|
|
|
1055 |
goto x_final;
|
|
|
1056 |
|
|
|
1057 |
default:
|
|
|
1058 |
if (reqhits & (1 << value))
|
|
|
1059 |
requantized = reqcache[value];
|
|
|
1060 |
else {
|
|
|
1061 |
reqhits |= (1 << value);
|
|
|
1062 |
requantized = reqcache[value] = III_requantize(value, exp);
|
|
|
1063 |
}
|
|
|
1064 |
|
|
|
1065 |
x_final:
|
|
|
1066 |
xrptr[0] = MASK1BIT(bitcache, cachesz--) ?
|
|
|
1067 |
-requantized : requantized;
|
|
|
1068 |
}
|
|
|
1069 |
|
|
|
1070 |
/* y (0..14) */
|
|
|
1071 |
|
|
|
1072 |
value = pair->value.y;
|
|
|
1073 |
|
|
|
1074 |
switch (value) {
|
|
|
1075 |
case 0:
|
|
|
1076 |
xrptr[1] = 0;
|
|
|
1077 |
break;
|
|
|
1078 |
|
|
|
1079 |
case 15:
|
|
|
1080 |
if (cachesz < linbits + 1) {
|
|
|
1081 |
bitcache = (bitcache << 16) | mad_bit_read(&peek, 16);
|
|
|
1082 |
cachesz += 16;
|
|
|
1083 |
bits_left -= 16;
|
|
|
1084 |
}
|
|
|
1085 |
|
|
|
1086 |
value += MASK(bitcache, cachesz, linbits);
|
|
|
1087 |
cachesz -= linbits;
|
|
|
1088 |
|
|
|
1089 |
requantized = III_requantize(value, exp);
|
|
|
1090 |
goto y_final;
|
|
|
1091 |
|
|
|
1092 |
default:
|
|
|
1093 |
if (reqhits & (1 << value))
|
|
|
1094 |
requantized = reqcache[value];
|
|
|
1095 |
else {
|
|
|
1096 |
reqhits |= (1 << value);
|
|
|
1097 |
requantized = reqcache[value] = III_requantize(value, exp);
|
|
|
1098 |
}
|
|
|
1099 |
|
|
|
1100 |
y_final:
|
|
|
1101 |
xrptr[1] = MASK1BIT(bitcache, cachesz--) ?
|
|
|
1102 |
-requantized : requantized;
|
|
|
1103 |
}
|
|
|
1104 |
}
|
|
|
1105 |
else {
|
|
|
1106 |
/* x (0..1) */
|
|
|
1107 |
|
|
|
1108 |
value = pair->value.x;
|
|
|
1109 |
|
|
|
1110 |
if (value == 0)
|
|
|
1111 |
xrptr[0] = 0;
|
|
|
1112 |
else {
|
|
|
1113 |
if (reqhits & (1 << value))
|
|
|
1114 |
requantized = reqcache[value];
|
|
|
1115 |
else {
|
|
|
1116 |
reqhits |= (1 << value);
|
|
|
1117 |
requantized = reqcache[value] = III_requantize(value, exp);
|
|
|
1118 |
}
|
|
|
1119 |
|
|
|
1120 |
xrptr[0] = MASK1BIT(bitcache, cachesz--) ?
|
|
|
1121 |
-requantized : requantized;
|
|
|
1122 |
}
|
|
|
1123 |
|
|
|
1124 |
/* y (0..1) */
|
|
|
1125 |
|
|
|
1126 |
value = pair->value.y;
|
|
|
1127 |
|
|
|
1128 |
if (value == 0)
|
|
|
1129 |
xrptr[1] = 0;
|
|
|
1130 |
else {
|
|
|
1131 |
if (reqhits & (1 << value))
|
|
|
1132 |
requantized = reqcache[value];
|
|
|
1133 |
else {
|
|
|
1134 |
reqhits |= (1 << value);
|
|
|
1135 |
requantized = reqcache[value] = III_requantize(value, exp);
|
|
|
1136 |
}
|
|
|
1137 |
|
|
|
1138 |
xrptr[1] = MASK1BIT(bitcache, cachesz--) ?
|
|
|
1139 |
-requantized : requantized;
|
|
|
1140 |
}
|
|
|
1141 |
}
|
|
|
1142 |
|
|
|
1143 |
xrptr += 2;
|
|
|
1144 |
}
|
|
|
1145 |
}
|
|
|
1146 |
|
|
|
1147 |
if (cachesz + bits_left < 0)
|
|
|
1148 |
return MAD_ERROR_BADHUFFDATA; /* big_values overrun */
|
|
|
1149 |
|
|
|
1150 |
/* count1 */
|
|
|
1151 |
{
|
|
|
1152 |
struct huffquad const *table;
|
|
|
1153 |
register mad_fixed_t requantized;
|
|
|
1154 |
|
|
|
1155 |
table = mad_huff_quad_table[channel->flags & count1table_select];
|
|
|
1156 |
|
|
|
1157 |
requantized = III_requantize(1, exp);
|
|
|
1158 |
|
|
|
1159 |
while (cachesz + bits_left > 0 && xrptr <= &xr[572]) {
|
|
|
1160 |
struct huffquad const *quad;
|
|
|
1161 |
|
|
|
1162 |
/* hcod (1..6) */
|
|
|
1163 |
|
|
|
1164 |
if (cachesz < 10) {
|
|
|
1165 |
bitcache = (bitcache << 16) | mad_bit_read(&peek, 16);
|
|
|
1166 |
cachesz += 16;
|
|
|
1167 |
bits_left -= 16;
|
|
|
1168 |
}
|
|
|
1169 |
|
|
|
1170 |
quad = &table[MASK(bitcache, cachesz, 4)];
|
|
|
1171 |
|
|
|
1172 |
/* quad tables guaranteed to have at most one extra lookup */
|
|
|
1173 |
if (!quad->final) {
|
|
|
1174 |
cachesz -= 4;
|
|
|
1175 |
|
|
|
1176 |
quad = &table[quad->ptr.offset +
|
|
|
1177 |
MASK(bitcache, cachesz, quad->ptr.bits)];
|
|
|
1178 |
}
|
|
|
1179 |
|
|
|
1180 |
cachesz -= quad->value.hlen;
|
|
|
1181 |
|
|
|
1182 |
if (xrptr == sfbound) {
|
|
|
1183 |
sfbound += *sfbwidth++;
|
|
|
1184 |
|
|
|
1185 |
if (exp != *expptr) {
|
|
|
1186 |
exp = *expptr;
|
|
|
1187 |
requantized = III_requantize(1, exp);
|
|
|
1188 |
}
|
|
|
1189 |
|
|
|
1190 |
++expptr;
|
|
|
1191 |
}
|
|
|
1192 |
|
|
|
1193 |
/* v (0..1) */
|
|
|
1194 |
|
|
|
1195 |
xrptr[0] = quad->value.v ?
|
|
|
1196 |
(MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
|
|
|
1197 |
|
|
|
1198 |
/* w (0..1) */
|
|
|
1199 |
|
|
|
1200 |
xrptr[1] = quad->value.w ?
|
|
|
1201 |
(MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
|
|
|
1202 |
|
|
|
1203 |
xrptr += 2;
|
|
|
1204 |
|
|
|
1205 |
if (xrptr == sfbound) {
|
|
|
1206 |
sfbound += *sfbwidth++;
|
|
|
1207 |
|
|
|
1208 |
if (exp != *expptr) {
|
|
|
1209 |
exp = *expptr;
|
|
|
1210 |
requantized = III_requantize(1, exp);
|
|
|
1211 |
}
|
|
|
1212 |
|
|
|
1213 |
++expptr;
|
|
|
1214 |
}
|
|
|
1215 |
|
|
|
1216 |
/* x (0..1) */
|
|
|
1217 |
|
|
|
1218 |
xrptr[0] = quad->value.x ?
|
|
|
1219 |
(MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
|
|
|
1220 |
|
|
|
1221 |
/* y (0..1) */
|
|
|
1222 |
|
|
|
1223 |
xrptr[1] = quad->value.y ?
|
|
|
1224 |
(MASK1BIT(bitcache, cachesz--) ? -requantized : requantized) : 0;
|
|
|
1225 |
|
|
|
1226 |
xrptr += 2;
|
|
|
1227 |
}
|
|
|
1228 |
|
|
|
1229 |
if (cachesz + bits_left < 0) {
|
|
|
1230 |
# if 0 && defined(DEBUG)
|
|
|
1231 |
fprintf(stderr, "huffman count1 overrun (%d bits)\n",
|
|
|
1232 |
-(cachesz + bits_left));
|
|
|
1233 |
# endif
|
|
|
1234 |
|
|
|
1235 |
/* technically the bitstream is misformatted, but apparently
|
|
|
1236 |
some encoders are just a bit sloppy with stuffing bits */
|
|
|
1237 |
|
|
|
1238 |
xrptr -= 4;
|
|
|
1239 |
}
|
|
|
1240 |
}
|
|
|
1241 |
|
|
|
1242 |
assert(-bits_left <= MAD_BUFFER_GUARD * CHAR_BIT);
|
|
|
1243 |
|
|
|
1244 |
# if 0 && defined(DEBUG)
|
|
|
1245 |
if (bits_left < 0)
|
|
|
1246 |
fprintf(stderr, "read %d bits too many\n", -bits_left);
|
|
|
1247 |
else if (cachesz + bits_left > 0)
|
|
|
1248 |
fprintf(stderr, "%d stuffing bits\n", cachesz + bits_left);
|
|
|
1249 |
# endif
|
|
|
1250 |
|
|
|
1251 |
/* rzero */
|
|
|
1252 |
while (xrptr < &xr[576]) {
|
|
|
1253 |
xrptr[0] = 0;
|
|
|
1254 |
xrptr[1] = 0;
|
|
|
1255 |
|
|
|
1256 |
xrptr += 2;
|
|
|
1257 |
}
|
|
|
1258 |
|
|
|
1259 |
return MAD_ERROR_NONE;
|
|
|
1260 |
}
|
|
|
1261 |
|
|
|
1262 |
# undef MASK
|
|
|
1263 |
# undef MASK1BIT
|
|
|
1264 |
|
|
|
1265 |
/*
|
|
|
1266 |
* NAME: III_reorder()
|
|
|
1267 |
* DESCRIPTION: reorder frequency lines of a short block into subband order
|
|
|
1268 |
*/
|
|
|
1269 |
static
|
|
|
1270 |
void III_reorder(mad_fixed_t xr[576], struct channel const *channel,
|
|
|
1271 |
unsigned char const sfbwidth[39])
|
|
|
1272 |
{
|
|
|
1273 |
mad_fixed_t tmp[32][3][6];
|
|
|
1274 |
unsigned int sb, l, f, w, sbw[3], sw[3];
|
|
|
1275 |
|
|
|
1276 |
/* this is probably wrong for 8000 Hz mixed blocks */
|
|
|
1277 |
|
|
|
1278 |
sb = 0;
|
|
|
1279 |
if (channel->flags & mixed_block_flag) {
|
|
|
1280 |
sb = 2;
|
|
|
1281 |
|
|
|
1282 |
l = 0;
|
|
|
1283 |
while (l < 36)
|
|
|
1284 |
l += *sfbwidth++;
|
|
|
1285 |
}
|
|
|
1286 |
|
|
|
1287 |
for (w = 0; w < 3; ++w) {
|
|
|
1288 |
sbw[w] = sb;
|
|
|
1289 |
sw[w] = 0;
|
|
|
1290 |
}
|
|
|
1291 |
|
|
|
1292 |
f = *sfbwidth++;
|
|
|
1293 |
w = 0;
|
|
|
1294 |
|
|
|
1295 |
for (l = 18 * sb; l < 576; ++l) {
|
|
|
1296 |
if (f-- == 0) {
|
|
|
1297 |
f = *sfbwidth++ - 1;
|
|
|
1298 |
w = (w + 1) % 3;
|
|
|
1299 |
}
|
|
|
1300 |
|
|
|
1301 |
tmp[sbw[w]][w][sw[w]++] = xr[l];
|
|
|
1302 |
|
|
|
1303 |
if (sw[w] == 6) {
|
|
|
1304 |
sw[w] = 0;
|
|
|
1305 |
++sbw[w];
|
|
|
1306 |
}
|
|
|
1307 |
}
|
|
|
1308 |
|
|
|
1309 |
memcpy(&xr[18 * sb], &tmp[sb], (576 - 18 * sb) * sizeof(mad_fixed_t));
|
|
|
1310 |
}
|
|
|
1311 |
|
|
|
1312 |
/*
|
|
|
1313 |
* NAME: III_stereo()
|
|
|
1314 |
* DESCRIPTION: perform joint stereo processing on a granule
|
|
|
1315 |
*/
|
|
|
1316 |
static
|
|
|
1317 |
enum mad_error III_stereo(mad_fixed_t xr[2][576],
|
|
|
1318 |
struct granule const *granule,
|
|
|
1319 |
struct mad_header *header,
|
|
|
1320 |
unsigned char const *sfbwidth)
|
|
|
1321 |
{
|
|
|
1322 |
short modes[39];
|
|
|
1323 |
unsigned int sfbi, l, n, i;
|
|
|
1324 |
|
|
|
1325 |
if (granule->ch[0].block_type !=
|
|
|
1326 |
granule->ch[1].block_type ||
|
|
|
1327 |
(granule->ch[0].flags & mixed_block_flag) !=
|
|
|
1328 |
(granule->ch[1].flags & mixed_block_flag))
|
|
|
1329 |
return MAD_ERROR_BADSTEREO;
|
|
|
1330 |
|
|
|
1331 |
for (i = 0; i < 39; ++i)
|
|
|
1332 |
modes[i] = header->mode_extension;
|
|
|
1333 |
|
|
|
1334 |
/* intensity stereo */
|
|
|
1335 |
|
|
|
1336 |
if (header->mode_extension & I_STEREO) {
|
|
|
1337 |
struct channel const *right_ch = &granule->ch[1];
|
|
|
1338 |
mad_fixed_t const *right_xr = xr[1];
|
|
|
1339 |
unsigned int is_pos;
|
|
|
1340 |
|
|
|
1341 |
header->flags |= MAD_FLAG_I_STEREO;
|
|
|
1342 |
|
|
|
1343 |
/* first determine which scalefactor bands are to be processed */
|
|
|
1344 |
|
|
|
1345 |
if (right_ch->block_type == 2) {
|
|
|
1346 |
unsigned int lower, start, max, bound[3], w;
|
|
|
1347 |
|
|
|
1348 |
lower = start = max = bound[0] = bound[1] = bound[2] = 0;
|
|
|
1349 |
|
|
|
1350 |
sfbi = l = 0;
|
|
|
1351 |
|
|
|
1352 |
if (right_ch->flags & mixed_block_flag) {
|
|
|
1353 |
while (l < 36) {
|
|
|
1354 |
n = sfbwidth[sfbi++];
|
|
|
1355 |
|
|
|
1356 |
for (i = 0; i < n; ++i) {
|
|
|
1357 |
if (right_xr[i]) {
|
|
|
1358 |
lower = sfbi;
|
|
|
1359 |
break;
|
|
|
1360 |
}
|
|
|
1361 |
}
|
|
|
1362 |
|
|
|
1363 |
right_xr += n;
|
|
|
1364 |
l += n;
|
|
|
1365 |
}
|
|
|
1366 |
|
|
|
1367 |
start = sfbi;
|
|
|
1368 |
}
|
|
|
1369 |
|
|
|
1370 |
w = 0;
|
|
|
1371 |
while (l < 576) {
|
|
|
1372 |
n = sfbwidth[sfbi++];
|
|
|
1373 |
|
|
|
1374 |
for (i = 0; i < n; ++i) {
|
|
|
1375 |
if (right_xr[i]) {
|
|
|
1376 |
max = bound[w] = sfbi;
|
|
|
1377 |
break;
|
|
|
1378 |
}
|
|
|
1379 |
}
|
|
|
1380 |
|
|
|
1381 |
right_xr += n;
|
|
|
1382 |
l += n;
|
|
|
1383 |
w = (w + 1) % 3;
|
|
|
1384 |
}
|
|
|
1385 |
|
|
|
1386 |
if (max)
|
|
|
1387 |
lower = start;
|
|
|
1388 |
|
|
|
1389 |
/* long blocks */
|
|
|
1390 |
|
|
|
1391 |
for (i = 0; i < lower; ++i)
|
|
|
1392 |
modes[i] = header->mode_extension & ~I_STEREO;
|
|
|
1393 |
|
|
|
1394 |
/* short blocks */
|
|
|
1395 |
|
|
|
1396 |
w = 0;
|
|
|
1397 |
for (i = start; i < max; ++i) {
|
|
|
1398 |
if (i < bound[w])
|
|
|
1399 |
modes[i] = header->mode_extension & ~I_STEREO;
|
|
|
1400 |
|
|
|
1401 |
w = (w + 1) % 3;
|
|
|
1402 |
}
|
|
|
1403 |
}
|
|
|
1404 |
else { /* right_ch->block_type != 2 */
|
|
|
1405 |
unsigned int bound;
|
|
|
1406 |
|
|
|
1407 |
bound = 0;
|
|
|
1408 |
for (sfbi = l = 0; l < 576; l += n) {
|
|
|
1409 |
n = sfbwidth[sfbi++];
|
|
|
1410 |
|
|
|
1411 |
for (i = 0; i < n; ++i) {
|
|
|
1412 |
if (right_xr[i]) {
|
|
|
1413 |
bound = sfbi;
|
|
|
1414 |
break;
|
|
|
1415 |
}
|
|
|
1416 |
}
|
|
|
1417 |
|
|
|
1418 |
right_xr += n;
|
|
|
1419 |
}
|
|
|
1420 |
|
|
|
1421 |
for (i = 0; i < bound; ++i)
|
|
|
1422 |
modes[i] = header->mode_extension & ~I_STEREO;
|
|
|
1423 |
}
|
|
|
1424 |
|
|
|
1425 |
/* now do the actual processing */
|
|
|
1426 |
|
|
|
1427 |
if (header->flags & MAD_FLAG_LSF_EXT) {
|
|
|
1428 |
unsigned char const *illegal_pos = granule[1].ch[1].scalefac;
|
|
|
1429 |
mad_fixed_t const *lsf_scale;
|
|
|
1430 |
|
|
|
1431 |
/* intensity_scale */
|
|
|
1432 |
lsf_scale = is_lsf_table[right_ch->scalefac_compress & 0x1];
|
|
|
1433 |
|
|
|
1434 |
for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
|
|
|
1435 |
n = sfbwidth[sfbi];
|
|
|
1436 |
|
|
|
1437 |
if (!(modes[sfbi] & I_STEREO))
|
|
|
1438 |
continue;
|
|
|
1439 |
|
|
|
1440 |
if (illegal_pos[sfbi]) {
|
|
|
1441 |
modes[sfbi] &= ~I_STEREO;
|
|
|
1442 |
continue;
|
|
|
1443 |
}
|
|
|
1444 |
|
|
|
1445 |
is_pos = right_ch->scalefac[sfbi];
|
|
|
1446 |
|
|
|
1447 |
for (i = 0; i < n; ++i) {
|
|
|
1448 |
register mad_fixed_t left;
|
|
|
1449 |
|
|
|
1450 |
left = xr[0][l + i];
|
|
|
1451 |
|
|
|
1452 |
if (is_pos == 0)
|
|
|
1453 |
xr[1][l + i] = left;
|
|
|
1454 |
else {
|
|
|
1455 |
register mad_fixed_t opposite;
|
|
|
1456 |
|
|
|
1457 |
opposite = mad_f_mul(left, lsf_scale[(is_pos - 1) / 2]);
|
|
|
1458 |
|
|
|
1459 |
if (is_pos & 1) {
|
|
|
1460 |
xr[0][l + i] = opposite;
|
|
|
1461 |
xr[1][l + i] = left;
|
|
|
1462 |
}
|
|
|
1463 |
else
|
|
|
1464 |
xr[1][l + i] = opposite;
|
|
|
1465 |
}
|
|
|
1466 |
}
|
|
|
1467 |
}
|
|
|
1468 |
}
|
|
|
1469 |
else { /* !(header->flags & MAD_FLAG_LSF_EXT) */
|
|
|
1470 |
for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
|
|
|
1471 |
n = sfbwidth[sfbi];
|
|
|
1472 |
|
|
|
1473 |
if (!(modes[sfbi] & I_STEREO))
|
|
|
1474 |
continue;
|
|
|
1475 |
|
|
|
1476 |
is_pos = right_ch->scalefac[sfbi];
|
|
|
1477 |
|
|
|
1478 |
if (is_pos >= 7) { /* illegal intensity position */
|
|
|
1479 |
modes[sfbi] &= ~I_STEREO;
|
|
|
1480 |
continue;
|
|
|
1481 |
}
|
|
|
1482 |
|
|
|
1483 |
for (i = 0; i < n; ++i) {
|
|
|
1484 |
register mad_fixed_t left;
|
|
|
1485 |
|
|
|
1486 |
left = xr[0][l + i];
|
|
|
1487 |
|
|
|
1488 |
xr[0][l + i] = mad_f_mul(left, is_table[ is_pos]);
|
|
|
1489 |
xr[1][l + i] = mad_f_mul(left, is_table[6 - is_pos]);
|
|
|
1490 |
}
|
|
|
1491 |
}
|
|
|
1492 |
}
|
|
|
1493 |
}
|
|
|
1494 |
|
|
|
1495 |
/* middle/side stereo */
|
|
|
1496 |
|
|
|
1497 |
if (header->mode_extension & MS_STEREO) {
|
|
|
1498 |
register mad_fixed_t invsqrt2;
|
|
|
1499 |
|
|
|
1500 |
header->flags |= MAD_FLAG_MS_STEREO;
|
|
|
1501 |
|
|
|
1502 |
invsqrt2 = root_table[3 + -2];
|
|
|
1503 |
|
|
|
1504 |
for (sfbi = l = 0; l < 576; ++sfbi, l += n) {
|
|
|
1505 |
n = sfbwidth[sfbi];
|
|
|
1506 |
|
|
|
1507 |
if (modes[sfbi] != MS_STEREO)
|
|
|
1508 |
continue;
|
|
|
1509 |
|
|
|
1510 |
for (i = 0; i < n; ++i) {
|
|
|
1511 |
register mad_fixed_t m, s;
|
|
|
1512 |
|
|
|
1513 |
m = xr[0][l + i];
|
|
|
1514 |
s = xr[1][l + i];
|
|
|
1515 |
|
|
|
1516 |
xr[0][l + i] = mad_f_mul(m + s, invsqrt2); /* l = (m + s) / sqrt(2) */
|
|
|
1517 |
xr[1][l + i] = mad_f_mul(m - s, invsqrt2); /* r = (m - s) / sqrt(2) */
|
|
|
1518 |
}
|
|
|
1519 |
}
|
|
|
1520 |
}
|
|
|
1521 |
|
|
|
1522 |
return MAD_ERROR_NONE;
|
|
|
1523 |
}
|
|
|
1524 |
|
|
|
1525 |
/*
|
|
|
1526 |
* NAME: III_aliasreduce()
|
|
|
1527 |
* DESCRIPTION: perform frequency line alias reduction
|
|
|
1528 |
*/
|
|
|
1529 |
static
|
|
|
1530 |
void III_aliasreduce(mad_fixed_t xr[576], int lines)
|
|
|
1531 |
{
|
|
|
1532 |
mad_fixed_t const *bound;
|
|
|
1533 |
int i;
|
|
|
1534 |
|
|
|
1535 |
bound = &xr[lines];
|
|
|
1536 |
for (xr += 18; xr < bound; xr += 18) {
|
|
|
1537 |
for (i = 0; i < 8; ++i) {
|
|
|
1538 |
register mad_fixed_t a, b;
|
|
|
1539 |
register mad_fixed64hi_t hi;
|
|
|
1540 |
register mad_fixed64lo_t lo;
|
|
|
1541 |
|
|
|
1542 |
a = xr[-1 - i];
|
|
|
1543 |
b = xr[ i];
|
|
|
1544 |
|
|
|
1545 |
# if defined(ASO_ZEROCHECK)
|
|
|
1546 |
if (a | b) {
|
|
|
1547 |
# endif
|
|
|
1548 |
MAD_F_ML0(hi, lo, a, cs[i]);
|
|
|
1549 |
MAD_F_MLA(hi, lo, -b, ca[i]);
|
|
|
1550 |
|
|
|
1551 |
xr[-1 - i] = MAD_F_MLZ(hi, lo);
|
|
|
1552 |
|
|
|
1553 |
MAD_F_ML0(hi, lo, b, cs[i]);
|
|
|
1554 |
MAD_F_MLA(hi, lo, a, ca[i]);
|
|
|
1555 |
|
|
|
1556 |
xr[ i] = MAD_F_MLZ(hi, lo);
|
|
|
1557 |
# if defined(ASO_ZEROCHECK)
|
|
|
1558 |
}
|
|
|
1559 |
# endif
|
|
|
1560 |
}
|
|
|
1561 |
}
|
|
|
1562 |
}
|
|
|
1563 |
|
|
|
1564 |
# if defined(ASO_IMDCT)
|
|
|
1565 |
void III_imdct_l(mad_fixed_t const [18], mad_fixed_t [36], unsigned int);
|
|
|
1566 |
# else
|
|
|
1567 |
# if 1
|
|
|
1568 |
static
|
|
|
1569 |
void fastsdct(mad_fixed_t const x[9], mad_fixed_t y[18])
|
|
|
1570 |
{
|
|
|
1571 |
mad_fixed_t a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12;
|
|
|
1572 |
mad_fixed_t a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25;
|
|
|
1573 |
mad_fixed_t m0, m1, m2, m3, m4, m5, m6, m7;
|
|
|
1574 |
|
|
|
1575 |
enum {
|
|
|
1576 |
c0 = MAD_F(0x1f838b8d), /* 2 * cos( 1 * PI / 18) */
|
|
|
1577 |
c1 = MAD_F(0x1bb67ae8), /* 2 * cos( 3 * PI / 18) */
|
|
|
1578 |
c2 = MAD_F(0x18836fa3), /* 2 * cos( 4 * PI / 18) */
|
|
|
1579 |
c3 = MAD_F(0x1491b752), /* 2 * cos( 5 * PI / 18) */
|
|
|
1580 |
c4 = MAD_F(0x0af1d43a), /* 2 * cos( 7 * PI / 18) */
|
|
|
1581 |
c5 = MAD_F(0x058e86a0), /* 2 * cos( 8 * PI / 18) */
|
|
|
1582 |
c6 = -MAD_F(0x1e11f642) /* 2 * cos(16 * PI / 18) */
|
|
|
1583 |
};
|
|
|
1584 |
|
|
|
1585 |
a0 = x[3] + x[5];
|
|
|
1586 |
a1 = x[3] - x[5];
|
|
|
1587 |
a2 = x[6] + x[2];
|
|
|
1588 |
a3 = x[6] - x[2];
|
|
|
1589 |
a4 = x[1] + x[7];
|
|
|
1590 |
a5 = x[1] - x[7];
|
|
|
1591 |
a6 = x[8] + x[0];
|
|
|
1592 |
a7 = x[8] - x[0];
|
|
|
1593 |
|
|
|
1594 |
a8 = a0 + a2;
|
|
|
1595 |
a9 = a0 - a2;
|
|
|
1596 |
a10 = a0 - a6;
|
|
|
1597 |
a11 = a2 - a6;
|
|
|
1598 |
a12 = a8 + a6;
|
|
|
1599 |
a13 = a1 - a3;
|
|
|
1600 |
a14 = a13 + a7;
|
|
|
1601 |
a15 = a3 + a7;
|
|
|
1602 |
a16 = a1 - a7;
|
|
|
1603 |
a17 = a1 + a3;
|
|
|
1604 |
|
|
|
1605 |
m0 = mad_f_mul(a17, -c3);
|
|
|
1606 |
m1 = mad_f_mul(a16, -c0);
|
|
|
1607 |
m2 = mad_f_mul(a15, -c4);
|
|
|
1608 |
m3 = mad_f_mul(a14, -c1);
|
|
|
1609 |
m4 = mad_f_mul(a5, -c1);
|
|
|
1610 |
m5 = mad_f_mul(a11, -c6);
|
|
|
1611 |
m6 = mad_f_mul(a10, -c5);
|
|
|
1612 |
m7 = mad_f_mul(a9, -c2);
|
|
|
1613 |
|
|
|
1614 |
a18 = x[4] + a4;
|
|
|
1615 |
a19 = 2 * x[4] - a4;
|
|
|
1616 |
a20 = a19 + m5;
|
|
|
1617 |
a21 = a19 - m5;
|
|
|
1618 |
a22 = a19 + m6;
|
|
|
1619 |
a23 = m4 + m2;
|
|
|
1620 |
a24 = m4 - m2;
|
|
|
1621 |
a25 = m4 + m1;
|
|
|
1622 |
|
|
|
1623 |
/* output to every other slot for convenience */
|
|
|
1624 |
|
|
|
1625 |
y[ 0] = a18 + a12;
|
|
|
1626 |
y[ 2] = m0 - a25;
|
|
|
1627 |
y[ 4] = m7 - a20;
|
|
|
1628 |
y[ 6] = m3;
|
|
|
1629 |
y[ 8] = a21 - m6;
|
|
|
1630 |
y[10] = a24 - m1;
|
|
|
1631 |
y[12] = a12 - 2 * a18;
|
|
|
1632 |
y[14] = a23 + m0;
|
|
|
1633 |
y[16] = a22 + m7;
|
|
|
1634 |
}
|
|
|
1635 |
|
|
|
1636 |
static inline
|
|
|
1637 |
void sdctII(mad_fixed_t const x[18], mad_fixed_t X[18])
|
|
|
1638 |
{
|
|
|
1639 |
mad_fixed_t tmp[9];
|
|
|
1640 |
int i;
|
|
|
1641 |
|
|
|
1642 |
/* scale[i] = 2 * cos(PI * (2 * i + 1) / (2 * 18)) */
|
|
|
1643 |
static mad_fixed_t const scale[9] = {
|
|
|
1644 |
MAD_F(0x1fe0d3b4), MAD_F(0x1ee8dd47), MAD_F(0x1d007930),
|
|
|
1645 |
MAD_F(0x1a367e59), MAD_F(0x16a09e66), MAD_F(0x125abcf8),
|
|
|
1646 |
MAD_F(0x0d8616bc), MAD_F(0x08483ee1), MAD_F(0x02c9fad7)
|
|
|
1647 |
};
|
|
|
1648 |
|
|
|
1649 |
/* divide the 18-point SDCT-II into two 9-point SDCT-IIs */
|
|
|
1650 |
|
|
|
1651 |
/* even input butterfly */
|
|
|
1652 |
|
|
|
1653 |
for (i = 0; i < 9; i += 3) {
|
|
|
1654 |
tmp[i + 0] = x[i + 0] + x[18 - (i + 0) - 1];
|
|
|
1655 |
tmp[i + 1] = x[i + 1] + x[18 - (i + 1) - 1];
|
|
|
1656 |
tmp[i + 2] = x[i + 2] + x[18 - (i + 2) - 1];
|
|
|
1657 |
}
|
|
|
1658 |
|
|
|
1659 |
fastsdct(tmp, &X[0]);
|
|
|
1660 |
|
|
|
1661 |
/* odd input butterfly and scaling */
|
|
|
1662 |
|
|
|
1663 |
for (i = 0; i < 9; i += 3) {
|
|
|
1664 |
tmp[i + 0] = mad_f_mul(x[i + 0] - x[18 - (i + 0) - 1], scale[i + 0]);
|
|
|
1665 |
tmp[i + 1] = mad_f_mul(x[i + 1] - x[18 - (i + 1) - 1], scale[i + 1]);
|
|
|
1666 |
tmp[i + 2] = mad_f_mul(x[i + 2] - x[18 - (i + 2) - 1], scale[i + 2]);
|
|
|
1667 |
}
|
|
|
1668 |
|
|
|
1669 |
fastsdct(tmp, &X[1]);
|
|
|
1670 |
|
|
|
1671 |
/* output accumulation */
|
|
|
1672 |
|
|
|
1673 |
for (i = 3; i < 18; i += 8) {
|
|
|
1674 |
X[i + 0] -= X[(i + 0) - 2];
|
|
|
1675 |
X[i + 2] -= X[(i + 2) - 2];
|
|
|
1676 |
X[i + 4] -= X[(i + 4) - 2];
|
|
|
1677 |
X[i + 6] -= X[(i + 6) - 2];
|
|
|
1678 |
}
|
|
|
1679 |
}
|
|
|
1680 |
|
|
|
1681 |
static inline
|
|
|
1682 |
void dctIV(mad_fixed_t const y[18], mad_fixed_t X[18])
|
|
|
1683 |
{
|
|
|
1684 |
mad_fixed_t tmp[18];
|
|
|
1685 |
int i;
|
|
|
1686 |
|
|
|
1687 |
/* scale[i] = 2 * cos(PI * (2 * i + 1) / (4 * 18)) */
|
|
|
1688 |
static mad_fixed_t const scale[18] = {
|
|
|
1689 |
MAD_F(0x1ff833fa), MAD_F(0x1fb9ea93), MAD_F(0x1f3dd120),
|
|
|
1690 |
MAD_F(0x1e84d969), MAD_F(0x1d906bcf), MAD_F(0x1c62648b),
|
|
|
1691 |
MAD_F(0x1afd100f), MAD_F(0x1963268b), MAD_F(0x1797c6a4),
|
|
|
1692 |
MAD_F(0x159e6f5b), MAD_F(0x137af940), MAD_F(0x11318ef3),
|
|
|
1693 |
MAD_F(0x0ec6a507), MAD_F(0x0c3ef153), MAD_F(0x099f61c5),
|
|
|
1694 |
MAD_F(0x06ed12c5), MAD_F(0x042d4544), MAD_F(0x0165547c)
|
|
|
1695 |
};
|
|
|
1696 |
|
|
|
1697 |
/* scaling */
|
|
|
1698 |
|
|
|
1699 |
for (i = 0; i < 18; i += 3) {
|
|
|
1700 |
tmp[i + 0] = mad_f_mul(y[i + 0], scale[i + 0]);
|
|
|
1701 |
tmp[i + 1] = mad_f_mul(y[i + 1], scale[i + 1]);
|
|
|
1702 |
tmp[i + 2] = mad_f_mul(y[i + 2], scale[i + 2]);
|
|
|
1703 |
}
|
|
|
1704 |
|
|
|
1705 |
/* SDCT-II */
|
|
|
1706 |
|
|
|
1707 |
sdctII(tmp, X);
|
|
|
1708 |
|
|
|
1709 |
/* scale reduction and output accumulation */
|
|
|
1710 |
|
|
|
1711 |
X[0] /= 2;
|
|
|
1712 |
for (i = 1; i < 17; i += 4) {
|
|
|
1713 |
X[i + 0] = X[i + 0] / 2 - X[(i + 0) - 1];
|
|
|
1714 |
X[i + 1] = X[i + 1] / 2 - X[(i + 1) - 1];
|
|
|
1715 |
X[i + 2] = X[i + 2] / 2 - X[(i + 2) - 1];
|
|
|
1716 |
X[i + 3] = X[i + 3] / 2 - X[(i + 3) - 1];
|
|
|
1717 |
}
|
|
|
1718 |
X[17] = X[17] / 2 - X[16];
|
|
|
1719 |
}
|
|
|
1720 |
|
|
|
1721 |
/*
|
|
|
1722 |
* NAME: imdct36
|
|
|
1723 |
* DESCRIPTION: perform X[18]->x[36] IMDCT using Szu-Wei Lee's fast algorithm
|
|
|
1724 |
*/
|
|
|
1725 |
static inline
|
|
|
1726 |
void imdct36(mad_fixed_t const x[18], mad_fixed_t y[36])
|
|
|
1727 |
{
|
|
|
1728 |
mad_fixed_t tmp[18];
|
|
|
1729 |
int i;
|
|
|
1730 |
|
|
|
1731 |
/* DCT-IV */
|
|
|
1732 |
|
|
|
1733 |
dctIV(x, tmp);
|
|
|
1734 |
|
|
|
1735 |
/* convert 18-point DCT-IV to 36-point IMDCT */
|
|
|
1736 |
|
|
|
1737 |
for (i = 0; i < 9; i += 3) {
|
|
|
1738 |
y[i + 0] = tmp[9 + (i + 0)];
|
|
|
1739 |
y[i + 1] = tmp[9 + (i + 1)];
|
|
|
1740 |
y[i + 2] = tmp[9 + (i + 2)];
|
|
|
1741 |
}
|
|
|
1742 |
for (i = 9; i < 27; i += 3) {
|
|
|
1743 |
y[i + 0] = -tmp[36 - (9 + (i + 0)) - 1];
|
|
|
1744 |
y[i + 1] = -tmp[36 - (9 + (i + 1)) - 1];
|
|
|
1745 |
y[i + 2] = -tmp[36 - (9 + (i + 2)) - 1];
|
|
|
1746 |
}
|
|
|
1747 |
for (i = 27; i < 36; i += 3) {
|
|
|
1748 |
y[i + 0] = -tmp[(i + 0) - 27];
|
|
|
1749 |
y[i + 1] = -tmp[(i + 1) - 27];
|
|
|
1750 |
y[i + 2] = -tmp[(i + 2) - 27];
|
|
|
1751 |
}
|
|
|
1752 |
}
|
|
|
1753 |
# else
|
|
|
1754 |
/*
|
|
|
1755 |
* NAME: imdct36
|
|
|
1756 |
* DESCRIPTION: perform X[18]->x[36] IMDCT
|
|
|
1757 |
*/
|
|
|
1758 |
static inline
|
|
|
1759 |
void imdct36(mad_fixed_t const X[18], mad_fixed_t x[36])
|
|
|
1760 |
{
|
|
|
1761 |
mad_fixed_t t0, t1, t2, t3, t4, t5, t6, t7;
|
|
|
1762 |
mad_fixed_t t8, t9, t10, t11, t12, t13, t14, t15;
|
|
|
1763 |
register mad_fixed64hi_t hi;
|
|
|
1764 |
register mad_fixed64lo_t lo;
|
|
|
1765 |
|
|
|
1766 |
MAD_F_ML0(hi, lo, X[4], MAD_F(0x0ec835e8));
|
|
|
1767 |
MAD_F_MLA(hi, lo, X[13], MAD_F(0x061f78aa));
|
|
|
1768 |
|
|
|
1769 |
t6 = MAD_F_MLZ(hi, lo);
|
|
|
1770 |
|
|
|
1771 |
MAD_F_MLA(hi, lo, (t14 = X[1] - X[10]), -MAD_F(0x061f78aa));
|
|
|
1772 |
MAD_F_MLA(hi, lo, (t15 = X[7] + X[16]), -MAD_F(0x0ec835e8));
|
|
|
1773 |
|
|
|
1774 |
t0 = MAD_F_MLZ(hi, lo);
|
|
|
1775 |
|
|
|
1776 |
MAD_F_MLA(hi, lo, (t8 = X[0] - X[11] - X[12]), MAD_F(0x0216a2a2));
|
|
|
1777 |
MAD_F_MLA(hi, lo, (t9 = X[2] - X[9] - X[14]), MAD_F(0x09bd7ca0));
|
|
|
1778 |
MAD_F_MLA(hi, lo, (t10 = X[3] - X[8] - X[15]), -MAD_F(0x0cb19346));
|
|
|
1779 |
MAD_F_MLA(hi, lo, (t11 = X[5] - X[6] - X[17]), -MAD_F(0x0fdcf549));
|
|
|
1780 |
|
|
|
1781 |
x[7] = MAD_F_MLZ(hi, lo);
|
|
|
1782 |
x[10] = -x[7];
|
|
|
1783 |
|
|
|
1784 |
MAD_F_ML0(hi, lo, t8, -MAD_F(0x0cb19346));
|
|
|
1785 |
MAD_F_MLA(hi, lo, t9, MAD_F(0x0fdcf549));
|
|
|
1786 |
MAD_F_MLA(hi, lo, t10, MAD_F(0x0216a2a2));
|
|
|
1787 |
MAD_F_MLA(hi, lo, t11, -MAD_F(0x09bd7ca0));
|
|
|
1788 |
|
|
|
1789 |
x[19] = x[34] = MAD_F_MLZ(hi, lo) - t0;
|
|
|
1790 |
|
|
|
1791 |
t12 = X[0] - X[3] + X[8] - X[11] - X[12] + X[15];
|
|
|
1792 |
t13 = X[2] + X[5] - X[6] - X[9] - X[14] - X[17];
|
|
|
1793 |
|
|
|
1794 |
MAD_F_ML0(hi, lo, t12, -MAD_F(0x0ec835e8));
|
|
|
1795 |
MAD_F_MLA(hi, lo, t13, MAD_F(0x061f78aa));
|
|
|
1796 |
|
|
|
1797 |
x[22] = x[31] = MAD_F_MLZ(hi, lo) + t0;
|
|
|
1798 |
|
|
|
1799 |
MAD_F_ML0(hi, lo, X[1], -MAD_F(0x09bd7ca0));
|
|
|
1800 |
MAD_F_MLA(hi, lo, X[7], MAD_F(0x0216a2a2));
|
|
|
1801 |
MAD_F_MLA(hi, lo, X[10], -MAD_F(0x0fdcf549));
|
|
|
1802 |
MAD_F_MLA(hi, lo, X[16], MAD_F(0x0cb19346));
|
|
|
1803 |
|
|
|
1804 |
t1 = MAD_F_MLZ(hi, lo) + t6;
|
|
|
1805 |
|
|
|
1806 |
MAD_F_ML0(hi, lo, X[0], MAD_F(0x03768962));
|
|
|
1807 |
MAD_F_MLA(hi, lo, X[2], MAD_F(0x0e313245));
|
|
|
1808 |
MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0ffc19fd));
|
|
|
1809 |
MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0acf37ad));
|
|
|
1810 |
MAD_F_MLA(hi, lo, X[6], MAD_F(0x04cfb0e2));
|
|
|
1811 |
MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0898c779));
|
|
|
1812 |
MAD_F_MLA(hi, lo, X[9], MAD_F(0x0d7e8807));
|
|
|
1813 |
MAD_F_MLA(hi, lo, X[11], MAD_F(0x0f426cb5));
|
|
|
1814 |
MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0bcbe352));
|
|
|
1815 |
MAD_F_MLA(hi, lo, X[14], MAD_F(0x00b2aa3e));
|
|
|
1816 |
MAD_F_MLA(hi, lo, X[15], -MAD_F(0x07635284));
|
|
|
1817 |
MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0f9ee890));
|
|
|
1818 |
|
|
|
1819 |
x[6] = MAD_F_MLZ(hi, lo) + t1;
|
|
|
1820 |
x[11] = -x[6];
|
|
|
1821 |
|
|
|
1822 |
MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0f426cb5));
|
|
|
1823 |
MAD_F_MLA(hi, lo, X[2], -MAD_F(0x00b2aa3e));
|
|
|
1824 |
MAD_F_MLA(hi, lo, X[3], MAD_F(0x0898c779));
|
|
|
1825 |
MAD_F_MLA(hi, lo, X[5], MAD_F(0x0f9ee890));
|
|
|
1826 |
MAD_F_MLA(hi, lo, X[6], MAD_F(0x0acf37ad));
|
|
|
1827 |
MAD_F_MLA(hi, lo, X[8], -MAD_F(0x07635284));
|
|
|
1828 |
MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0e313245));
|
|
|
1829 |
MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0bcbe352));
|
|
|
1830 |
MAD_F_MLA(hi, lo, X[12], -MAD_F(0x03768962));
|
|
|
1831 |
MAD_F_MLA(hi, lo, X[14], MAD_F(0x0d7e8807));
|
|
|
1832 |
MAD_F_MLA(hi, lo, X[15], MAD_F(0x0ffc19fd));
|
|
|
1833 |
MAD_F_MLA(hi, lo, X[17], MAD_F(0x04cfb0e2));
|
|
|
1834 |
|
|
|
1835 |
x[23] = x[30] = MAD_F_MLZ(hi, lo) + t1;
|
|
|
1836 |
|
|
|
1837 |
MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0bcbe352));
|
|
|
1838 |
MAD_F_MLA(hi, lo, X[2], MAD_F(0x0d7e8807));
|
|
|
1839 |
MAD_F_MLA(hi, lo, X[3], -MAD_F(0x07635284));
|
|
|
1840 |
MAD_F_MLA(hi, lo, X[5], MAD_F(0x04cfb0e2));
|
|
|
1841 |
MAD_F_MLA(hi, lo, X[6], MAD_F(0x0f9ee890));
|
|
|
1842 |
MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0ffc19fd));
|
|
|
1843 |
MAD_F_MLA(hi, lo, X[9], -MAD_F(0x00b2aa3e));
|
|
|
1844 |
MAD_F_MLA(hi, lo, X[11], MAD_F(0x03768962));
|
|
|
1845 |
MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0f426cb5));
|
|
|
1846 |
MAD_F_MLA(hi, lo, X[14], MAD_F(0x0e313245));
|
|
|
1847 |
MAD_F_MLA(hi, lo, X[15], MAD_F(0x0898c779));
|
|
|
1848 |
MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0acf37ad));
|
|
|
1849 |
|
|
|
1850 |
x[18] = x[35] = MAD_F_MLZ(hi, lo) - t1;
|
|
|
1851 |
|
|
|
1852 |
MAD_F_ML0(hi, lo, X[4], MAD_F(0x061f78aa));
|
|
|
1853 |
MAD_F_MLA(hi, lo, X[13], -MAD_F(0x0ec835e8));
|
|
|
1854 |
|
|
|
1855 |
t7 = MAD_F_MLZ(hi, lo);
|
|
|
1856 |
|
|
|
1857 |
MAD_F_MLA(hi, lo, X[1], -MAD_F(0x0cb19346));
|
|
|
1858 |
MAD_F_MLA(hi, lo, X[7], MAD_F(0x0fdcf549));
|
|
|
1859 |
MAD_F_MLA(hi, lo, X[10], MAD_F(0x0216a2a2));
|
|
|
1860 |
MAD_F_MLA(hi, lo, X[16], -MAD_F(0x09bd7ca0));
|
|
|
1861 |
|
|
|
1862 |
t2 = MAD_F_MLZ(hi, lo);
|
|
|
1863 |
|
|
|
1864 |
MAD_F_MLA(hi, lo, X[0], MAD_F(0x04cfb0e2));
|
|
|
1865 |
MAD_F_MLA(hi, lo, X[2], MAD_F(0x0ffc19fd));
|
|
|
1866 |
MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0d7e8807));
|
|
|
1867 |
MAD_F_MLA(hi, lo, X[5], MAD_F(0x03768962));
|
|
|
1868 |
MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0bcbe352));
|
|
|
1869 |
MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0e313245));
|
|
|
1870 |
MAD_F_MLA(hi, lo, X[9], MAD_F(0x07635284));
|
|
|
1871 |
MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0acf37ad));
|
|
|
1872 |
MAD_F_MLA(hi, lo, X[12], MAD_F(0x0f9ee890));
|
|
|
1873 |
MAD_F_MLA(hi, lo, X[14], MAD_F(0x0898c779));
|
|
|
1874 |
MAD_F_MLA(hi, lo, X[15], MAD_F(0x00b2aa3e));
|
|
|
1875 |
MAD_F_MLA(hi, lo, X[17], MAD_F(0x0f426cb5));
|
|
|
1876 |
|
|
|
1877 |
x[5] = MAD_F_MLZ(hi, lo);
|
|
|
1878 |
x[12] = -x[5];
|
|
|
1879 |
|
|
|
1880 |
MAD_F_ML0(hi, lo, X[0], MAD_F(0x0acf37ad));
|
|
|
1881 |
MAD_F_MLA(hi, lo, X[2], -MAD_F(0x0898c779));
|
|
|
1882 |
MAD_F_MLA(hi, lo, X[3], MAD_F(0x0e313245));
|
|
|
1883 |
MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0f426cb5));
|
|
|
1884 |
MAD_F_MLA(hi, lo, X[6], -MAD_F(0x03768962));
|
|
|
1885 |
MAD_F_MLA(hi, lo, X[8], MAD_F(0x00b2aa3e));
|
|
|
1886 |
MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0ffc19fd));
|
|
|
1887 |
MAD_F_MLA(hi, lo, X[11], MAD_F(0x0f9ee890));
|
|
|
1888 |
MAD_F_MLA(hi, lo, X[12], -MAD_F(0x04cfb0e2));
|
|
|
1889 |
MAD_F_MLA(hi, lo, X[14], MAD_F(0x07635284));
|
|
|
1890 |
MAD_F_MLA(hi, lo, X[15], MAD_F(0x0d7e8807));
|
|
|
1891 |
MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0bcbe352));
|
|
|
1892 |
|
|
|
1893 |
x[0] = MAD_F_MLZ(hi, lo) + t2;
|
|
|
1894 |
x[17] = -x[0];
|
|
|
1895 |
|
|
|
1896 |
MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0f9ee890));
|
|
|
1897 |
MAD_F_MLA(hi, lo, X[2], -MAD_F(0x07635284));
|
|
|
1898 |
MAD_F_MLA(hi, lo, X[3], -MAD_F(0x00b2aa3e));
|
|
|
1899 |
MAD_F_MLA(hi, lo, X[5], MAD_F(0x0bcbe352));
|
|
|
1900 |
MAD_F_MLA(hi, lo, X[6], MAD_F(0x0f426cb5));
|
|
|
1901 |
MAD_F_MLA(hi, lo, X[8], MAD_F(0x0d7e8807));
|
|
|
1902 |
MAD_F_MLA(hi, lo, X[9], MAD_F(0x0898c779));
|
|
|
1903 |
MAD_F_MLA(hi, lo, X[11], -MAD_F(0x04cfb0e2));
|
|
|
1904 |
MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0acf37ad));
|
|
|
1905 |
MAD_F_MLA(hi, lo, X[14], -MAD_F(0x0ffc19fd));
|
|
|
1906 |
MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0e313245));
|
|
|
1907 |
MAD_F_MLA(hi, lo, X[17], -MAD_F(0x03768962));
|
|
|
1908 |
|
|
|
1909 |
x[24] = x[29] = MAD_F_MLZ(hi, lo) + t2;
|
|
|
1910 |
|
|
|
1911 |
MAD_F_ML0(hi, lo, X[1], -MAD_F(0x0216a2a2));
|
|
|
1912 |
MAD_F_MLA(hi, lo, X[7], -MAD_F(0x09bd7ca0));
|
|
|
1913 |
MAD_F_MLA(hi, lo, X[10], MAD_F(0x0cb19346));
|
|
|
1914 |
MAD_F_MLA(hi, lo, X[16], MAD_F(0x0fdcf549));
|
|
|
1915 |
|
|
|
1916 |
t3 = MAD_F_MLZ(hi, lo) + t7;
|
|
|
1917 |
|
|
|
1918 |
MAD_F_ML0(hi, lo, X[0], MAD_F(0x00b2aa3e));
|
|
|
1919 |
MAD_F_MLA(hi, lo, X[2], MAD_F(0x03768962));
|
|
|
1920 |
MAD_F_MLA(hi, lo, X[3], -MAD_F(0x04cfb0e2));
|
|
|
1921 |
MAD_F_MLA(hi, lo, X[5], -MAD_F(0x07635284));
|
|
|
1922 |
MAD_F_MLA(hi, lo, X[6], MAD_F(0x0898c779));
|
|
|
1923 |
MAD_F_MLA(hi, lo, X[8], MAD_F(0x0acf37ad));
|
|
|
1924 |
MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0bcbe352));
|
|
|
1925 |
MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0d7e8807));
|
|
|
1926 |
MAD_F_MLA(hi, lo, X[12], MAD_F(0x0e313245));
|
|
|
1927 |
MAD_F_MLA(hi, lo, X[14], MAD_F(0x0f426cb5));
|
|
|
1928 |
MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0f9ee890));
|
|
|
1929 |
MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0ffc19fd));
|
|
|
1930 |
|
|
|
1931 |
x[8] = MAD_F_MLZ(hi, lo) + t3;
|
|
|
1932 |
x[9] = -x[8];
|
|
|
1933 |
|
|
|
1934 |
MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0e313245));
|
|
|
1935 |
MAD_F_MLA(hi, lo, X[2], MAD_F(0x0bcbe352));
|
|
|
1936 |
MAD_F_MLA(hi, lo, X[3], MAD_F(0x0f9ee890));
|
|
|
1937 |
MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0898c779));
|
|
|
1938 |
MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0ffc19fd));
|
|
|
1939 |
MAD_F_MLA(hi, lo, X[8], MAD_F(0x04cfb0e2));
|
|
|
1940 |
MAD_F_MLA(hi, lo, X[9], MAD_F(0x0f426cb5));
|
|
|
1941 |
MAD_F_MLA(hi, lo, X[11], -MAD_F(0x00b2aa3e));
|
|
|
1942 |
MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0d7e8807));
|
|
|
1943 |
MAD_F_MLA(hi, lo, X[14], -MAD_F(0x03768962));
|
|
|
1944 |
MAD_F_MLA(hi, lo, X[15], MAD_F(0x0acf37ad));
|
|
|
1945 |
MAD_F_MLA(hi, lo, X[17], MAD_F(0x07635284));
|
|
|
1946 |
|
|
|
1947 |
x[21] = x[32] = MAD_F_MLZ(hi, lo) + t3;
|
|
|
1948 |
|
|
|
1949 |
MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0d7e8807));
|
|
|
1950 |
MAD_F_MLA(hi, lo, X[2], MAD_F(0x0f426cb5));
|
|
|
1951 |
MAD_F_MLA(hi, lo, X[3], MAD_F(0x0acf37ad));
|
|
|
1952 |
MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0ffc19fd));
|
|
|
1953 |
MAD_F_MLA(hi, lo, X[6], -MAD_F(0x07635284));
|
|
|
1954 |
MAD_F_MLA(hi, lo, X[8], MAD_F(0x0f9ee890));
|
|
|
1955 |
MAD_F_MLA(hi, lo, X[9], MAD_F(0x03768962));
|
|
|
1956 |
MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0e313245));
|
|
|
1957 |
MAD_F_MLA(hi, lo, X[12], MAD_F(0x00b2aa3e));
|
|
|
1958 |
MAD_F_MLA(hi, lo, X[14], MAD_F(0x0bcbe352));
|
|
|
1959 |
MAD_F_MLA(hi, lo, X[15], -MAD_F(0x04cfb0e2));
|
|
|
1960 |
MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0898c779));
|
|
|
1961 |
|
|
|
1962 |
x[20] = x[33] = MAD_F_MLZ(hi, lo) - t3;
|
|
|
1963 |
|
|
|
1964 |
MAD_F_ML0(hi, lo, t14, -MAD_F(0x0ec835e8));
|
|
|
1965 |
MAD_F_MLA(hi, lo, t15, MAD_F(0x061f78aa));
|
|
|
1966 |
|
|
|
1967 |
t4 = MAD_F_MLZ(hi, lo) - t7;
|
|
|
1968 |
|
|
|
1969 |
MAD_F_ML0(hi, lo, t12, MAD_F(0x061f78aa));
|
|
|
1970 |
MAD_F_MLA(hi, lo, t13, MAD_F(0x0ec835e8));
|
|
|
1971 |
|
|
|
1972 |
x[4] = MAD_F_MLZ(hi, lo) + t4;
|
|
|
1973 |
x[13] = -x[4];
|
|
|
1974 |
|
|
|
1975 |
MAD_F_ML0(hi, lo, t8, MAD_F(0x09bd7ca0));
|
|
|
1976 |
MAD_F_MLA(hi, lo, t9, -MAD_F(0x0216a2a2));
|
|
|
1977 |
MAD_F_MLA(hi, lo, t10, MAD_F(0x0fdcf549));
|
|
|
1978 |
MAD_F_MLA(hi, lo, t11, -MAD_F(0x0cb19346));
|
|
|
1979 |
|
|
|
1980 |
x[1] = MAD_F_MLZ(hi, lo) + t4;
|
|
|
1981 |
x[16] = -x[1];
|
|
|
1982 |
|
|
|
1983 |
MAD_F_ML0(hi, lo, t8, -MAD_F(0x0fdcf549));
|
|
|
1984 |
MAD_F_MLA(hi, lo, t9, -MAD_F(0x0cb19346));
|
|
|
1985 |
MAD_F_MLA(hi, lo, t10, -MAD_F(0x09bd7ca0));
|
|
|
1986 |
MAD_F_MLA(hi, lo, t11, -MAD_F(0x0216a2a2));
|
|
|
1987 |
|
|
|
1988 |
x[25] = x[28] = MAD_F_MLZ(hi, lo) + t4;
|
|
|
1989 |
|
|
|
1990 |
MAD_F_ML0(hi, lo, X[1], -MAD_F(0x0fdcf549));
|
|
|
1991 |
MAD_F_MLA(hi, lo, X[7], -MAD_F(0x0cb19346));
|
|
|
1992 |
MAD_F_MLA(hi, lo, X[10], -MAD_F(0x09bd7ca0));
|
|
|
1993 |
MAD_F_MLA(hi, lo, X[16], -MAD_F(0x0216a2a2));
|
|
|
1994 |
|
|
|
1995 |
t5 = MAD_F_MLZ(hi, lo) - t6;
|
|
|
1996 |
|
|
|
1997 |
MAD_F_ML0(hi, lo, X[0], MAD_F(0x0898c779));
|
|
|
1998 |
MAD_F_MLA(hi, lo, X[2], MAD_F(0x04cfb0e2));
|
|
|
1999 |
MAD_F_MLA(hi, lo, X[3], MAD_F(0x0bcbe352));
|
|
|
2000 |
MAD_F_MLA(hi, lo, X[5], MAD_F(0x00b2aa3e));
|
|
|
2001 |
MAD_F_MLA(hi, lo, X[6], MAD_F(0x0e313245));
|
|
|
2002 |
MAD_F_MLA(hi, lo, X[8], -MAD_F(0x03768962));
|
|
|
2003 |
MAD_F_MLA(hi, lo, X[9], MAD_F(0x0f9ee890));
|
|
|
2004 |
MAD_F_MLA(hi, lo, X[11], -MAD_F(0x07635284));
|
|
|
2005 |
MAD_F_MLA(hi, lo, X[12], MAD_F(0x0ffc19fd));
|
|
|
2006 |
MAD_F_MLA(hi, lo, X[14], -MAD_F(0x0acf37ad));
|
|
|
2007 |
MAD_F_MLA(hi, lo, X[15], MAD_F(0x0f426cb5));
|
|
|
2008 |
MAD_F_MLA(hi, lo, X[17], -MAD_F(0x0d7e8807));
|
|
|
2009 |
|
|
|
2010 |
x[2] = MAD_F_MLZ(hi, lo) + t5;
|
|
|
2011 |
x[15] = -x[2];
|
|
|
2012 |
|
|
|
2013 |
MAD_F_ML0(hi, lo, X[0], MAD_F(0x07635284));
|
|
|
2014 |
MAD_F_MLA(hi, lo, X[2], MAD_F(0x0acf37ad));
|
|
|
2015 |
MAD_F_MLA(hi, lo, X[3], MAD_F(0x03768962));
|
|
|
2016 |
MAD_F_MLA(hi, lo, X[5], MAD_F(0x0d7e8807));
|
|
|
2017 |
MAD_F_MLA(hi, lo, X[6], -MAD_F(0x00b2aa3e));
|
|
|
2018 |
MAD_F_MLA(hi, lo, X[8], MAD_F(0x0f426cb5));
|
|
|
2019 |
MAD_F_MLA(hi, lo, X[9], -MAD_F(0x04cfb0e2));
|
|
|
2020 |
MAD_F_MLA(hi, lo, X[11], MAD_F(0x0ffc19fd));
|
|
|
2021 |
MAD_F_MLA(hi, lo, X[12], -MAD_F(0x0898c779));
|
|
|
2022 |
MAD_F_MLA(hi, lo, X[14], MAD_F(0x0f9ee890));
|
|
|
2023 |
MAD_F_MLA(hi, lo, X[15], -MAD_F(0x0bcbe352));
|
|
|
2024 |
MAD_F_MLA(hi, lo, X[17], MAD_F(0x0e313245));
|
|
|
2025 |
|
|
|
2026 |
x[3] = MAD_F_MLZ(hi, lo) + t5;
|
|
|
2027 |
x[14] = -x[3];
|
|
|
2028 |
|
|
|
2029 |
MAD_F_ML0(hi, lo, X[0], -MAD_F(0x0ffc19fd));
|
|
|
2030 |
MAD_F_MLA(hi, lo, X[2], -MAD_F(0x0f9ee890));
|
|
|
2031 |
MAD_F_MLA(hi, lo, X[3], -MAD_F(0x0f426cb5));
|
|
|
2032 |
MAD_F_MLA(hi, lo, X[5], -MAD_F(0x0e313245));
|
|
|
2033 |
MAD_F_MLA(hi, lo, X[6], -MAD_F(0x0d7e8807));
|
|
|
2034 |
MAD_F_MLA(hi, lo, X[8], -MAD_F(0x0bcbe352));
|
|
|
2035 |
MAD_F_MLA(hi, lo, X[9], -MAD_F(0x0acf37ad));
|
|
|
2036 |
MAD_F_MLA(hi, lo, X[11], -MAD_F(0x0898c779));
|
|
|
2037 |
MAD_F_MLA(hi, lo, X[12], -MAD_F(0x07635284));
|
|
|
2038 |
MAD_F_MLA(hi, lo, X[14], -MAD_F(0x04cfb0e2));
|
|
|
2039 |
MAD_F_MLA(hi, lo, X[15], -MAD_F(0x03768962));
|
|
|
2040 |
MAD_F_MLA(hi, lo, X[17], -MAD_F(0x00b2aa3e));
|
|
|
2041 |
|
|
|
2042 |
x[26] = x[27] = MAD_F_MLZ(hi, lo) + t5;
|
|
|
2043 |
}
|
|
|
2044 |
# endif
|
|
|
2045 |
|
|
|
2046 |
/*
|
|
|
2047 |
* NAME: III_imdct_l()
|
|
|
2048 |
* DESCRIPTION: perform IMDCT and windowing for long blocks
|
|
|
2049 |
*/
|
|
|
2050 |
static
|
|
|
2051 |
void III_imdct_l(mad_fixed_t const X[18], mad_fixed_t z[36],
|
|
|
2052 |
unsigned int block_type)
|
|
|
2053 |
{
|
|
|
2054 |
unsigned int i;
|
|
|
2055 |
|
|
|
2056 |
/* IMDCT */
|
|
|
2057 |
|
|
|
2058 |
imdct36(X, z);
|
|
|
2059 |
|
|
|
2060 |
/* windowing */
|
|
|
2061 |
|
|
|
2062 |
switch (block_type) {
|
|
|
2063 |
case 0: /* normal window */
|
|
|
2064 |
# if defined(ASO_INTERLEAVE1)
|
|
|
2065 |
{
|
|
|
2066 |
register mad_fixed_t tmp1, tmp2;
|
|
|
2067 |
|
|
|
2068 |
tmp1 = window_l[0];
|
|
|
2069 |
tmp2 = window_l[1];
|
|
|
2070 |
|
|
|
2071 |
for (i = 0; i < 34; i += 2) {
|
|
|
2072 |
z[i + 0] = mad_f_mul(z[i + 0], tmp1);
|
|
|
2073 |
tmp1 = window_l[i + 2];
|
|
|
2074 |
z[i + 1] = mad_f_mul(z[i + 1], tmp2);
|
|
|
2075 |
tmp2 = window_l[i + 3];
|
|
|
2076 |
}
|
|
|
2077 |
|
|
|
2078 |
z[34] = mad_f_mul(z[34], tmp1);
|
|
|
2079 |
z[35] = mad_f_mul(z[35], tmp2);
|
|
|
2080 |
}
|
|
|
2081 |
# elif defined(ASO_INTERLEAVE2)
|
|
|
2082 |
{
|
|
|
2083 |
register mad_fixed_t tmp1, tmp2;
|
|
|
2084 |
|
|
|
2085 |
tmp1 = z[0];
|
|
|
2086 |
tmp2 = window_l[0];
|
|
|
2087 |
|
|
|
2088 |
for (i = 0; i < 35; ++i) {
|
|
|
2089 |
z[i] = mad_f_mul(tmp1, tmp2);
|
|
|
2090 |
tmp1 = z[i + 1];
|
|
|
2091 |
tmp2 = window_l[i + 1];
|
|
|
2092 |
}
|
|
|
2093 |
|
|
|
2094 |
z[35] = mad_f_mul(tmp1, tmp2);
|
|
|
2095 |
}
|
|
|
2096 |
# elif 1
|
|
|
2097 |
for (i = 0; i < 36; i += 4) {
|
|
|
2098 |
z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
|
|
|
2099 |
z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
|
|
|
2100 |
z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
|
|
|
2101 |
z[i + 3] = mad_f_mul(z[i + 3], window_l[i + 3]);
|
|
|
2102 |
}
|
|
|
2103 |
# else
|
|
|
2104 |
for (i = 0; i < 36; ++i) z[i] = mad_f_mul(z[i], window_l[i]);
|
|
|
2105 |
# endif
|
|
|
2106 |
break;
|
|
|
2107 |
|
|
|
2108 |
case 1: /* start block */
|
|
|
2109 |
for (i = 0; i < 18; i += 3) {
|
|
|
2110 |
z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
|
|
|
2111 |
z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
|
|
|
2112 |
z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
|
|
|
2113 |
}
|
|
|
2114 |
/* (i = 18; i < 24; ++i) z[i] unchanged */
|
|
|
2115 |
for (i = 24; i < 30; ++i) z[i] = mad_f_mul(z[i], window_s[i - 18]);
|
|
|
2116 |
for (i = 30; i < 36; ++i) z[i] = 0;
|
|
|
2117 |
break;
|
|
|
2118 |
|
|
|
2119 |
case 3: /* stop block */
|
|
|
2120 |
for (i = 0; i < 6; ++i) z[i] = 0;
|
|
|
2121 |
for (i = 6; i < 12; ++i) z[i] = mad_f_mul(z[i], window_s[i - 6]);
|
|
|
2122 |
/* (i = 12; i < 18; ++i) z[i] unchanged */
|
|
|
2123 |
for (i = 18; i < 36; i += 3) {
|
|
|
2124 |
z[i + 0] = mad_f_mul(z[i + 0], window_l[i + 0]);
|
|
|
2125 |
z[i + 1] = mad_f_mul(z[i + 1], window_l[i + 1]);
|
|
|
2126 |
z[i + 2] = mad_f_mul(z[i + 2], window_l[i + 2]);
|
|
|
2127 |
}
|
|
|
2128 |
break;
|
|
|
2129 |
}
|
|
|
2130 |
}
|
|
|
2131 |
# endif /* ASO_IMDCT */
|
|
|
2132 |
|
|
|
2133 |
/*
|
|
|
2134 |
* NAME: III_imdct_s()
|
|
|
2135 |
* DESCRIPTION: perform IMDCT and windowing for short blocks
|
|
|
2136 |
*/
|
|
|
2137 |
static
|
|
|
2138 |
void III_imdct_s(mad_fixed_t const X[18], mad_fixed_t z[36])
|
|
|
2139 |
{
|
|
|
2140 |
mad_fixed_t y[36], *yptr;
|
|
|
2141 |
mad_fixed_t const *wptr;
|
|
|
2142 |
int w, i;
|
|
|
2143 |
register mad_fixed64hi_t hi;
|
|
|
2144 |
register mad_fixed64lo_t lo;
|
|
|
2145 |
|
|
|
2146 |
/* IMDCT */
|
|
|
2147 |
|
|
|
2148 |
yptr = &y[0];
|
|
|
2149 |
|
|
|
2150 |
for (w = 0; w < 3; ++w) {
|
|
|
2151 |
register mad_fixed_t const (*s)[6];
|
|
|
2152 |
|
|
|
2153 |
s = imdct_s;
|
|
|
2154 |
|
|
|
2155 |
for (i = 0; i < 3; ++i) {
|
|
|
2156 |
MAD_F_ML0(hi, lo, X[0], (*s)[0]);
|
|
|
2157 |
MAD_F_MLA(hi, lo, X[1], (*s)[1]);
|
|
|
2158 |
MAD_F_MLA(hi, lo, X[2], (*s)[2]);
|
|
|
2159 |
MAD_F_MLA(hi, lo, X[3], (*s)[3]);
|
|
|
2160 |
MAD_F_MLA(hi, lo, X[4], (*s)[4]);
|
|
|
2161 |
MAD_F_MLA(hi, lo, X[5], (*s)[5]);
|
|
|
2162 |
|
|
|
2163 |
yptr[i + 0] = MAD_F_MLZ(hi, lo);
|
|
|
2164 |
yptr[5 - i] = -yptr[i + 0];
|
|
|
2165 |
|
|
|
2166 |
++s;
|
|
|
2167 |
|
|
|
2168 |
MAD_F_ML0(hi, lo, X[0], (*s)[0]);
|
|
|
2169 |
MAD_F_MLA(hi, lo, X[1], (*s)[1]);
|
|
|
2170 |
MAD_F_MLA(hi, lo, X[2], (*s)[2]);
|
|
|
2171 |
MAD_F_MLA(hi, lo, X[3], (*s)[3]);
|
|
|
2172 |
MAD_F_MLA(hi, lo, X[4], (*s)[4]);
|
|
|
2173 |
MAD_F_MLA(hi, lo, X[5], (*s)[5]);
|
|
|
2174 |
|
|
|
2175 |
yptr[ i + 6] = MAD_F_MLZ(hi, lo);
|
|
|
2176 |
yptr[11 - i] = yptr[i + 6];
|
|
|
2177 |
|
|
|
2178 |
++s;
|
|
|
2179 |
}
|
|
|
2180 |
|
|
|
2181 |
yptr += 12;
|
|
|
2182 |
X += 6;
|
|
|
2183 |
}
|
|
|
2184 |
|
|
|
2185 |
/* windowing, overlapping and concatenation */
|
|
|
2186 |
|
|
|
2187 |
yptr = &y[0];
|
|
|
2188 |
wptr = &window_s[0];
|
|
|
2189 |
|
|
|
2190 |
for (i = 0; i < 6; ++i) {
|
|
|
2191 |
z[i + 0] = 0;
|
|
|
2192 |
z[i + 6] = mad_f_mul(yptr[ 0 + 0], wptr[0]);
|
|
|
2193 |
|
|
|
2194 |
MAD_F_ML0(hi, lo, yptr[ 0 + 6], wptr[6]);
|
|
|
2195 |
MAD_F_MLA(hi, lo, yptr[12 + 0], wptr[0]);
|
|
|
2196 |
|
|
|
2197 |
z[i + 12] = MAD_F_MLZ(hi, lo);
|
|
|
2198 |
|
|
|
2199 |
MAD_F_ML0(hi, lo, yptr[12 + 6], wptr[6]);
|
|
|
2200 |
MAD_F_MLA(hi, lo, yptr[24 + 0], wptr[0]);
|
|
|
2201 |
|
|
|
2202 |
z[i + 18] = MAD_F_MLZ(hi, lo);
|
|
|
2203 |
|
|
|
2204 |
z[i + 24] = mad_f_mul(yptr[24 + 6], wptr[6]);
|
|
|
2205 |
z[i + 30] = 0;
|
|
|
2206 |
|
|
|
2207 |
++yptr;
|
|
|
2208 |
++wptr;
|
|
|
2209 |
}
|
|
|
2210 |
}
|
|
|
2211 |
|
|
|
2212 |
/*
|
|
|
2213 |
* NAME: III_overlap()
|
|
|
2214 |
* DESCRIPTION: perform overlap-add of windowed IMDCT outputs
|
|
|
2215 |
*/
|
|
|
2216 |
static
|
|
|
2217 |
void III_overlap(mad_fixed_t const output[36], mad_fixed_t overlap[18],
|
|
|
2218 |
mad_fixed_t sample[18][32], unsigned int sb)
|
|
|
2219 |
{
|
|
|
2220 |
unsigned int i;
|
|
|
2221 |
|
|
|
2222 |
# if defined(ASO_INTERLEAVE2)
|
|
|
2223 |
{
|
|
|
2224 |
register mad_fixed_t tmp1, tmp2;
|
|
|
2225 |
|
|
|
2226 |
tmp1 = overlap[0];
|
|
|
2227 |
tmp2 = overlap[1];
|
|
|
2228 |
|
|
|
2229 |
for (i = 0; i < 16; i += 2) {
|
|
|
2230 |
sample[i + 0][sb] = output[i + 0 + 0] + tmp1;
|
|
|
2231 |
overlap[i + 0] = output[i + 0 + 18];
|
|
|
2232 |
tmp1 = overlap[i + 2];
|
|
|
2233 |
|
|
|
2234 |
sample[i + 1][sb] = output[i + 1 + 0] + tmp2;
|
|
|
2235 |
overlap[i + 1] = output[i + 1 + 18];
|
|
|
2236 |
tmp2 = overlap[i + 3];
|
|
|
2237 |
}
|
|
|
2238 |
|
|
|
2239 |
sample[16][sb] = output[16 + 0] + tmp1;
|
|
|
2240 |
overlap[16] = output[16 + 18];
|
|
|
2241 |
sample[17][sb] = output[17 + 0] + tmp2;
|
|
|
2242 |
overlap[17] = output[17 + 18];
|
|
|
2243 |
}
|
|
|
2244 |
# elif 0
|
|
|
2245 |
for (i = 0; i < 18; i += 2) {
|
|
|
2246 |
sample[i + 0][sb] = output[i + 0 + 0] + overlap[i + 0];
|
|
|
2247 |
overlap[i + 0] = output[i + 0 + 18];
|
|
|
2248 |
|
|
|
2249 |
sample[i + 1][sb] = output[i + 1 + 0] + overlap[i + 1];
|
|
|
2250 |
overlap[i + 1] = output[i + 1 + 18];
|
|
|
2251 |
}
|
|
|
2252 |
# else
|
|
|
2253 |
for (i = 0; i < 18; ++i) {
|
|
|
2254 |
sample[i][sb] = output[i + 0] + overlap[i];
|
|
|
2255 |
overlap[i] = output[i + 18];
|
|
|
2256 |
}
|
|
|
2257 |
# endif
|
|
|
2258 |
}
|
|
|
2259 |
|
|
|
2260 |
/*
|
|
|
2261 |
* NAME: III_overlap_z()
|
|
|
2262 |
* DESCRIPTION: perform "overlap-add" of zero IMDCT outputs
|
|
|
2263 |
*/
|
|
|
2264 |
static inline
|
|
|
2265 |
void III_overlap_z(mad_fixed_t overlap[18],
|
|
|
2266 |
mad_fixed_t sample[18][32], unsigned int sb)
|
|
|
2267 |
{
|
|
|
2268 |
unsigned int i;
|
|
|
2269 |
|
|
|
2270 |
# if defined(ASO_INTERLEAVE2)
|
|
|
2271 |
{
|
|
|
2272 |
register mad_fixed_t tmp1, tmp2;
|
|
|
2273 |
|
|
|
2274 |
tmp1 = overlap[0];
|
|
|
2275 |
tmp2 = overlap[1];
|
|
|
2276 |
|
|
|
2277 |
for (i = 0; i < 16; i += 2) {
|
|
|
2278 |
sample[i + 0][sb] = tmp1;
|
|
|
2279 |
overlap[i + 0] = 0;
|
|
|
2280 |
tmp1 = overlap[i + 2];
|
|
|
2281 |
|
|
|
2282 |
sample[i + 1][sb] = tmp2;
|
|
|
2283 |
overlap[i + 1] = 0;
|
|
|
2284 |
tmp2 = overlap[i + 3];
|
|
|
2285 |
}
|
|
|
2286 |
|
|
|
2287 |
sample[16][sb] = tmp1;
|
|
|
2288 |
overlap[16] = 0;
|
|
|
2289 |
sample[17][sb] = tmp2;
|
|
|
2290 |
overlap[17] = 0;
|
|
|
2291 |
}
|
|
|
2292 |
# else
|
|
|
2293 |
for (i = 0; i < 18; ++i) {
|
|
|
2294 |
sample[i][sb] = overlap[i];
|
|
|
2295 |
overlap[i] = 0;
|
|
|
2296 |
}
|
|
|
2297 |
# endif
|
|
|
2298 |
}
|
|
|
2299 |
|
|
|
2300 |
/*
|
|
|
2301 |
* NAME: III_freqinver()
|
|
|
2302 |
* DESCRIPTION: perform subband frequency inversion for odd sample lines
|
|
|
2303 |
*/
|
|
|
2304 |
static
|
|
|
2305 |
void III_freqinver(mad_fixed_t sample[18][32], unsigned int sb)
|
|
|
2306 |
{
|
|
|
2307 |
unsigned int i;
|
|
|
2308 |
|
|
|
2309 |
# if 1 || defined(ASO_INTERLEAVE1) || defined(ASO_INTERLEAVE2)
|
|
|
2310 |
{
|
|
|
2311 |
register mad_fixed_t tmp1, tmp2;
|
|
|
2312 |
|
|
|
2313 |
tmp1 = sample[1][sb];
|
|
|
2314 |
tmp2 = sample[3][sb];
|
|
|
2315 |
|
|
|
2316 |
for (i = 1; i < 13; i += 4) {
|
|
|
2317 |
sample[i + 0][sb] = -tmp1;
|
|
|
2318 |
tmp1 = sample[i + 4][sb];
|
|
|
2319 |
sample[i + 2][sb] = -tmp2;
|
|
|
2320 |
tmp2 = sample[i + 6][sb];
|
|
|
2321 |
}
|
|
|
2322 |
|
|
|
2323 |
sample[13][sb] = -tmp1;
|
|
|
2324 |
tmp1 = sample[17][sb];
|
|
|
2325 |
sample[15][sb] = -tmp2;
|
|
|
2326 |
sample[17][sb] = -tmp1;
|
|
|
2327 |
}
|
|
|
2328 |
# else
|
|
|
2329 |
for (i = 1; i < 18; i += 2)
|
|
|
2330 |
sample[i][sb] = -sample[i][sb];
|
|
|
2331 |
# endif
|
|
|
2332 |
}
|
|
|
2333 |
|
|
|
2334 |
/*
|
|
|
2335 |
* NAME: III_decode()
|
|
|
2336 |
* DESCRIPTION: decode frame main_data
|
|
|
2337 |
*/
|
|
|
2338 |
static
|
|
|
2339 |
enum mad_error III_decode(struct mad_bitptr *ptr, struct mad_frame *frame,
|
|
|
2340 |
struct sideinfo *si, unsigned int nch)
|
|
|
2341 |
{
|
|
|
2342 |
struct mad_header *header = &frame->header;
|
|
|
2343 |
unsigned int sfreqi, ngr, gr;
|
|
|
2344 |
|
|
|
2345 |
{
|
|
|
2346 |
unsigned int sfreq;
|
|
|
2347 |
|
|
|
2348 |
sfreq = header->samplerate;
|
|
|
2349 |
if (header->flags & MAD_FLAG_MPEG_2_5_EXT)
|
|
|
2350 |
sfreq *= 2;
|
|
|
2351 |
|
|
|
2352 |
/* 48000 => 0, 44100 => 1, 32000 => 2,
|
|
|
2353 |
24000 => 3, 22050 => 4, 16000 => 5 */
|
|
|
2354 |
sfreqi = ((sfreq >> 7) & 0x000f) +
|
|
|
2355 |
((sfreq >> 15) & 0x0001) - 8;
|
|
|
2356 |
|
|
|
2357 |
if (header->flags & MAD_FLAG_MPEG_2_5_EXT)
|
|
|
2358 |
sfreqi += 3;
|
|
|
2359 |
}
|
|
|
2360 |
|
|
|
2361 |
/* scalefactors, Huffman decoding, requantization */
|
|
|
2362 |
|
|
|
2363 |
ngr = (header->flags & MAD_FLAG_LSF_EXT) ? 1 : 2;
|
|
|
2364 |
|
|
|
2365 |
for (gr = 0; gr < ngr; ++gr) {
|
|
|
2366 |
struct granule *granule = &si->gr[gr];
|
|
|
2367 |
unsigned char const *sfbwidth[2];
|
|
|
2368 |
mad_fixed_t xr[2][576];
|
|
|
2369 |
unsigned int ch;
|
|
|
2370 |
enum mad_error error;
|
|
|
2371 |
|
|
|
2372 |
for (ch = 0; ch < nch; ++ch) {
|
|
|
2373 |
struct channel *channel = &granule->ch[ch];
|
|
|
2374 |
unsigned int part2_length;
|
|
|
2375 |
|
|
|
2376 |
sfbwidth[ch] = sfbwidth_table[sfreqi].l;
|
|
|
2377 |
if (channel->block_type == 2) {
|
|
|
2378 |
sfbwidth[ch] = (channel->flags & mixed_block_flag) ?
|
|
|
2379 |
sfbwidth_table[sfreqi].m : sfbwidth_table[sfreqi].s;
|
|
|
2380 |
}
|
|
|
2381 |
|
|
|
2382 |
if (header->flags & MAD_FLAG_LSF_EXT) {
|
|
|
2383 |
part2_length = III_scalefactors_lsf(ptr, channel,
|
|
|
2384 |
ch == 0 ? 0 : &si->gr[1].ch[1],
|
|
|
2385 |
header->mode_extension);
|
|
|
2386 |
}
|
|
|
2387 |
else {
|
|
|
2388 |
part2_length = III_scalefactors(ptr, channel, &si->gr[0].ch[ch],
|
|
|
2389 |
gr == 0 ? 0 : si->scfsi[ch]);
|
|
|
2390 |
}
|
|
|
2391 |
|
|
|
2392 |
error = III_huffdecode(ptr, xr[ch], channel, sfbwidth[ch], part2_length);
|
|
|
2393 |
if (error)
|
|
|
2394 |
return error;
|
|
|
2395 |
}
|
|
|
2396 |
|
|
|
2397 |
/* joint stereo processing */
|
|
|
2398 |
|
|
|
2399 |
if (header->mode == MAD_MODE_JOINT_STEREO && header->mode_extension) {
|
|
|
2400 |
error = III_stereo(xr, granule, header, sfbwidth[0]);
|
|
|
2401 |
if (error)
|
|
|
2402 |
return error;
|
|
|
2403 |
}
|
|
|
2404 |
|
|
|
2405 |
/* reordering, alias reduction, IMDCT, overlap-add, frequency inversion */
|
|
|
2406 |
|
|
|
2407 |
for (ch = 0; ch < nch; ++ch) {
|
|
|
2408 |
struct channel const *channel = &granule->ch[ch];
|
|
|
2409 |
mad_fixed_t (*sample)[32] = &frame->sbsample[ch][18 * gr];
|
|
|
2410 |
unsigned int sb, l, i, sblimit;
|
|
|
2411 |
mad_fixed_t output[36];
|
|
|
2412 |
|
|
|
2413 |
if (channel->block_type == 2) {
|
|
|
2414 |
III_reorder(xr[ch], channel, sfbwidth[ch]);
|
|
|
2415 |
|
|
|
2416 |
# if !defined(OPT_STRICT)
|
|
|
2417 |
/*
|
|
|
2418 |
* According to ISO/IEC 11172-3, "Alias reduction is not applied for
|
|
|
2419 |
* granules with block_type == 2 (short block)." However, other
|
|
|
2420 |
* sources suggest alias reduction should indeed be performed on the
|
|
|
2421 |
* lower two subbands of mixed blocks. Most other implementations do
|
|
|
2422 |
* this, so by default we will too.
|
|
|
2423 |
*/
|
|
|
2424 |
if (channel->flags & mixed_block_flag)
|
|
|
2425 |
III_aliasreduce(xr[ch], 36);
|
|
|
2426 |
# endif
|
|
|
2427 |
}
|
|
|
2428 |
else
|
|
|
2429 |
III_aliasreduce(xr[ch], 576);
|
|
|
2430 |
|
|
|
2431 |
l = 0;
|
|
|
2432 |
|
|
|
2433 |
/* subbands 0-1 */
|
|
|
2434 |
|
|
|
2435 |
if (channel->block_type != 2 || (channel->flags & mixed_block_flag)) {
|
|
|
2436 |
unsigned int block_type;
|
|
|
2437 |
|
|
|
2438 |
block_type = channel->block_type;
|
|
|
2439 |
if (channel->flags & mixed_block_flag)
|
|
|
2440 |
block_type = 0;
|
|
|
2441 |
|
|
|
2442 |
/* long blocks */
|
|
|
2443 |
for (sb = 0; sb < 2; ++sb, l += 18) {
|
|
|
2444 |
III_imdct_l(&xr[ch][l], output, block_type);
|
|
|
2445 |
III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
|
|
|
2446 |
}
|
|
|
2447 |
}
|
|
|
2448 |
else {
|
|
|
2449 |
/* short blocks */
|
|
|
2450 |
for (sb = 0; sb < 2; ++sb, l += 18) {
|
|
|
2451 |
III_imdct_s(&xr[ch][l], output);
|
|
|
2452 |
III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
|
|
|
2453 |
}
|
|
|
2454 |
}
|
|
|
2455 |
|
|
|
2456 |
III_freqinver(sample, 1);
|
|
|
2457 |
|
|
|
2458 |
/* (nonzero) subbands 2-31 */
|
|
|
2459 |
|
|
|
2460 |
i = 576;
|
|
|
2461 |
while (i > 36 && xr[ch][i - 1] == 0)
|
|
|
2462 |
--i;
|
|
|
2463 |
|
|
|
2464 |
sblimit = 32 - (576 - i) / 18;
|
|
|
2465 |
|
|
|
2466 |
if (channel->block_type != 2) {
|
|
|
2467 |
/* long blocks */
|
|
|
2468 |
for (sb = 2; sb < sblimit; ++sb, l += 18) {
|
|
|
2469 |
III_imdct_l(&xr[ch][l], output, channel->block_type);
|
|
|
2470 |
III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
|
|
|
2471 |
|
|
|
2472 |
if (sb & 1)
|
|
|
2473 |
III_freqinver(sample, sb);
|
|
|
2474 |
}
|
|
|
2475 |
}
|
|
|
2476 |
else {
|
|
|
2477 |
/* short blocks */
|
|
|
2478 |
for (sb = 2; sb < sblimit; ++sb, l += 18) {
|
|
|
2479 |
III_imdct_s(&xr[ch][l], output);
|
|
|
2480 |
III_overlap(output, (*frame->overlap)[ch][sb], sample, sb);
|
|
|
2481 |
|
|
|
2482 |
if (sb & 1)
|
|
|
2483 |
III_freqinver(sample, sb);
|
|
|
2484 |
}
|
|
|
2485 |
}
|
|
|
2486 |
|
|
|
2487 |
/* remaining (zero) subbands */
|
|
|
2488 |
|
|
|
2489 |
for (sb = sblimit; sb < 32; ++sb) {
|
|
|
2490 |
III_overlap_z((*frame->overlap)[ch][sb], sample, sb);
|
|
|
2491 |
|
|
|
2492 |
if (sb & 1)
|
|
|
2493 |
III_freqinver(sample, sb);
|
|
|
2494 |
}
|
|
|
2495 |
}
|
|
|
2496 |
}
|
|
|
2497 |
|
|
|
2498 |
return MAD_ERROR_NONE;
|
|
|
2499 |
}
|
|
|
2500 |
|
|
|
2501 |
/*
|
|
|
2502 |
* NAME: layer->III()
|
|
|
2503 |
* DESCRIPTION: decode a single Layer III frame
|
|
|
2504 |
*/
|
|
|
2505 |
int mad_layer_III(struct mad_stream *stream, struct mad_frame *frame)
|
|
|
2506 |
{
|
|
|
2507 |
struct mad_header *header = &frame->header;
|
|
|
2508 |
unsigned int nch, priv_bitlen, next_md_begin = 0;
|
|
|
2509 |
unsigned int si_len, data_bitlen, md_len;
|
|
|
2510 |
unsigned int frame_space, frame_used, frame_free;
|
|
|
2511 |
struct mad_bitptr ptr;
|
|
|
2512 |
struct sideinfo si;
|
|
|
2513 |
enum mad_error error;
|
|
|
2514 |
int result = 0;
|
|
|
2515 |
|
|
|
2516 |
/* allocate Layer III dynamic structures */
|
|
|
2517 |
|
|
|
2518 |
if (stream->main_data == 0) {
|
|
|
2519 |
stream->main_data = malloc(MAD_BUFFER_MDLEN);
|
|
|
2520 |
if (stream->main_data == 0) {
|
|
|
2521 |
stream->error = MAD_ERROR_NOMEM;
|
|
|
2522 |
return -1;
|
|
|
2523 |
}
|
|
|
2524 |
}
|
|
|
2525 |
|
|
|
2526 |
if (frame->overlap == 0) {
|
|
|
2527 |
frame->overlap = calloc(2 * 32 * 18, sizeof(mad_fixed_t));
|
|
|
2528 |
if (frame->overlap == 0) {
|
|
|
2529 |
stream->error = MAD_ERROR_NOMEM;
|
|
|
2530 |
return -1;
|
|
|
2531 |
}
|
|
|
2532 |
}
|
|
|
2533 |
|
|
|
2534 |
nch = MAD_NCHANNELS(header);
|
|
|
2535 |
si_len = (header->flags & MAD_FLAG_LSF_EXT) ?
|
|
|
2536 |
(nch == 1 ? 9 : 17) : (nch == 1 ? 17 : 32);
|
|
|
2537 |
|
|
|
2538 |
/* check frame sanity */
|
|
|
2539 |
|
|
|
2540 |
if (stream->next_frame - mad_bit_nextbyte(&stream->ptr) <
|
|
|
2541 |
(signed int) si_len) {
|
|
|
2542 |
stream->error = MAD_ERROR_BADFRAMELEN;
|
|
|
2543 |
stream->md_len = 0;
|
|
|
2544 |
return -1;
|
|
|
2545 |
}
|
|
|
2546 |
|
|
|
2547 |
/* check CRC word */
|
|
|
2548 |
|
|
|
2549 |
if (header->flags & MAD_FLAG_PROTECTION) {
|
|
|
2550 |
header->crc_check =
|
|
|
2551 |
mad_bit_crc(stream->ptr, si_len * CHAR_BIT, header->crc_check);
|
|
|
2552 |
|
|
|
2553 |
if (header->crc_check != header->crc_target &&
|
|
|
2554 |
!(frame->options & MAD_OPTION_IGNORECRC)) {
|
|
|
2555 |
stream->error = MAD_ERROR_BADCRC;
|
|
|
2556 |
result = -1;
|
|
|
2557 |
}
|
|
|
2558 |
}
|
|
|
2559 |
|
|
|
2560 |
/* decode frame side information */
|
|
|
2561 |
|
|
|
2562 |
error = III_sideinfo(&stream->ptr, nch, header->flags & MAD_FLAG_LSF_EXT,
|
|
|
2563 |
&si, &data_bitlen, &priv_bitlen);
|
|
|
2564 |
if (error && result == 0) {
|
|
|
2565 |
stream->error = error;
|
|
|
2566 |
result = -1;
|
|
|
2567 |
}
|
|
|
2568 |
|
|
|
2569 |
header->flags |= priv_bitlen;
|
|
|
2570 |
header->private_bits |= si.private_bits;
|
|
|
2571 |
|
|
|
2572 |
/* find main_data of next frame */
|
|
|
2573 |
|
|
|
2574 |
{
|
|
|
2575 |
struct mad_bitptr peek;
|
|
|
2576 |
unsigned long header;
|
|
|
2577 |
|
|
|
2578 |
mad_bit_init(&peek, stream->next_frame);
|
|
|
2579 |
|
|
|
2580 |
header = mad_bit_read(&peek, 32);
|
|
|
2581 |
if ((header & 0xffe60000L) /* syncword | layer */ == 0xffe20000L) {
|
|
|
2582 |
if (!(header & 0x00010000L)) /* protection_bit */
|
|
|
2583 |
mad_bit_skip(&peek, 16); /* crc_check */
|
|
|
2584 |
|
|
|
2585 |
next_md_begin =
|
|
|
2586 |
mad_bit_read(&peek, (header & 0x00080000L) /* ID */ ? 9 : 8);
|
|
|
2587 |
}
|
|
|
2588 |
|
|
|
2589 |
mad_bit_finish(&peek);
|
|
|
2590 |
}
|
|
|
2591 |
|
|
|
2592 |
/* find main_data of this frame */
|
|
|
2593 |
|
|
|
2594 |
frame_space = stream->next_frame - mad_bit_nextbyte(&stream->ptr);
|
|
|
2595 |
|
|
|
2596 |
if (next_md_begin > si.main_data_begin + frame_space)
|
|
|
2597 |
next_md_begin = 0;
|
|
|
2598 |
|
|
|
2599 |
md_len = si.main_data_begin + frame_space - next_md_begin;
|
|
|
2600 |
|
|
|
2601 |
frame_used = 0;
|
|
|
2602 |
|
|
|
2603 |
if (si.main_data_begin == 0) {
|
|
|
2604 |
ptr = stream->ptr;
|
|
|
2605 |
stream->md_len = 0;
|
|
|
2606 |
|
|
|
2607 |
frame_used = md_len;
|
|
|
2608 |
}
|
|
|
2609 |
else {
|
|
|
2610 |
if (si.main_data_begin > stream->md_len) {
|
|
|
2611 |
if (result == 0) {
|
|
|
2612 |
stream->error = MAD_ERROR_BADDATAPTR;
|
|
|
2613 |
result = -1;
|
|
|
2614 |
}
|
|
|
2615 |
}
|
|
|
2616 |
else {
|
|
|
2617 |
mad_bit_init(&ptr,
|
|
|
2618 |
*stream->main_data + stream->md_len - si.main_data_begin);
|
|
|
2619 |
|
|
|
2620 |
if (md_len > si.main_data_begin) {
|
|
|
2621 |
assert(stream->md_len + md_len -
|
|
|
2622 |
si.main_data_begin <= MAD_BUFFER_MDLEN);
|
|
|
2623 |
|
|
|
2624 |
memcpy(*stream->main_data + stream->md_len,
|
|
|
2625 |
mad_bit_nextbyte(&stream->ptr),
|
|
|
2626 |
frame_used = md_len - si.main_data_begin);
|
|
|
2627 |
stream->md_len += frame_used;
|
|
|
2628 |
}
|
|
|
2629 |
}
|
|
|
2630 |
}
|
|
|
2631 |
|
|
|
2632 |
frame_free = frame_space - frame_used;
|
|
|
2633 |
|
|
|
2634 |
/* decode main_data */
|
|
|
2635 |
|
|
|
2636 |
if (result == 0) {
|
|
|
2637 |
error = III_decode(&ptr, frame, &si, nch);
|
|
|
2638 |
if (error) {
|
|
|
2639 |
stream->error = error;
|
|
|
2640 |
result = -1;
|
|
|
2641 |
}
|
|
|
2642 |
|
|
|
2643 |
/* designate ancillary bits */
|
|
|
2644 |
|
|
|
2645 |
stream->anc_ptr = ptr;
|
|
|
2646 |
stream->anc_bitlen = md_len * CHAR_BIT - data_bitlen;
|
|
|
2647 |
}
|
|
|
2648 |
|
|
|
2649 |
# if 0 && defined(DEBUG)
|
|
|
2650 |
fprintf(stderr,
|
|
|
2651 |
"main_data_begin:%u, md_len:%u, frame_free:%u, "
|
|
|
2652 |
"data_bitlen:%u, anc_bitlen: %u\n",
|
|
|
2653 |
si.main_data_begin, md_len, frame_free,
|
|
|
2654 |
data_bitlen, stream->anc_bitlen);
|
|
|
2655 |
# endif
|
|
|
2656 |
|
|
|
2657 |
/* preload main_data buffer with up to 511 bytes for next frame(s) */
|
|
|
2658 |
|
|
|
2659 |
if (frame_free >= next_md_begin) {
|
|
|
2660 |
memcpy(*stream->main_data,
|
|
|
2661 |
stream->next_frame - next_md_begin, next_md_begin);
|
|
|
2662 |
stream->md_len = next_md_begin;
|
|
|
2663 |
}
|
|
|
2664 |
else {
|
|
|
2665 |
if (md_len < si.main_data_begin) {
|
|
|
2666 |
unsigned int extra;
|
|
|
2667 |
|
|
|
2668 |
extra = si.main_data_begin - md_len;
|
|
|
2669 |
if (extra + frame_free > next_md_begin)
|
|
|
2670 |
extra = next_md_begin - frame_free;
|
|
|
2671 |
|
|
|
2672 |
if (extra < stream->md_len) {
|
|
|
2673 |
memmove(*stream->main_data,
|
|
|
2674 |
*stream->main_data + stream->md_len - extra, extra);
|
|
|
2675 |
stream->md_len = extra;
|
|
|
2676 |
}
|
|
|
2677 |
}
|
|
|
2678 |
else
|
|
|
2679 |
stream->md_len = 0;
|
|
|
2680 |
|
|
|
2681 |
memcpy(*stream->main_data + stream->md_len,
|
|
|
2682 |
stream->next_frame - frame_free, frame_free);
|
|
|
2683 |
stream->md_len += frame_free;
|
|
|
2684 |
}
|
|
|
2685 |
|
|
|
2686 |
return result;
|
|
|
2687 |
}
|