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