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