Mercurial > mplayer.hg
annotate libfaad2/specrec.c @ 13526:6c2a46f17184
synced with 1.760
author | paszczi |
---|---|
date | Sat, 02 Oct 2004 09:28:33 +0000 |
parents | 6d50ef45a058 |
children | 2ae5ab4331ca |
rev | line source |
---|---|
10725 | 1 /* |
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | |
12527 | 3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com |
10725 | 4 ** |
5 ** This program is free software; you can redistribute it and/or modify | |
6 ** it under the terms of the GNU General Public License as published by | |
7 ** the Free Software Foundation; either version 2 of the License, or | |
8 ** (at your option) any later version. | |
9 ** | |
10 ** This program is distributed in the hope that it will be useful, | |
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 ** GNU General Public License for more details. | |
14 ** | |
15 ** You should have received a copy of the GNU General Public License | |
16 ** along with this program; if not, write to the Free Software | |
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 ** | |
19 ** Any non-GPL usage of this software or parts of this software is strictly | |
20 ** forbidden. | |
21 ** | |
22 ** Commercial non-GPL licensing of this software is possible. | |
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. | |
24 ** | |
12625
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
25 ** Initially modified for use with MPlayer by Arpad Gereöffy on 2003/08/30 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
26 ** $Id: specrec.c,v 1.4 2004/06/23 13:50:52 diego Exp $ |
12625
d81145997036
More information about modifications to comply more closely with GPL 2a.
diego
parents:
12527
diff
changeset
|
27 ** detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ |
10725 | 28 **/ |
29 | |
30 /* | |
31 Spectral reconstruction: | |
32 - grouping/sectioning | |
33 - inverse quantization | |
34 - applying scalefactors | |
35 */ | |
36 | |
37 #include "common.h" | |
38 #include "structs.h" | |
39 | |
40 #include <string.h> | |
12527 | 41 #include <stdlib.h> |
10725 | 42 #include "specrec.h" |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
43 #include "filtbank.h" |
10725 | 44 #include "syntax.h" |
45 #include "iq_table.h" | |
12527 | 46 #include "ms.h" |
47 #include "is.h" | |
48 #include "pns.h" | |
49 #include "tns.h" | |
50 #include "drc.h" | |
51 #include "lt_predict.h" | |
52 #include "ic_predict.h" | |
53 #ifdef SSR_DEC | |
54 #include "ssr.h" | |
55 #include "ssr_fb.h" | |
56 #endif | |
57 | |
58 | |
59 /* static function declarations */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
60 static uint8_t quant_to_spec(NeAACDecHandle hDecoder, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
61 ic_stream *ics, int16_t *quant_data, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
62 real_t *spec_data, uint16_t frame_len); |
12527 | 63 |
10725 | 64 |
65 #ifdef LD_DEC | |
12527 | 66 ALIGN static const uint8_t num_swb_512_window[] = |
10725 | 67 { |
68 0, 0, 0, 36, 36, 37, 31, 31, 0, 0, 0, 0 | |
69 }; | |
12527 | 70 ALIGN static const uint8_t num_swb_480_window[] = |
10725 | 71 { |
72 0, 0, 0, 35, 35, 37, 30, 30, 0, 0, 0, 0 | |
73 }; | |
74 #endif | |
75 | |
12527 | 76 ALIGN static const uint8_t num_swb_960_window[] = |
10725 | 77 { |
78 40, 40, 45, 49, 49, 49, 46, 46, 42, 42, 42, 40 | |
79 }; | |
80 | |
12527 | 81 ALIGN static const uint8_t num_swb_1024_window[] = |
10725 | 82 { |
83 41, 41, 47, 49, 49, 51, 47, 47, 43, 43, 43, 40 | |
84 }; | |
85 | |
12527 | 86 ALIGN static const uint8_t num_swb_128_window[] = |
10725 | 87 { |
88 12, 12, 12, 14, 14, 14, 15, 15, 15, 15, 15, 15 | |
89 }; | |
90 | |
12527 | 91 ALIGN static const uint16_t swb_offset_1024_96[] = |
10725 | 92 { |
93 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, | |
94 64, 72, 80, 88, 96, 108, 120, 132, 144, 156, 172, 188, 212, 240, | |
95 276, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024 | |
96 }; | |
97 | |
12527 | 98 ALIGN static const uint16_t swb_offset_128_96[] = |
10725 | 99 { |
100 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128 | |
101 }; | |
102 | |
12527 | 103 ALIGN static const uint16_t swb_offset_1024_64[] = |
10725 | 104 { |
105 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, | |
106 64, 72, 80, 88, 100, 112, 124, 140, 156, 172, 192, 216, 240, 268, | |
107 304, 344, 384, 424, 464, 504, 544, 584, 624, 664, 704, 744, 784, 824, | |
108 864, 904, 944, 984, 1024 | |
109 }; | |
110 | |
12527 | 111 ALIGN static const uint16_t swb_offset_128_64[] = |
10725 | 112 { |
113 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128 | |
114 }; | |
115 | |
12527 | 116 ALIGN static const uint16_t swb_offset_1024_48[] = |
10725 | 117 { |
118 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72, | |
119 80, 88, 96, 108, 120, 132, 144, 160, 176, 196, 216, 240, 264, 292, | |
120 320, 352, 384, 416, 448, 480, 512, 544, 576, 608, 640, 672, 704, 736, | |
121 768, 800, 832, 864, 896, 928, 1024 | |
122 }; | |
123 | |
124 #ifdef LD_DEC | |
12527 | 125 ALIGN static const uint16_t swb_offset_512_48[] = |
10725 | 126 { |
127 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 68, 76, 84, | |
128 92, 100, 112, 124, 136, 148, 164, 184, 208, 236, 268, 300, 332, 364, 396, | |
129 428, 460, 512 | |
130 }; | |
131 | |
12527 | 132 ALIGN static const uint16_t swb_offset_480_48[] = |
10725 | 133 { |
134 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 64, 72 ,80 ,88, | |
135 96, 108, 120, 132, 144, 156, 172, 188, 212, 240, 272, 304, 336, 368, 400, | |
136 432, 480 | |
137 }; | |
138 #endif | |
139 | |
12527 | 140 ALIGN static const uint16_t swb_offset_128_48[] = |
10725 | 141 { |
142 0, 4, 8, 12, 16, 20, 28, 36, 44, 56, 68, 80, 96, 112, 128 | |
143 }; | |
144 | |
12527 | 145 ALIGN static const uint16_t swb_offset_1024_32[] = |
10725 | 146 { |
147 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72, | |
148 80, 88, 96, 108, 120, 132, 144, 160, 176, 196, 216, 240, 264, 292, | |
149 320, 352, 384, 416, 448, 480, 512, 544, 576, 608, 640, 672, 704, 736, | |
150 768, 800, 832, 864, 896, 928, 960, 992, 1024 | |
151 }; | |
152 | |
153 #ifdef LD_DEC | |
12527 | 154 ALIGN static const uint16_t swb_offset_512_32[] = |
10725 | 155 { |
156 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 64, 72, 80, | |
157 88, 96, 108, 120, 132, 144, 160, 176, 192, 212, 236, 260, 288, 320, 352, | |
158 384, 416, 448, 480, 512 | |
159 }; | |
160 | |
12527 | 161 ALIGN static const uint16_t swb_offset_480_32[] = |
10725 | 162 { |
163 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 72, 80, | |
164 88, 96, 104, 112, 124, 136, 148, 164, 180, 200, 224, 256, 288, 320, 352, | |
165 384, 416, 448, 480 | |
166 }; | |
167 #endif | |
168 | |
12527 | 169 ALIGN static const uint16_t swb_offset_1024_24[] = |
10725 | 170 { |
171 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 52, 60, 68, | |
172 76, 84, 92, 100, 108, 116, 124, 136, 148, 160, 172, 188, 204, 220, | |
173 240, 260, 284, 308, 336, 364, 396, 432, 468, 508, 552, 600, 652, 704, | |
174 768, 832, 896, 960, 1024 | |
175 }; | |
176 | |
177 #ifdef LD_DEC | |
12527 | 178 ALIGN static const uint16_t swb_offset_512_24[] = |
10725 | 179 { |
180 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 52, 60, 68, | |
181 80, 92, 104, 120, 140, 164, 192, 224, 256, 288, 320, 352, 384, 416, | |
182 448, 480, 512 | |
183 }; | |
184 | |
12527 | 185 ALIGN static const uint16_t swb_offset_480_24[] = |
10725 | 186 { |
187 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 52, 60, 68, 80, 92, 104, 120, | |
188 140, 164, 192, 224, 256, 288, 320, 352, 384, 416, 448, 480 | |
189 }; | |
190 #endif | |
191 | |
12527 | 192 ALIGN static const uint16_t swb_offset_128_24[] = |
10725 | 193 { |
194 0, 4, 8, 12, 16, 20, 24, 28, 36, 44, 52, 64, 76, 92, 108, 128 | |
195 }; | |
196 | |
12527 | 197 ALIGN static const uint16_t swb_offset_1024_16[] = |
10725 | 198 { |
199 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 100, 112, 124, | |
200 136, 148, 160, 172, 184, 196, 212, 228, 244, 260, 280, 300, 320, 344, | |
201 368, 396, 424, 456, 492, 532, 572, 616, 664, 716, 772, 832, 896, 960, 1024 | |
202 }; | |
203 | |
12527 | 204 ALIGN static const uint16_t swb_offset_128_16[] = |
10725 | 205 { |
206 0, 4, 8, 12, 16, 20, 24, 28, 32, 40, 48, 60, 72, 88, 108, 128 | |
207 }; | |
208 | |
12527 | 209 ALIGN static const uint16_t swb_offset_1024_8[] = |
10725 | 210 { |
211 0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 172, | |
212 188, 204, 220, 236, 252, 268, 288, 308, 328, 348, 372, 396, 420, 448, | |
213 476, 508, 544, 580, 620, 664, 712, 764, 820, 880, 944, 1024 | |
214 }; | |
215 | |
12527 | 216 ALIGN static const uint16_t swb_offset_128_8[] = |
10725 | 217 { |
218 0, 4, 8, 12, 16, 20, 24, 28, 36, 44, 52, 60, 72, 88, 108, 128 | |
219 }; | |
220 | |
12527 | 221 ALIGN static const uint16_t *swb_offset_1024_window[] = |
10725 | 222 { |
223 swb_offset_1024_96, /* 96000 */ | |
224 swb_offset_1024_96, /* 88200 */ | |
225 swb_offset_1024_64, /* 64000 */ | |
226 swb_offset_1024_48, /* 48000 */ | |
227 swb_offset_1024_48, /* 44100 */ | |
228 swb_offset_1024_32, /* 32000 */ | |
229 swb_offset_1024_24, /* 24000 */ | |
230 swb_offset_1024_24, /* 22050 */ | |
231 swb_offset_1024_16, /* 16000 */ | |
232 swb_offset_1024_16, /* 12000 */ | |
233 swb_offset_1024_16, /* 11025 */ | |
234 swb_offset_1024_8 /* 8000 */ | |
235 }; | |
236 | |
237 #ifdef LD_DEC | |
12527 | 238 ALIGN static const uint16_t *swb_offset_512_window[] = |
10725 | 239 { |
240 0, /* 96000 */ | |
241 0, /* 88200 */ | |
242 0, /* 64000 */ | |
243 swb_offset_512_48, /* 48000 */ | |
244 swb_offset_512_48, /* 44100 */ | |
245 swb_offset_512_32, /* 32000 */ | |
246 swb_offset_512_24, /* 24000 */ | |
247 swb_offset_512_24, /* 22050 */ | |
248 0, /* 16000 */ | |
249 0, /* 12000 */ | |
250 0, /* 11025 */ | |
251 0 /* 8000 */ | |
252 }; | |
253 | |
12527 | 254 ALIGN static const uint16_t *swb_offset_480_window[] = |
10725 | 255 { |
256 0, /* 96000 */ | |
257 0, /* 88200 */ | |
258 0, /* 64000 */ | |
259 swb_offset_480_48, /* 48000 */ | |
260 swb_offset_480_48, /* 44100 */ | |
261 swb_offset_480_32, /* 32000 */ | |
262 swb_offset_480_24, /* 24000 */ | |
263 swb_offset_480_24, /* 22050 */ | |
264 0, /* 16000 */ | |
265 0, /* 12000 */ | |
266 0, /* 11025 */ | |
267 0 /* 8000 */ | |
268 }; | |
269 #endif | |
270 | |
12527 | 271 ALIGN static const uint16_t *swb_offset_128_window[] = |
10725 | 272 { |
273 swb_offset_128_96, /* 96000 */ | |
274 swb_offset_128_96, /* 88200 */ | |
275 swb_offset_128_64, /* 64000 */ | |
276 swb_offset_128_48, /* 48000 */ | |
277 swb_offset_128_48, /* 44100 */ | |
278 swb_offset_128_48, /* 32000 */ | |
279 swb_offset_128_24, /* 24000 */ | |
280 swb_offset_128_24, /* 22050 */ | |
281 swb_offset_128_16, /* 16000 */ | |
282 swb_offset_128_16, /* 12000 */ | |
283 swb_offset_128_16, /* 11025 */ | |
284 swb_offset_128_8 /* 8000 */ | |
285 }; | |
286 | |
287 #define bit_set(A, B) ((A) & (1<<(B))) | |
288 | |
289 /* 4.5.2.3.4 */ | |
290 /* | |
291 - determine the number of windows in a window_sequence named num_windows | |
292 - determine the number of window_groups named num_window_groups | |
293 - determine the number of windows in each group named window_group_length[g] | |
294 - determine the total number of scalefactor window bands named num_swb for | |
295 the actual window type | |
296 - determine swb_offset[swb], the offset of the first coefficient in | |
297 scalefactor window band named swb of the window actually used | |
298 - determine sect_sfb_offset[g][section],the offset of the first coefficient | |
299 in section named section. This offset depends on window_sequence and | |
300 scale_factor_grouping and is needed to decode the spectral_data(). | |
301 */ | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
302 uint8_t window_grouping_info(NeAACDecHandle hDecoder, ic_stream *ics) |
10725 | 303 { |
304 uint8_t i, g; | |
305 | |
306 uint8_t sf_index = hDecoder->sf_index; | |
307 | |
308 switch (ics->window_sequence) { | |
309 case ONLY_LONG_SEQUENCE: | |
310 case LONG_START_SEQUENCE: | |
311 case LONG_STOP_SEQUENCE: | |
312 ics->num_windows = 1; | |
313 ics->num_window_groups = 1; | |
314 ics->window_group_length[ics->num_window_groups-1] = 1; | |
315 #ifdef LD_DEC | |
316 if (hDecoder->object_type == LD) | |
317 { | |
318 if (hDecoder->frameLength == 512) | |
319 ics->num_swb = num_swb_512_window[sf_index]; | |
320 else /* if (hDecoder->frameLength == 480) */ | |
321 ics->num_swb = num_swb_480_window[sf_index]; | |
322 } else { | |
323 #endif | |
324 if (hDecoder->frameLength == 1024) | |
325 ics->num_swb = num_swb_1024_window[sf_index]; | |
326 else /* if (hDecoder->frameLength == 960) */ | |
327 ics->num_swb = num_swb_960_window[sf_index]; | |
328 #ifdef LD_DEC | |
329 } | |
330 #endif | |
331 | |
332 /* preparation of sect_sfb_offset for long blocks */ | |
333 /* also copy the last value! */ | |
334 #ifdef LD_DEC | |
335 if (hDecoder->object_type == LD) | |
336 { | |
337 if (hDecoder->frameLength == 512) | |
338 { | |
339 for (i = 0; i < ics->num_swb; i++) | |
340 { | |
341 ics->sect_sfb_offset[0][i] = swb_offset_512_window[sf_index][i]; | |
342 ics->swb_offset[i] = swb_offset_512_window[sf_index][i]; | |
343 } | |
344 } else /* if (hDecoder->frameLength == 480) */ { | |
345 for (i = 0; i < ics->num_swb; i++) | |
346 { | |
347 ics->sect_sfb_offset[0][i] = swb_offset_480_window[sf_index][i]; | |
348 ics->swb_offset[i] = swb_offset_480_window[sf_index][i]; | |
349 } | |
350 } | |
351 ics->sect_sfb_offset[0][ics->num_swb] = hDecoder->frameLength; | |
352 ics->swb_offset[ics->num_swb] = hDecoder->frameLength; | |
353 } else { | |
354 #endif | |
355 for (i = 0; i < ics->num_swb; i++) | |
356 { | |
357 ics->sect_sfb_offset[0][i] = swb_offset_1024_window[sf_index][i]; | |
358 ics->swb_offset[i] = swb_offset_1024_window[sf_index][i]; | |
359 } | |
360 ics->sect_sfb_offset[0][ics->num_swb] = hDecoder->frameLength; | |
361 ics->swb_offset[ics->num_swb] = hDecoder->frameLength; | |
362 #ifdef LD_DEC | |
363 } | |
364 #endif | |
365 return 0; | |
366 case EIGHT_SHORT_SEQUENCE: | |
367 ics->num_windows = 8; | |
368 ics->num_window_groups = 1; | |
369 ics->window_group_length[ics->num_window_groups-1] = 1; | |
370 ics->num_swb = num_swb_128_window[sf_index]; | |
371 | |
372 for (i = 0; i < ics->num_swb; i++) | |
373 ics->swb_offset[i] = swb_offset_128_window[sf_index][i]; | |
374 ics->swb_offset[ics->num_swb] = hDecoder->frameLength/8; | |
375 | |
376 for (i = 0; i < ics->num_windows-1; i++) { | |
377 if (bit_set(ics->scale_factor_grouping, 6-i) == 0) | |
378 { | |
379 ics->num_window_groups += 1; | |
380 ics->window_group_length[ics->num_window_groups-1] = 1; | |
381 } else { | |
382 ics->window_group_length[ics->num_window_groups-1] += 1; | |
383 } | |
384 } | |
385 | |
386 /* preparation of sect_sfb_offset for short blocks */ | |
387 for (g = 0; g < ics->num_window_groups; g++) | |
388 { | |
389 uint16_t width; | |
390 uint8_t sect_sfb = 0; | |
391 uint16_t offset = 0; | |
392 | |
393 for (i = 0; i < ics->num_swb; i++) | |
394 { | |
395 if (i+1 == ics->num_swb) | |
396 { | |
397 width = (hDecoder->frameLength/8) - swb_offset_128_window[sf_index][i]; | |
398 } else { | |
399 width = swb_offset_128_window[sf_index][i+1] - | |
400 swb_offset_128_window[sf_index][i]; | |
401 } | |
402 width *= ics->window_group_length[g]; | |
403 ics->sect_sfb_offset[g][sect_sfb++] = offset; | |
404 offset += width; | |
405 } | |
406 ics->sect_sfb_offset[g][sect_sfb] = offset; | |
407 } | |
408 return 0; | |
409 default: | |
410 return 1; | |
411 } | |
412 } | |
413 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
414 /* iquant() * |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
415 /* output = sign(input)*abs(input)^(4/3) */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
416 /**/ |
12527 | 417 static INLINE real_t iquant(int16_t q, const real_t *tab, uint8_t *error) |
10725 | 418 { |
10989 | 419 #ifdef FIXED_POINT |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
420 /* For FIXED_POINT the iq_table is prescaled by 3 bits (iq_table[]/8) */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
421 /* BIG_IQ_TABLE allows you to use the full 8192 value table, if this is not |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
422 * defined a 1026 value table and interpolation will be used |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
423 */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
424 #ifndef BIG_IQ_TABLE |
12527 | 425 static const real_t errcorr[] = { |
426 REAL_CONST(0), REAL_CONST(1.0/8.0), REAL_CONST(2.0/8.0), REAL_CONST(3.0/8.0), | |
427 REAL_CONST(4.0/8.0), REAL_CONST(5.0/8.0), REAL_CONST(6.0/8.0), REAL_CONST(7.0/8.0), | |
428 REAL_CONST(0) | |
429 }; | |
430 real_t x1, x2; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
431 #endif |
10725 | 432 int16_t sgn = 1; |
433 | |
10989 | 434 if (q < 0) |
435 { | |
436 q = -q; | |
437 sgn = -1; | |
438 } | |
439 | |
440 if (q < IQ_TABLE_SIZE) | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
441 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
442 //#define IQUANT_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
443 #ifdef IQUANT_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
444 //printf("0x%.8X\n", sgn * tab[q]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
445 printf("%d\n", sgn * tab[q]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
446 #endif |
10989 | 447 return sgn * tab[q]; |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
448 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
449 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
450 #ifndef BIG_IQ_TABLE |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
451 if (q >= 8192) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
452 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
453 *error = 17; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
454 return 0; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
455 } |
10989 | 456 |
12527 | 457 /* linear interpolation */ |
458 x1 = tab[q>>3]; | |
459 x2 = tab[(q>>3) + 1]; | |
460 return sgn * 16 * (MUL_R(errcorr[q&7],(x2-x1)) + x1); | |
461 #else | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
462 *error = 17; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
463 return 0; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
464 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
465 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
466 #else |
12527 | 467 if (q < 0) |
468 { | |
469 /* tab contains a value for all possible q [0,8192] */ | |
470 if (-q < IQ_TABLE_SIZE) | |
471 return -tab[-q]; | |
472 | |
473 *error = 17; | |
474 return 0; | |
475 } else { | |
476 /* tab contains a value for all possible q [0,8192] */ | |
477 if (q < IQ_TABLE_SIZE) | |
478 return tab[q]; | |
479 | |
480 *error = 17; | |
481 return 0; | |
482 } | |
10989 | 483 #endif |
10725 | 484 } |
485 | |
486 #ifndef FIXED_POINT | |
12527 | 487 ALIGN static const real_t pow2sf_tab[] = { |
488 2.9802322387695313E-008, 5.9604644775390625E-008, 1.1920928955078125E-007, | |
489 2.384185791015625E-007, 4.76837158203125E-007, 9.5367431640625E-007, | |
490 1.9073486328125E-006, 3.814697265625E-006, 7.62939453125E-006, | |
491 1.52587890625E-005, 3.0517578125E-005, 6.103515625E-005, | |
492 0.0001220703125, 0.000244140625, 0.00048828125, | |
493 0.0009765625, 0.001953125, 0.00390625, | |
494 0.0078125, 0.015625, 0.03125, | |
495 0.0625, 0.125, 0.25, | |
496 0.5, 1.0, 2.0, | |
497 4.0, 8.0, 16.0, 32.0, | |
498 64.0, 128.0, 256.0, | |
499 512.0, 1024.0, 2048.0, | |
500 4096.0, 8192.0, 16384.0, | |
501 32768.0, 65536.0, 131072.0, | |
502 262144.0, 524288.0, 1048576.0, | |
503 2097152.0, 4194304.0, 8388608.0, | |
504 16777216.0, 33554432.0, 67108864.0, | |
505 134217728.0, 268435456.0, 536870912.0, | |
506 1073741824.0, 2147483648.0, 4294967296.0, | |
507 8589934592.0, 17179869184.0, 34359738368.0, | |
508 68719476736.0, 137438953472.0, 274877906944.0 | |
10725 | 509 }; |
510 #endif | |
511 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
512 /* quant_to_spec: perform dequantisation and scaling |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
513 * and in case of short block it also does the deinterleaving |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
514 */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
515 /* |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
516 For ONLY_LONG_SEQUENCE windows (num_window_groups = 1, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
517 window_group_length[0] = 1) the spectral data is in ascending spectral |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
518 order. |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
519 For the EIGHT_SHORT_SEQUENCE window, the spectral order depends on the |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
520 grouping in the following manner: |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
521 - Groups are ordered sequentially |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
522 - Within a group, a scalefactor band consists of the spectral data of all |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
523 grouped SHORT_WINDOWs for the associated scalefactor window band. To |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
524 clarify via example, the length of a group is in the range of one to eight |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
525 SHORT_WINDOWs. |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
526 - If there are eight groups each with length one (num_window_groups = 8, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
527 window_group_length[0..7] = 1), the result is a sequence of eight spectra, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
528 each in ascending spectral order. |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
529 - If there is only one group with length eight (num_window_groups = 1, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
530 window_group_length[0] = 8), the result is that spectral data of all eight |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
531 SHORT_WINDOWs is interleaved by scalefactor window bands. |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
532 - Within a scalefactor window band, the coefficients are in ascending |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
533 spectral order. |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
534 */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
535 static uint8_t quant_to_spec(NeAACDecHandle hDecoder, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
536 ic_stream *ics, int16_t *quant_data, |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
537 real_t *spec_data, uint16_t frame_len) |
12527 | 538 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
539 ALIGN static const real_t pow2_table[] = |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
540 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
541 COEF_CONST(1.0), |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
542 COEF_CONST(1.1892071150027210667174999705605), /* 2^0.25 */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
543 COEF_CONST(1.4142135623730950488016887242097), /* 2^0.5 */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
544 COEF_CONST(1.6817928305074290860622509524664) /* 2^0.75 */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
545 }; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
546 const real_t *tab = iq_table; |
12527 | 547 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
548 uint8_t g, sfb, win; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
549 uint16_t width, bin, k, gindex; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
550 uint8_t error = 0; /* Init error flag */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
551 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
552 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
553 k = 0; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
554 gindex = 0; |
10725 | 555 |
556 for (g = 0; g < ics->num_window_groups; g++) | |
557 { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
558 uint16_t j = 0; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
559 uint16_t gincrease = 0; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
560 uint16_t win_inc = ics->swb_offset[ics->num_swb]; |
10725 | 561 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
562 for (sfb = 0; sfb < ics->num_swb; sfb++) |
10725 | 563 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
564 int32_t exp, frac; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
565 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
566 width = ics->swb_offset[sfb+1] - ics->swb_offset[sfb]; |
10725 | 567 |
12527 | 568 /* this could be scalefactor for IS or PNS, those can be negative or bigger then 255 */ |
569 /* just ignore them */ | |
570 if (ics->scale_factors[g][sfb] < 0 || ics->scale_factors[g][sfb] > 255) | |
571 { | |
572 exp = 0; | |
573 frac = 0; | |
574 } else { | |
575 /* ics->scale_factors[g][sfb] must be between 0 and 255 */ | |
576 exp = (ics->scale_factors[g][sfb] /* - 100 */) >> 2; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
577 /* frac must always be > 0 */ |
12527 | 578 frac = (ics->scale_factors[g][sfb] /* - 100 */) & 3; |
579 } | |
10725 | 580 |
12527 | 581 #ifdef FIXED_POINT |
582 exp -= 25; | |
10989 | 583 /* IMDCT pre-scaling */ |
10725 | 584 if (hDecoder->object_type == LD) |
585 { | |
586 exp -= 6 /*9*/; | |
587 } else { | |
588 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE) | |
589 exp -= 4 /*7*/; | |
590 else | |
591 exp -= 7 /*10*/; | |
592 } | |
593 #endif | |
594 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
595 for (win = 0; win < ics->window_group_length[g]; win++) |
10725 | 596 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
597 for (bin = 0; bin < width; bin += 4) |
10725 | 598 { |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
599 #ifndef FIXED_POINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
600 spec_data[gindex+(win*win_inc)+j+bin+0] = iquant(quant_data[k+0], tab, &error) * |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
601 pow2sf_tab[exp/*+25*/] * pow2_table[frac]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
602 spec_data[gindex+(win*win_inc)+j+bin+1] = iquant(quant_data[k+1], tab, &error) * |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
603 pow2sf_tab[exp/*+25*/] * pow2_table[frac]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
604 spec_data[gindex+(win*win_inc)+j+bin+2] = iquant(quant_data[k+2], tab, &error) * |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
605 pow2sf_tab[exp/*+25*/] * pow2_table[frac]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
606 spec_data[gindex+(win*win_inc)+j+bin+3] = iquant(quant_data[k+3], tab, &error) * |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
607 pow2sf_tab[exp/*+25*/] * pow2_table[frac]; |
12527 | 608 #else |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
609 real_t iq0 = iquant(quant_data[k+0], tab, &error); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
610 real_t iq1 = iquant(quant_data[k+1], tab, &error); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
611 real_t iq2 = iquant(quant_data[k+2], tab, &error); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
612 real_t iq3 = iquant(quant_data[k+3], tab, &error); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
613 if (exp < 0) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
614 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
615 spec_data[gindex+(win*win_inc)+j+bin+0] = iq0 >>= -exp; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
616 spec_data[gindex+(win*win_inc)+j+bin+1] = iq1 >>= -exp; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
617 spec_data[gindex+(win*win_inc)+j+bin+2] = iq2 >>= -exp; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
618 spec_data[gindex+(win*win_inc)+j+bin+3] = iq3 >>= -exp; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
619 } else { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
620 spec_data[gindex+(win*win_inc)+j+bin+0] = iq0 <<= exp; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
621 spec_data[gindex+(win*win_inc)+j+bin+1] = iq1 <<= exp; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
622 spec_data[gindex+(win*win_inc)+j+bin+2] = iq2 <<= exp; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
623 spec_data[gindex+(win*win_inc)+j+bin+3] = iq3 <<= exp; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
624 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
625 spec_data[gindex+(win*win_inc)+j+bin+0] = MUL_C(spec_data[gindex+(win*win_inc)+j+bin+0],pow2_table[frac]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
626 spec_data[gindex+(win*win_inc)+j+bin+1] = MUL_C(spec_data[gindex+(win*win_inc)+j+bin+1],pow2_table[frac]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
627 spec_data[gindex+(win*win_inc)+j+bin+2] = MUL_C(spec_data[gindex+(win*win_inc)+j+bin+2],pow2_table[frac]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
628 spec_data[gindex+(win*win_inc)+j+bin+3] = MUL_C(spec_data[gindex+(win*win_inc)+j+bin+3],pow2_table[frac]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
629 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
630 //#define SCFS_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
631 #ifdef SCFS_PRINT |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
632 //printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+0]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
633 //printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+1]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
634 //printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+2]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
635 //printf("%d\n", spec_data[gindex+(win*win_inc)+j+bin+3]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
636 printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+0]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
637 printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+1]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
638 printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+2]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
639 printf("0x%.8X\n", spec_data[gindex+(win*win_inc)+j+bin+3]); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
640 #endif |
12527 | 641 #endif |
10725 | 642 |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
643 gincrease += 4; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
644 k += 4; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
645 } |
12527 | 646 } |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
647 j += width; |
12527 | 648 } |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
649 gindex += gincrease; |
12527 | 650 } |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
651 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
652 return error; |
12527 | 653 } |
654 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
655 static uint8_t allocate_single_channel(NeAACDecHandle hDecoder, uint8_t channel, |
12527 | 656 uint8_t output_channels) |
657 { | |
658 uint8_t mul = 1; | |
659 | |
660 #ifdef MAIN_DEC | |
661 /* MAIN object type prediction */ | |
662 if (hDecoder->object_type == MAIN) | |
663 { | |
664 /* allocate the state only when needed */ | |
665 if (hDecoder->pred_stat[channel] == NULL) | |
666 { | |
667 hDecoder->pred_stat[channel] = (pred_state*)faad_malloc(hDecoder->frameLength * sizeof(pred_state)); | |
668 reset_all_predictors(hDecoder->pred_stat[channel], hDecoder->frameLength); | |
669 } | |
670 } | |
671 #endif | |
672 | |
673 #ifdef LTP_DEC | |
674 if (is_ltp_ot(hDecoder->object_type)) | |
675 { | |
676 /* allocate the state only when needed */ | |
677 if (hDecoder->lt_pred_stat[channel] == NULL) | |
678 { | |
679 hDecoder->lt_pred_stat[channel] = (int16_t*)faad_malloc(hDecoder->frameLength*4 * sizeof(int16_t)); | |
680 memset(hDecoder->lt_pred_stat[channel], 0, hDecoder->frameLength*4 * sizeof(int16_t)); | |
681 } | |
682 } | |
683 #endif | |
684 | |
685 if (hDecoder->time_out[channel] == NULL) | |
686 { | |
687 mul = 1; | |
688 #ifdef SBR_DEC | |
689 hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 0; | |
690 if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | |
691 { | |
692 /* SBR requires 2 times as much output data */ | |
693 mul = 2; | |
694 hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1; | |
695 } | |
696 #endif | |
697 hDecoder->time_out[channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t)); | |
698 memset(hDecoder->time_out[channel], 0, mul*hDecoder->frameLength*sizeof(real_t)); | |
699 } | |
700 #if (defined(PS_DEC) || defined(DRM_PS)) | |
701 if (output_channels == 2) | |
702 { | |
703 if (hDecoder->time_out[channel+1] == NULL) | |
704 { | |
705 hDecoder->time_out[channel+1] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t)); | |
706 memset(hDecoder->time_out[channel+1], 0, mul*hDecoder->frameLength*sizeof(real_t)); | |
707 } | |
708 } | |
709 #endif | |
710 | |
711 if (hDecoder->fb_intermed[channel] == NULL) | |
712 { | |
713 hDecoder->fb_intermed[channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t)); | |
714 memset(hDecoder->fb_intermed[channel], 0, hDecoder->frameLength*sizeof(real_t)); | |
715 } | |
716 | |
717 #ifdef SSR_DEC | |
718 if (hDecoder->object_type == SSR) | |
719 { | |
720 if (hDecoder->ssr_overlap[channel] == NULL) | |
721 { | |
722 hDecoder->ssr_overlap[channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
723 memset(hDecoder->ssr_overlap[channel], 0, 2*hDecoder->frameLength*sizeof(real_t)); | |
724 } | |
725 if (hDecoder->prev_fmd[channel] == NULL) | |
726 { | |
727 uint16_t k; | |
728 hDecoder->prev_fmd[channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
729 for (k = 0; k < 2*hDecoder->frameLength; k++) | |
730 hDecoder->prev_fmd[channel][k] = REAL_CONST(-1); | |
731 } | |
732 } | |
733 #endif | |
734 | |
735 return 0; | |
736 } | |
737 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
738 static uint8_t allocate_channel_pair(NeAACDecHandle hDecoder, |
12527 | 739 uint8_t channel, uint8_t paired_channel) |
740 { | |
741 uint8_t mul = 1; | |
742 | |
743 #ifdef MAIN_DEC | |
744 /* MAIN object type prediction */ | |
745 if (hDecoder->object_type == MAIN) | |
746 { | |
747 /* allocate the state only when needed */ | |
748 if (hDecoder->pred_stat[channel] == NULL) | |
749 { | |
750 hDecoder->pred_stat[channel] = (pred_state*)faad_malloc(hDecoder->frameLength * sizeof(pred_state)); | |
751 reset_all_predictors(hDecoder->pred_stat[channel], hDecoder->frameLength); | |
752 } | |
753 if (hDecoder->pred_stat[paired_channel] == NULL) | |
754 { | |
755 hDecoder->pred_stat[paired_channel] = (pred_state*)faad_malloc(hDecoder->frameLength * sizeof(pred_state)); | |
756 reset_all_predictors(hDecoder->pred_stat[paired_channel], hDecoder->frameLength); | |
757 } | |
758 } | |
759 #endif | |
760 | |
761 #ifdef LTP_DEC | |
762 if (is_ltp_ot(hDecoder->object_type)) | |
763 { | |
764 /* allocate the state only when needed */ | |
765 if (hDecoder->lt_pred_stat[channel] == NULL) | |
766 { | |
767 hDecoder->lt_pred_stat[channel] = (int16_t*)faad_malloc(hDecoder->frameLength*4 * sizeof(int16_t)); | |
768 memset(hDecoder->lt_pred_stat[channel], 0, hDecoder->frameLength*4 * sizeof(int16_t)); | |
769 } | |
770 if (hDecoder->lt_pred_stat[paired_channel] == NULL) | |
771 { | |
772 hDecoder->lt_pred_stat[paired_channel] = (int16_t*)faad_malloc(hDecoder->frameLength*4 * sizeof(int16_t)); | |
773 memset(hDecoder->lt_pred_stat[paired_channel], 0, hDecoder->frameLength*4 * sizeof(int16_t)); | |
774 } | |
775 } | |
776 #endif | |
777 | |
778 if (hDecoder->time_out[channel] == NULL) | |
779 { | |
780 mul = 1; | |
781 #ifdef SBR_DEC | |
782 hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 0; | |
783 if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | |
784 { | |
785 /* SBR requires 2 times as much output data */ | |
786 mul = 2; | |
787 hDecoder->sbr_alloced[hDecoder->fr_ch_ele] = 1; | |
788 } | |
789 #endif | |
790 hDecoder->time_out[channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t)); | |
791 memset(hDecoder->time_out[channel], 0, mul*hDecoder->frameLength*sizeof(real_t)); | |
792 } | |
793 if (hDecoder->time_out[paired_channel] == NULL) | |
794 { | |
795 hDecoder->time_out[paired_channel] = (real_t*)faad_malloc(mul*hDecoder->frameLength*sizeof(real_t)); | |
796 memset(hDecoder->time_out[paired_channel], 0, mul*hDecoder->frameLength*sizeof(real_t)); | |
797 } | |
798 | |
799 if (hDecoder->fb_intermed[channel] == NULL) | |
800 { | |
801 hDecoder->fb_intermed[channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t)); | |
802 memset(hDecoder->fb_intermed[channel], 0, hDecoder->frameLength*sizeof(real_t)); | |
803 } | |
804 if (hDecoder->fb_intermed[paired_channel] == NULL) | |
805 { | |
806 hDecoder->fb_intermed[paired_channel] = (real_t*)faad_malloc(hDecoder->frameLength*sizeof(real_t)); | |
807 memset(hDecoder->fb_intermed[paired_channel], 0, hDecoder->frameLength*sizeof(real_t)); | |
808 } | |
809 | |
810 #ifdef SSR_DEC | |
811 if (hDecoder->object_type == SSR) | |
812 { | |
813 if (hDecoder->ssr_overlap[cpe->channel] == NULL) | |
814 { | |
815 hDecoder->ssr_overlap[cpe->channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
816 memset(hDecoder->ssr_overlap[cpe->channel], 0, 2*hDecoder->frameLength*sizeof(real_t)); | |
817 } | |
818 if (hDecoder->ssr_overlap[cpe->paired_channel] == NULL) | |
819 { | |
820 hDecoder->ssr_overlap[cpe->paired_channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
821 memset(hDecoder->ssr_overlap[cpe->paired_channel], 0, 2*hDecoder->frameLength*sizeof(real_t)); | |
822 } | |
823 if (hDecoder->prev_fmd[cpe->channel] == NULL) | |
824 { | |
825 uint16_t k; | |
826 hDecoder->prev_fmd[cpe->channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
827 for (k = 0; k < 2*hDecoder->frameLength; k++) | |
828 hDecoder->prev_fmd[cpe->channel][k] = REAL_CONST(-1); | |
829 } | |
830 if (hDecoder->prev_fmd[cpe->paired_channel] == NULL) | |
831 { | |
832 uint16_t k; | |
833 hDecoder->prev_fmd[cpe->paired_channel] = (real_t*)faad_malloc(2*hDecoder->frameLength*sizeof(real_t)); | |
834 for (k = 0; k < 2*hDecoder->frameLength; k++) | |
835 hDecoder->prev_fmd[cpe->paired_channel][k] = REAL_CONST(-1); | |
836 } | |
837 } | |
838 #endif | |
839 | |
840 return 0; | |
841 } | |
842 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
843 uint8_t reconstruct_single_channel(NeAACDecHandle hDecoder, ic_stream *ics, |
12527 | 844 element *sce, int16_t *spec_data) |
845 { | |
846 uint8_t retval, output_channels; | |
847 ALIGN real_t spec_coef[1024]; | |
848 | |
849 #ifdef PROFILE | |
850 int64_t count = faad_get_ts(); | |
851 #endif | |
852 | |
853 | |
854 /* determine whether some mono->stereo tool is used */ | |
855 #if (defined(PS_DEC) || defined(DRM_PS)) | |
856 output_channels = hDecoder->ps_used[hDecoder->fr_ch_ele] ? 2 : 1; | |
857 #else | |
858 output_channels = 1; | |
859 #endif | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
860 #ifdef DRM_PS |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
861 /* for DRM error recovery is crucial */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
862 /* simply always allocate 2 channels, you never know when PS will pop up */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
863 if (hDecoder->object_type == DRM_ER_LC) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
864 output_channels = 2; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
865 #endif |
12527 | 866 if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] == 0) |
867 { | |
868 /* element_output_channels not set yet */ | |
869 hDecoder->element_output_channels[hDecoder->fr_ch_ele] = output_channels; | |
870 } else if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] != output_channels) { | |
871 /* element inconsistency */ | |
872 return 21; | |
873 } | |
874 | |
875 if (hDecoder->element_alloced[hDecoder->fr_ch_ele] == 0) | |
876 { | |
877 retval = allocate_single_channel(hDecoder, sce->channel, output_channels); | |
878 if (retval > 0) | |
879 return retval; | |
880 | |
881 hDecoder->element_alloced[hDecoder->fr_ch_ele] = 1; | |
882 } | |
883 | |
884 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
885 /* dequantisation and scaling */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
886 retval = quant_to_spec(hDecoder, ics, spec_data, spec_coef, hDecoder->frameLength); |
12527 | 887 if (retval > 0) |
888 return retval; | |
889 | |
890 #ifdef PROFILE | |
891 count = faad_get_ts() - count; | |
892 hDecoder->requant_cycles += count; | |
893 #endif | |
894 | |
895 | |
896 /* pns decoding */ | |
897 pns_decode(ics, NULL, spec_coef, NULL, hDecoder->frameLength, 0, hDecoder->object_type); | |
898 | |
899 #ifdef MAIN_DEC | |
900 /* MAIN object type prediction */ | |
901 if (hDecoder->object_type == MAIN) | |
902 { | |
903 /* intra channel prediction */ | |
904 ic_prediction(ics, spec_coef, hDecoder->pred_stat[sce->channel], hDecoder->frameLength, | |
905 hDecoder->sf_index); | |
906 | |
907 /* In addition, for scalefactor bands coded by perceptual | |
908 noise substitution the predictors belonging to the | |
909 corresponding spectral coefficients are reset. | |
910 */ | |
911 pns_reset_pred_state(ics, hDecoder->pred_stat[sce->channel]); | |
912 } | |
913 #endif | |
914 | |
915 #ifdef LTP_DEC | |
916 if (is_ltp_ot(hDecoder->object_type)) | |
917 { | |
918 #ifdef LD_DEC | |
919 if (hDecoder->object_type == LD) | |
920 { | |
921 if (ics->ltp.data_present) | |
922 { | |
923 if (ics->ltp.lag_update) | |
924 hDecoder->ltp_lag[sce->channel] = ics->ltp.lag; | |
925 } | |
926 ics->ltp.lag = hDecoder->ltp_lag[sce->channel]; | |
927 } | |
928 #endif | |
929 | |
930 /* long term prediction */ | |
931 lt_prediction(ics, &(ics->ltp), spec_coef, hDecoder->lt_pred_stat[sce->channel], hDecoder->fb, | |
932 ics->window_shape, hDecoder->window_shape_prev[sce->channel], | |
933 hDecoder->sf_index, hDecoder->object_type, hDecoder->frameLength); | |
934 } | |
935 #endif | |
936 | |
937 /* tns decoding */ | |
938 tns_decode_frame(ics, &(ics->tns), hDecoder->sf_index, hDecoder->object_type, | |
939 spec_coef, hDecoder->frameLength); | |
940 | |
941 /* drc decoding */ | |
942 if (hDecoder->drc->present) | |
943 { | |
944 if (!hDecoder->drc->exclude_mask[sce->channel] || !hDecoder->drc->excluded_chns_present) | |
945 drc_decode(hDecoder->drc, spec_coef); | |
946 } | |
947 | |
948 /* filter bank */ | |
949 #ifdef SSR_DEC | |
950 if (hDecoder->object_type != SSR) | |
951 { | |
952 #endif | |
953 #ifdef USE_SSE | |
954 hDecoder->fb->if_func(hDecoder->fb, ics->window_sequence, ics->window_shape, | |
955 hDecoder->window_shape_prev[sce->channel], spec_coef, | |
956 hDecoder->time_out[sce->channel], hDecoder->object_type, hDecoder->frameLength); | |
957 #else | |
958 ifilter_bank(hDecoder->fb, ics->window_sequence, ics->window_shape, | |
959 hDecoder->window_shape_prev[sce->channel], spec_coef, | |
960 hDecoder->time_out[sce->channel], hDecoder->fb_intermed[sce->channel], | |
961 hDecoder->object_type, hDecoder->frameLength); | |
962 #endif | |
963 #ifdef SSR_DEC | |
964 } else { | |
965 ssr_decode(&(ics->ssr), hDecoder->fb, ics->window_sequence, ics->window_shape, | |
966 hDecoder->window_shape_prev[sce->channel], spec_coef, hDecoder->time_out[sce->channel], | |
967 hDecoder->ssr_overlap[sce->channel], hDecoder->ipqf_buffer[sce->channel], hDecoder->prev_fmd[sce->channel], | |
968 hDecoder->frameLength); | |
969 } | |
970 #endif | |
971 | |
972 /* save window shape for next frame */ | |
973 hDecoder->window_shape_prev[sce->channel] = ics->window_shape; | |
974 | |
975 #ifdef LTP_DEC | |
976 if (is_ltp_ot(hDecoder->object_type)) | |
977 { | |
978 lt_update_state(hDecoder->lt_pred_stat[sce->channel], hDecoder->time_out[sce->channel], | |
979 hDecoder->fb_intermed[sce->channel], hDecoder->frameLength, hDecoder->object_type); | |
980 } | |
981 #endif | |
982 | |
983 #ifdef SBR_DEC | |
984 if (((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | |
985 && hDecoder->sbr_alloced[hDecoder->fr_ch_ele]) | |
986 { | |
987 uint8_t ele = hDecoder->fr_ch_ele; | |
988 uint8_t ch = sce->channel; | |
989 | |
990 /* following case can happen when forceUpSampling == 1 */ | |
991 if (hDecoder->sbr[ele] == NULL) | |
992 { | |
993 hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength, | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
994 hDecoder->element_id[ele], 2*get_sample_rate(hDecoder->sf_index), |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
995 hDecoder->downSampledSBR |
12527 | 996 #ifdef DRM |
997 , 0 | |
998 #endif | |
999 ); | |
1000 } | |
1001 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1002 if (sce->ics1.window_sequence == EIGHT_SHORT_SEQUENCE) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1003 hDecoder->sbr[ele]->maxAACLine = 8*sce->ics1.swb_offset[max(sce->ics1.max_sfb-1, 0)]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1004 else |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1005 hDecoder->sbr[ele]->maxAACLine = sce->ics1.swb_offset[max(sce->ics1.max_sfb-1, 0)]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1006 |
12527 | 1007 /* check if any of the PS tools is used */ |
1008 #if (defined(PS_DEC) || defined(DRM_PS)) | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1009 if (hDecoder->ps_used[ele] == 0) |
12527 | 1010 { |
1011 #endif | |
1012 retval = sbrDecodeSingleFrame(hDecoder->sbr[ele], hDecoder->time_out[ch], | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1013 hDecoder->postSeekResetFlag, hDecoder->downSampledSBR); |
12527 | 1014 #if (defined(PS_DEC) || defined(DRM_PS)) |
1015 } else { | |
1016 retval = sbrDecodeSingleFramePS(hDecoder->sbr[ele], hDecoder->time_out[ch], | |
1017 hDecoder->time_out[ch+1], hDecoder->postSeekResetFlag, | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1018 hDecoder->downSampledSBR); |
12527 | 1019 } |
1020 #endif | |
1021 if (retval > 0) | |
1022 return retval; | |
1023 } else if (((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | |
1024 && !hDecoder->sbr_alloced[hDecoder->fr_ch_ele]) | |
1025 { | |
1026 return 23; | |
1027 } | |
1028 #endif | |
1029 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1030 #ifdef DRM_PS |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1031 /* copy L to R for DRM when no PS is used */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1032 if ((hDecoder->object_type == DRM_ER_LC) && |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1033 (hDecoder->ps_used[hDecoder->fr_ch_ele] == 0)) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1034 { |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1035 uint8_t ele = hDecoder->fr_ch_ele; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1036 uint8_t ch = sce->channel; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1037 uint16_t frame_size = (hDecoder->sbr_alloced[ele]) ? 2 : 1; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1038 frame_size *= hDecoder->frameLength*sizeof(real_t); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1039 |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1040 memcpy(hDecoder->time_out[ch+1], hDecoder->time_out[ch], frame_size); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1041 } |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1042 #endif |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1043 |
12527 | 1044 return 0; |
1045 } | |
1046 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1047 uint8_t reconstruct_channel_pair(NeAACDecHandle hDecoder, ic_stream *ics1, ic_stream *ics2, |
12527 | 1048 element *cpe, int16_t *spec_data1, int16_t *spec_data2) |
1049 { | |
1050 uint8_t retval; | |
1051 ALIGN real_t spec_coef1[1024]; | |
1052 ALIGN real_t spec_coef2[1024]; | |
1053 | |
1054 #ifdef PROFILE | |
1055 int64_t count = faad_get_ts(); | |
1056 #endif | |
1057 if (hDecoder->element_alloced[hDecoder->fr_ch_ele] == 0) | |
1058 { | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1059 retval = allocate_channel_pair(hDecoder, cpe->channel, (uint8_t)cpe->paired_channel); |
12527 | 1060 if (retval > 0) |
1061 return retval; | |
1062 | |
1063 hDecoder->element_alloced[hDecoder->fr_ch_ele] = 1; | |
1064 } | |
1065 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1066 /* dequantisation and scaling */ |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1067 retval = quant_to_spec(hDecoder, ics1, spec_data1, spec_coef1, hDecoder->frameLength); |
12527 | 1068 if (retval > 0) |
1069 return retval; | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1070 retval = quant_to_spec(hDecoder, ics2, spec_data2, spec_coef2, hDecoder->frameLength); |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1071 if (retval > 0) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1072 return retval; |
12527 | 1073 |
1074 #ifdef PROFILE | |
1075 count = faad_get_ts() - count; | |
1076 hDecoder->requant_cycles += count; | |
1077 #endif | |
1078 | |
1079 | |
1080 /* pns decoding */ | |
1081 if (ics1->ms_mask_present) | |
1082 { | |
1083 pns_decode(ics1, ics2, spec_coef1, spec_coef2, hDecoder->frameLength, 1, hDecoder->object_type); | |
1084 } else { | |
1085 pns_decode(ics1, NULL, spec_coef1, NULL, hDecoder->frameLength, 0, hDecoder->object_type); | |
1086 pns_decode(ics2, NULL, spec_coef2, NULL, hDecoder->frameLength, 0, hDecoder->object_type); | |
1087 } | |
1088 | |
1089 /* mid/side decoding */ | |
1090 ms_decode(ics1, ics2, spec_coef1, spec_coef2, hDecoder->frameLength); | |
1091 | |
1092 /* intensity stereo decoding */ | |
1093 is_decode(ics1, ics2, spec_coef1, spec_coef2, hDecoder->frameLength); | |
1094 | |
1095 #ifdef MAIN_DEC | |
1096 /* MAIN object type prediction */ | |
1097 if (hDecoder->object_type == MAIN) | |
1098 { | |
1099 /* intra channel prediction */ | |
1100 ic_prediction(ics1, spec_coef1, hDecoder->pred_stat[cpe->channel], hDecoder->frameLength, | |
1101 hDecoder->sf_index); | |
1102 ic_prediction(ics2, spec_coef2, hDecoder->pred_stat[cpe->paired_channel], hDecoder->frameLength, | |
1103 hDecoder->sf_index); | |
1104 | |
1105 /* In addition, for scalefactor bands coded by perceptual | |
1106 noise substitution the predictors belonging to the | |
1107 corresponding spectral coefficients are reset. | |
1108 */ | |
1109 pns_reset_pred_state(ics1, hDecoder->pred_stat[cpe->channel]); | |
1110 pns_reset_pred_state(ics2, hDecoder->pred_stat[cpe->paired_channel]); | |
1111 } | |
1112 #endif | |
1113 | |
1114 #ifdef LTP_DEC | |
1115 if (is_ltp_ot(hDecoder->object_type)) | |
1116 { | |
1117 ltp_info *ltp1 = &(ics1->ltp); | |
1118 ltp_info *ltp2 = (cpe->common_window) ? &(ics2->ltp2) : &(ics2->ltp); | |
1119 #ifdef LD_DEC | |
1120 if (hDecoder->object_type == LD) | |
1121 { | |
1122 if (ltp1->data_present) | |
1123 { | |
1124 if (ltp1->lag_update) | |
1125 hDecoder->ltp_lag[cpe->channel] = ltp1->lag; | |
1126 } | |
1127 ltp1->lag = hDecoder->ltp_lag[cpe->channel]; | |
1128 if (ltp2->data_present) | |
1129 { | |
1130 if (ltp2->lag_update) | |
1131 hDecoder->ltp_lag[cpe->paired_channel] = ltp2->lag; | |
1132 } | |
1133 ltp2->lag = hDecoder->ltp_lag[cpe->paired_channel]; | |
1134 } | |
1135 #endif | |
1136 | |
1137 /* long term prediction */ | |
1138 lt_prediction(ics1, ltp1, spec_coef1, hDecoder->lt_pred_stat[cpe->channel], hDecoder->fb, | |
1139 ics1->window_shape, hDecoder->window_shape_prev[cpe->channel], | |
1140 hDecoder->sf_index, hDecoder->object_type, hDecoder->frameLength); | |
1141 lt_prediction(ics2, ltp2, spec_coef2, hDecoder->lt_pred_stat[cpe->paired_channel], hDecoder->fb, | |
1142 ics2->window_shape, hDecoder->window_shape_prev[cpe->paired_channel], | |
1143 hDecoder->sf_index, hDecoder->object_type, hDecoder->frameLength); | |
1144 } | |
1145 #endif | |
1146 | |
1147 /* tns decoding */ | |
1148 tns_decode_frame(ics1, &(ics1->tns), hDecoder->sf_index, hDecoder->object_type, | |
1149 spec_coef1, hDecoder->frameLength); | |
1150 tns_decode_frame(ics2, &(ics2->tns), hDecoder->sf_index, hDecoder->object_type, | |
1151 spec_coef2, hDecoder->frameLength); | |
1152 | |
1153 /* drc decoding */ | |
1154 if (hDecoder->drc->present) | |
1155 { | |
1156 if (!hDecoder->drc->exclude_mask[cpe->channel] || !hDecoder->drc->excluded_chns_present) | |
1157 drc_decode(hDecoder->drc, spec_coef1); | |
1158 if (!hDecoder->drc->exclude_mask[cpe->paired_channel] || !hDecoder->drc->excluded_chns_present) | |
1159 drc_decode(hDecoder->drc, spec_coef2); | |
1160 } | |
1161 | |
1162 /* filter bank */ | |
1163 #ifdef SSR_DEC | |
1164 if (hDecoder->object_type != SSR) | |
1165 { | |
1166 #endif | |
1167 #ifdef USE_SSE | |
1168 hDecoder->fb->if_func(hDecoder->fb, ics1->window_sequence, ics1->window_shape, | |
1169 hDecoder->window_shape_prev[cpe->channel], spec_coef1, | |
1170 hDecoder->time_out[cpe->channel], hDecoder->object_type, hDecoder->frameLength); | |
1171 hDecoder->fb->if_func(hDecoder->fb, ics2->window_sequence, ics2->window_shape, | |
1172 hDecoder->window_shape_prev[cpe->paired_channel], spec_coef2, | |
1173 hDecoder->time_out[cpe->paired_channel], hDecoder->object_type, hDecoder->frameLength); | |
1174 #else | |
1175 ifilter_bank(hDecoder->fb, ics1->window_sequence, ics1->window_shape, | |
1176 hDecoder->window_shape_prev[cpe->channel], spec_coef1, | |
1177 hDecoder->time_out[cpe->channel], hDecoder->fb_intermed[cpe->channel], | |
1178 hDecoder->object_type, hDecoder->frameLength); | |
1179 ifilter_bank(hDecoder->fb, ics2->window_sequence, ics2->window_shape, | |
1180 hDecoder->window_shape_prev[cpe->paired_channel], spec_coef2, | |
1181 hDecoder->time_out[cpe->paired_channel], hDecoder->fb_intermed[cpe->paired_channel], | |
1182 hDecoder->object_type, hDecoder->frameLength); | |
1183 #endif | |
1184 #ifdef SSR_DEC | |
1185 } else { | |
1186 ssr_decode(&(ics1->ssr), hDecoder->fb, ics1->window_sequence, ics1->window_shape, | |
1187 hDecoder->window_shape_prev[cpe->channel], spec_coef1, hDecoder->time_out[cpe->channel], | |
1188 hDecoder->ssr_overlap[cpe->channel], hDecoder->ipqf_buffer[cpe->channel], | |
1189 hDecoder->prev_fmd[cpe->channel], hDecoder->frameLength); | |
1190 ssr_decode(&(ics2->ssr), hDecoder->fb, ics2->window_sequence, ics2->window_shape, | |
1191 hDecoder->window_shape_prev[cpe->paired_channel], spec_coef2, hDecoder->time_out[cpe->paired_channel], | |
1192 hDecoder->ssr_overlap[cpe->paired_channel], hDecoder->ipqf_buffer[cpe->paired_channel], | |
1193 hDecoder->prev_fmd[cpe->paired_channel], hDecoder->frameLength); | |
1194 } | |
1195 #endif | |
1196 | |
1197 /* save window shape for next frame */ | |
1198 hDecoder->window_shape_prev[cpe->channel] = ics1->window_shape; | |
1199 hDecoder->window_shape_prev[cpe->paired_channel] = ics2->window_shape; | |
1200 | |
1201 #ifdef LTP_DEC | |
1202 if (is_ltp_ot(hDecoder->object_type)) | |
1203 { | |
1204 lt_update_state(hDecoder->lt_pred_stat[cpe->channel], hDecoder->time_out[cpe->channel], | |
1205 hDecoder->fb_intermed[cpe->channel], hDecoder->frameLength, hDecoder->object_type); | |
1206 lt_update_state(hDecoder->lt_pred_stat[cpe->paired_channel], hDecoder->time_out[cpe->paired_channel], | |
1207 hDecoder->fb_intermed[cpe->paired_channel], hDecoder->frameLength, hDecoder->object_type); | |
1208 } | |
1209 #endif | |
1210 | |
1211 #ifdef SBR_DEC | |
1212 if (((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | |
1213 && hDecoder->sbr_alloced[hDecoder->fr_ch_ele]) | |
1214 { | |
1215 uint8_t ele = hDecoder->fr_ch_ele; | |
1216 uint8_t ch0 = cpe->channel; | |
1217 uint8_t ch1 = cpe->paired_channel; | |
1218 | |
1219 /* following case can happen when forceUpSampling == 1 */ | |
1220 if (hDecoder->sbr[ele] == NULL) | |
1221 { | |
1222 hDecoder->sbr[ele] = sbrDecodeInit(hDecoder->frameLength, | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1223 hDecoder->element_id[ele], 2*get_sample_rate(hDecoder->sf_index), |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1224 hDecoder->downSampledSBR |
12527 | 1225 #ifdef DRM |
1226 , 0 | |
1227 #endif | |
1228 ); | |
1229 } | |
1230 | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1231 if (cpe->ics1.window_sequence == EIGHT_SHORT_SEQUENCE) |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1232 hDecoder->sbr[ele]->maxAACLine = 8*cpe->ics1.swb_offset[max(cpe->ics1.max_sfb-1, 0)]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1233 else |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1234 hDecoder->sbr[ele]->maxAACLine = cpe->ics1.swb_offset[max(cpe->ics1.max_sfb-1, 0)]; |
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1235 |
12527 | 1236 retval = sbrDecodeCoupleFrame(hDecoder->sbr[ele], |
1237 hDecoder->time_out[ch0], hDecoder->time_out[ch1], | |
13453
6d50ef45a058
Update FAAD to a 2.1 beta CVS snapshot from 2004.07.12.
diego
parents:
12625
diff
changeset
|
1238 hDecoder->postSeekResetFlag, hDecoder->downSampledSBR); |
12527 | 1239 if (retval > 0) |
1240 return retval; | |
1241 } else if (((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) | |
1242 && !hDecoder->sbr_alloced[hDecoder->fr_ch_ele]) | |
1243 { | |
1244 return 23; | |
1245 } | |
1246 #endif | |
1247 | |
1248 return 0; | |
1249 } |