10725
|
1 /*
|
|
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
|
|
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
|
|
4 **
|
|
5 ** This program is free software; you can redistribute it and/or modify
|
|
6 ** it under the terms of the GNU General Public License as published by
|
|
7 ** the Free Software Foundation; either version 2 of the License, or
|
|
8 ** (at your option) any later version.
|
|
9 **
|
|
10 ** This program is distributed in the hope that it will be useful,
|
|
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 ** GNU General Public License for more details.
|
|
14 **
|
|
15 ** You should have received a copy of the GNU General Public License
|
|
16 ** along with this program; if not, write to the Free Software
|
|
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
18 **
|
|
19 ** Any non-GPL usage of this software or parts of this software is strictly
|
|
20 ** forbidden.
|
|
21 **
|
|
22 ** Commercial non-GPL licensing of this software is possible.
|
|
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
|
|
24 **
|
10989
|
25 ** $Id: specrec.c,v 1.27 2003/09/30 12:43:05 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>
|
|
39 #include "specrec.h"
|
|
40 #include "syntax.h"
|
|
41 #include "iq_table.h"
|
|
42
|
|
43 #ifdef LD_DEC
|
|
44 static uint8_t num_swb_512_window[] =
|
|
45 {
|
|
46 0, 0, 0, 36, 36, 37, 31, 31, 0, 0, 0, 0
|
|
47 };
|
|
48 static uint8_t num_swb_480_window[] =
|
|
49 {
|
|
50 0, 0, 0, 35, 35, 37, 30, 30, 0, 0, 0, 0
|
|
51 };
|
|
52 #endif
|
|
53
|
|
54 static uint8_t num_swb_960_window[] =
|
|
55 {
|
|
56 40, 40, 45, 49, 49, 49, 46, 46, 42, 42, 42, 40
|
|
57 };
|
|
58
|
|
59 static uint8_t num_swb_1024_window[] =
|
|
60 {
|
|
61 41, 41, 47, 49, 49, 51, 47, 47, 43, 43, 43, 40
|
|
62 };
|
|
63
|
|
64 static uint8_t num_swb_128_window[] =
|
|
65 {
|
|
66 12, 12, 12, 14, 14, 14, 15, 15, 15, 15, 15, 15
|
|
67 };
|
|
68
|
|
69 static uint16_t swb_offset_1024_96[] =
|
|
70 {
|
|
71 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56,
|
|
72 64, 72, 80, 88, 96, 108, 120, 132, 144, 156, 172, 188, 212, 240,
|
|
73 276, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896, 960, 1024
|
|
74 };
|
|
75
|
|
76 static uint16_t swb_offset_128_96[] =
|
|
77 {
|
|
78 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128
|
|
79 };
|
|
80
|
|
81 static uint16_t swb_offset_1024_64[] =
|
|
82 {
|
|
83 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56,
|
|
84 64, 72, 80, 88, 100, 112, 124, 140, 156, 172, 192, 216, 240, 268,
|
|
85 304, 344, 384, 424, 464, 504, 544, 584, 624, 664, 704, 744, 784, 824,
|
|
86 864, 904, 944, 984, 1024
|
|
87 };
|
|
88
|
|
89 static uint16_t swb_offset_128_64[] =
|
|
90 {
|
|
91 0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 92, 128
|
|
92 };
|
|
93
|
|
94
|
|
95 static uint16_t swb_offset_1024_48[] =
|
|
96 {
|
|
97 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72,
|
|
98 80, 88, 96, 108, 120, 132, 144, 160, 176, 196, 216, 240, 264, 292,
|
|
99 320, 352, 384, 416, 448, 480, 512, 544, 576, 608, 640, 672, 704, 736,
|
|
100 768, 800, 832, 864, 896, 928, 1024
|
|
101 };
|
|
102
|
|
103 #ifdef LD_DEC
|
|
104 static uint16_t swb_offset_512_48[] =
|
|
105 {
|
|
106 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 68, 76, 84,
|
|
107 92, 100, 112, 124, 136, 148, 164, 184, 208, 236, 268, 300, 332, 364, 396,
|
|
108 428, 460, 512
|
|
109 };
|
|
110
|
|
111 static uint16_t swb_offset_480_48[] =
|
|
112 {
|
|
113 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 64, 72 ,80 ,88,
|
|
114 96, 108, 120, 132, 144, 156, 172, 188, 212, 240, 272, 304, 336, 368, 400,
|
|
115 432, 480
|
|
116 };
|
|
117 #endif
|
|
118
|
|
119 static uint16_t swb_offset_128_48[] =
|
|
120 {
|
|
121 0, 4, 8, 12, 16, 20, 28, 36, 44, 56, 68, 80, 96, 112, 128
|
|
122 };
|
|
123
|
|
124 static uint16_t swb_offset_1024_32[] =
|
|
125 {
|
|
126 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72,
|
|
127 80, 88, 96, 108, 120, 132, 144, 160, 176, 196, 216, 240, 264, 292,
|
|
128 320, 352, 384, 416, 448, 480, 512, 544, 576, 608, 640, 672, 704, 736,
|
|
129 768, 800, 832, 864, 896, 928, 960, 992, 1024
|
|
130 };
|
|
131
|
|
132 #ifdef LD_DEC
|
|
133 static uint16_t swb_offset_512_32[] =
|
|
134 {
|
|
135 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 64, 72, 80,
|
|
136 88, 96, 108, 120, 132, 144, 160, 176, 192, 212, 236, 260, 288, 320, 352,
|
|
137 384, 416, 448, 480, 512
|
|
138 };
|
|
139
|
|
140 static uint16_t swb_offset_480_32[] =
|
|
141 {
|
|
142 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 72, 80,
|
|
143 88, 96, 104, 112, 124, 136, 148, 164, 180, 200, 224, 256, 288, 320, 352,
|
|
144 384, 416, 448, 480
|
|
145 };
|
|
146 #endif
|
|
147
|
|
148 static uint16_t swb_offset_1024_24[] =
|
|
149 {
|
|
150 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 52, 60, 68,
|
|
151 76, 84, 92, 100, 108, 116, 124, 136, 148, 160, 172, 188, 204, 220,
|
|
152 240, 260, 284, 308, 336, 364, 396, 432, 468, 508, 552, 600, 652, 704,
|
|
153 768, 832, 896, 960, 1024
|
|
154 };
|
|
155
|
|
156 #ifdef LD_DEC
|
|
157 static uint16_t swb_offset_512_24[] =
|
|
158 {
|
|
159 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 52, 60, 68,
|
|
160 80, 92, 104, 120, 140, 164, 192, 224, 256, 288, 320, 352, 384, 416,
|
|
161 448, 480, 512
|
|
162 };
|
|
163
|
|
164 static uint16_t swb_offset_480_24[] =
|
|
165 {
|
|
166 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 52, 60, 68, 80, 92, 104, 120,
|
|
167 140, 164, 192, 224, 256, 288, 320, 352, 384, 416, 448, 480
|
|
168 };
|
|
169 #endif
|
|
170
|
|
171 static uint16_t swb_offset_128_24[] =
|
|
172 {
|
|
173 0, 4, 8, 12, 16, 20, 24, 28, 36, 44, 52, 64, 76, 92, 108, 128
|
|
174 };
|
|
175
|
|
176 static uint16_t swb_offset_1024_16[] =
|
|
177 {
|
|
178 0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 100, 112, 124,
|
|
179 136, 148, 160, 172, 184, 196, 212, 228, 244, 260, 280, 300, 320, 344,
|
|
180 368, 396, 424, 456, 492, 532, 572, 616, 664, 716, 772, 832, 896, 960, 1024
|
|
181 };
|
|
182
|
|
183 static uint16_t swb_offset_128_16[] =
|
|
184 {
|
|
185 0, 4, 8, 12, 16, 20, 24, 28, 32, 40, 48, 60, 72, 88, 108, 128
|
|
186 };
|
|
187
|
|
188 static uint16_t swb_offset_1024_8[] =
|
|
189 {
|
|
190 0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144, 156, 172,
|
|
191 188, 204, 220, 236, 252, 268, 288, 308, 328, 348, 372, 396, 420, 448,
|
|
192 476, 508, 544, 580, 620, 664, 712, 764, 820, 880, 944, 1024
|
|
193 };
|
|
194
|
|
195 static uint16_t swb_offset_128_8[] =
|
|
196 {
|
|
197 0, 4, 8, 12, 16, 20, 24, 28, 36, 44, 52, 60, 72, 88, 108, 128
|
|
198 };
|
|
199
|
|
200 static uint16_t *swb_offset_1024_window[] =
|
|
201 {
|
|
202 swb_offset_1024_96, /* 96000 */
|
|
203 swb_offset_1024_96, /* 88200 */
|
|
204 swb_offset_1024_64, /* 64000 */
|
|
205 swb_offset_1024_48, /* 48000 */
|
|
206 swb_offset_1024_48, /* 44100 */
|
|
207 swb_offset_1024_32, /* 32000 */
|
|
208 swb_offset_1024_24, /* 24000 */
|
|
209 swb_offset_1024_24, /* 22050 */
|
|
210 swb_offset_1024_16, /* 16000 */
|
|
211 swb_offset_1024_16, /* 12000 */
|
|
212 swb_offset_1024_16, /* 11025 */
|
|
213 swb_offset_1024_8 /* 8000 */
|
|
214 };
|
|
215
|
|
216 #ifdef LD_DEC
|
|
217 static uint16_t *swb_offset_512_window[] =
|
|
218 {
|
|
219 0, /* 96000 */
|
|
220 0, /* 88200 */
|
|
221 0, /* 64000 */
|
|
222 swb_offset_512_48, /* 48000 */
|
|
223 swb_offset_512_48, /* 44100 */
|
|
224 swb_offset_512_32, /* 32000 */
|
|
225 swb_offset_512_24, /* 24000 */
|
|
226 swb_offset_512_24, /* 22050 */
|
|
227 0, /* 16000 */
|
|
228 0, /* 12000 */
|
|
229 0, /* 11025 */
|
|
230 0 /* 8000 */
|
|
231 };
|
|
232
|
|
233 static uint16_t *swb_offset_480_window[] =
|
|
234 {
|
|
235 0, /* 96000 */
|
|
236 0, /* 88200 */
|
|
237 0, /* 64000 */
|
|
238 swb_offset_480_48, /* 48000 */
|
|
239 swb_offset_480_48, /* 44100 */
|
|
240 swb_offset_480_32, /* 32000 */
|
|
241 swb_offset_480_24, /* 24000 */
|
|
242 swb_offset_480_24, /* 22050 */
|
|
243 0, /* 16000 */
|
|
244 0, /* 12000 */
|
|
245 0, /* 11025 */
|
|
246 0 /* 8000 */
|
|
247 };
|
|
248 #endif
|
|
249
|
|
250 static uint16_t *swb_offset_128_window[] =
|
|
251 {
|
|
252 swb_offset_128_96, /* 96000 */
|
|
253 swb_offset_128_96, /* 88200 */
|
|
254 swb_offset_128_64, /* 64000 */
|
|
255 swb_offset_128_48, /* 48000 */
|
|
256 swb_offset_128_48, /* 44100 */
|
|
257 swb_offset_128_48, /* 32000 */
|
|
258 swb_offset_128_24, /* 24000 */
|
|
259 swb_offset_128_24, /* 22050 */
|
|
260 swb_offset_128_16, /* 16000 */
|
|
261 swb_offset_128_16, /* 12000 */
|
|
262 swb_offset_128_16, /* 11025 */
|
|
263 swb_offset_128_8 /* 8000 */
|
|
264 };
|
|
265
|
|
266 #define bit_set(A, B) ((A) & (1<<(B)))
|
|
267
|
|
268 /* 4.5.2.3.4 */
|
|
269 /*
|
|
270 - determine the number of windows in a window_sequence named num_windows
|
|
271 - determine the number of window_groups named num_window_groups
|
|
272 - determine the number of windows in each group named window_group_length[g]
|
|
273 - determine the total number of scalefactor window bands named num_swb for
|
|
274 the actual window type
|
|
275 - determine swb_offset[swb], the offset of the first coefficient in
|
|
276 scalefactor window band named swb of the window actually used
|
|
277 - determine sect_sfb_offset[g][section],the offset of the first coefficient
|
|
278 in section named section. This offset depends on window_sequence and
|
|
279 scale_factor_grouping and is needed to decode the spectral_data().
|
|
280 */
|
|
281 uint8_t window_grouping_info(faacDecHandle hDecoder, ic_stream *ics)
|
|
282 {
|
|
283 uint8_t i, g;
|
|
284
|
|
285 uint8_t sf_index = hDecoder->sf_index;
|
|
286
|
|
287 switch (ics->window_sequence) {
|
|
288 case ONLY_LONG_SEQUENCE:
|
|
289 case LONG_START_SEQUENCE:
|
|
290 case LONG_STOP_SEQUENCE:
|
|
291 ics->num_windows = 1;
|
|
292 ics->num_window_groups = 1;
|
|
293 ics->window_group_length[ics->num_window_groups-1] = 1;
|
|
294 #ifdef LD_DEC
|
|
295 if (hDecoder->object_type == LD)
|
|
296 {
|
|
297 if (hDecoder->frameLength == 512)
|
|
298 ics->num_swb = num_swb_512_window[sf_index];
|
|
299 else /* if (hDecoder->frameLength == 480) */
|
|
300 ics->num_swb = num_swb_480_window[sf_index];
|
|
301 } else {
|
|
302 #endif
|
|
303 if (hDecoder->frameLength == 1024)
|
|
304 ics->num_swb = num_swb_1024_window[sf_index];
|
|
305 else /* if (hDecoder->frameLength == 960) */
|
|
306 ics->num_swb = num_swb_960_window[sf_index];
|
|
307 #ifdef LD_DEC
|
|
308 }
|
|
309 #endif
|
|
310
|
|
311 /* preparation of sect_sfb_offset for long blocks */
|
|
312 /* also copy the last value! */
|
|
313 #ifdef LD_DEC
|
|
314 if (hDecoder->object_type == LD)
|
|
315 {
|
|
316 if (hDecoder->frameLength == 512)
|
|
317 {
|
|
318 for (i = 0; i < ics->num_swb; i++)
|
|
319 {
|
|
320 ics->sect_sfb_offset[0][i] = swb_offset_512_window[sf_index][i];
|
|
321 ics->swb_offset[i] = swb_offset_512_window[sf_index][i];
|
|
322 }
|
|
323 } else /* if (hDecoder->frameLength == 480) */ {
|
|
324 for (i = 0; i < ics->num_swb; i++)
|
|
325 {
|
|
326 ics->sect_sfb_offset[0][i] = swb_offset_480_window[sf_index][i];
|
|
327 ics->swb_offset[i] = swb_offset_480_window[sf_index][i];
|
|
328 }
|
|
329 }
|
|
330 ics->sect_sfb_offset[0][ics->num_swb] = hDecoder->frameLength;
|
|
331 ics->swb_offset[ics->num_swb] = hDecoder->frameLength;
|
|
332 } else {
|
|
333 #endif
|
|
334 for (i = 0; i < ics->num_swb; i++)
|
|
335 {
|
|
336 ics->sect_sfb_offset[0][i] = swb_offset_1024_window[sf_index][i];
|
|
337 ics->swb_offset[i] = swb_offset_1024_window[sf_index][i];
|
|
338 }
|
|
339 ics->sect_sfb_offset[0][ics->num_swb] = hDecoder->frameLength;
|
|
340 ics->swb_offset[ics->num_swb] = hDecoder->frameLength;
|
|
341 #ifdef LD_DEC
|
|
342 }
|
|
343 #endif
|
|
344 return 0;
|
|
345 case EIGHT_SHORT_SEQUENCE:
|
|
346 ics->num_windows = 8;
|
|
347 ics->num_window_groups = 1;
|
|
348 ics->window_group_length[ics->num_window_groups-1] = 1;
|
|
349 ics->num_swb = num_swb_128_window[sf_index];
|
|
350
|
|
351 for (i = 0; i < ics->num_swb; i++)
|
|
352 ics->swb_offset[i] = swb_offset_128_window[sf_index][i];
|
|
353 ics->swb_offset[ics->num_swb] = hDecoder->frameLength/8;
|
|
354
|
|
355 for (i = 0; i < ics->num_windows-1; i++) {
|
|
356 if (bit_set(ics->scale_factor_grouping, 6-i) == 0)
|
|
357 {
|
|
358 ics->num_window_groups += 1;
|
|
359 ics->window_group_length[ics->num_window_groups-1] = 1;
|
|
360 } else {
|
|
361 ics->window_group_length[ics->num_window_groups-1] += 1;
|
|
362 }
|
|
363 }
|
|
364
|
|
365 /* preparation of sect_sfb_offset for short blocks */
|
|
366 for (g = 0; g < ics->num_window_groups; g++)
|
|
367 {
|
|
368 uint16_t width;
|
|
369 uint8_t sect_sfb = 0;
|
|
370 uint16_t offset = 0;
|
|
371
|
|
372 for (i = 0; i < ics->num_swb; i++)
|
|
373 {
|
|
374 if (i+1 == ics->num_swb)
|
|
375 {
|
|
376 width = (hDecoder->frameLength/8) - swb_offset_128_window[sf_index][i];
|
|
377 } else {
|
|
378 width = swb_offset_128_window[sf_index][i+1] -
|
|
379 swb_offset_128_window[sf_index][i];
|
|
380 }
|
|
381 width *= ics->window_group_length[g];
|
|
382 ics->sect_sfb_offset[g][sect_sfb++] = offset;
|
|
383 offset += width;
|
|
384 }
|
|
385 ics->sect_sfb_offset[g][sect_sfb] = offset;
|
|
386 }
|
|
387 return 0;
|
|
388 default:
|
|
389 return 1;
|
|
390 }
|
|
391 }
|
|
392
|
|
393 /*
|
|
394 For ONLY_LONG_SEQUENCE windows (num_window_groups = 1,
|
|
395 window_group_length[0] = 1) the spectral data is in ascending spectral
|
|
396 order.
|
|
397 For the EIGHT_SHORT_SEQUENCE window, the spectral order depends on the
|
|
398 grouping in the following manner:
|
|
399 - Groups are ordered sequentially
|
|
400 - Within a group, a scalefactor band consists of the spectral data of all
|
|
401 grouped SHORT_WINDOWs for the associated scalefactor window band. To
|
|
402 clarify via example, the length of a group is in the range of one to eight
|
|
403 SHORT_WINDOWs.
|
|
404 - If there are eight groups each with length one (num_window_groups = 8,
|
|
405 window_group_length[0..7] = 1), the result is a sequence of eight spectra,
|
|
406 each in ascending spectral order.
|
|
407 - If there is only one group with length eight (num_window_groups = 1,
|
|
408 window_group_length[0] = 8), the result is that spectral data of all eight
|
|
409 SHORT_WINDOWs is interleaved by scalefactor window bands.
|
|
410 - Within a scalefactor window band, the coefficients are in ascending
|
|
411 spectral order.
|
|
412 */
|
|
413 void quant_to_spec(ic_stream *ics, real_t *spec_data, uint16_t frame_len)
|
|
414 {
|
|
415 uint8_t g, sfb, win;
|
10989
|
416 uint16_t width, bin, k, gindex;
|
10725
|
417
|
|
418 real_t tmp_spec[1024];
|
10989
|
419
|
|
420 memset(tmp_spec, 0, frame_len*sizeof(real_t));
|
10725
|
421
|
10989
|
422 k = 0;
|
|
423 gindex = 0;
|
10725
|
424
|
|
425 for (g = 0; g < ics->num_window_groups; g++)
|
|
426 {
|
|
427 uint16_t j = 0;
|
10989
|
428 uint16_t gincrease = 0;
|
|
429 uint16_t win_inc = ics->swb_offset[ics->num_swb];
|
10725
|
430
|
|
431 for (sfb = 0; sfb < ics->num_swb; sfb++)
|
|
432 {
|
|
433 width = ics->swb_offset[sfb+1] - ics->swb_offset[sfb];
|
|
434
|
|
435 for (win = 0; win < ics->window_group_length[g]; win++)
|
|
436 {
|
|
437 for (bin = 0; bin < width; bin += 4)
|
|
438 {
|
10989
|
439 tmp_spec[gindex+(win*win_inc)+j+bin+0] = spec_data[k+0];
|
|
440 tmp_spec[gindex+(win*win_inc)+j+bin+1] = spec_data[k+1];
|
|
441 tmp_spec[gindex+(win*win_inc)+j+bin+2] = spec_data[k+2];
|
|
442 tmp_spec[gindex+(win*win_inc)+j+bin+3] = spec_data[k+3];
|
|
443 gincrease += 4;
|
|
444 k += 4;
|
10725
|
445 }
|
|
446 }
|
|
447 j += width;
|
|
448 }
|
10989
|
449 gindex += gincrease;
|
10725
|
450 }
|
|
451
|
10989
|
452 memcpy(spec_data, tmp_spec, frame_len*sizeof(real_t));
|
10725
|
453 }
|
|
454
|
|
455 #ifndef FIXED_POINT
|
|
456 void build_tables(real_t *pow2_table)
|
|
457 {
|
|
458 uint16_t i;
|
|
459
|
|
460 /* build pow(2, 0.25*x) table for scalefactors */
|
|
461 for(i = 0; i < POW_TABLE_SIZE; i++)
|
|
462 {
|
|
463 pow2_table[i] = REAL_CONST(pow(2.0, 0.25 * (i-100)));
|
|
464 }
|
|
465 }
|
|
466 #endif
|
|
467
|
|
468 static INLINE real_t iquant(int16_t q, real_t *tab)
|
|
469 {
|
10989
|
470 #ifdef FIXED_POINT
|
10725
|
471 int16_t sgn = 1;
|
|
472
|
|
473 if (q == 0) return 0;
|
|
474
|
|
475 if (q < 0)
|
|
476 {
|
|
477 q = -q;
|
|
478 sgn = -1;
|
|
479 }
|
|
480
|
|
481 if (q >= IQ_TABLE_SIZE)
|
10989
|
482 return 0; /* sgn * tab[q>>3] * 16; */
|
10725
|
483
|
|
484 return sgn * tab[q];
|
10989
|
485 #else
|
|
486 int16_t sgn = 1;
|
|
487
|
|
488 if (q == 0) return 0;
|
|
489
|
|
490 if (q < 0)
|
|
491 {
|
|
492 q = -q;
|
|
493 sgn = -1;
|
|
494 }
|
|
495
|
|
496 if (q < IQ_TABLE_SIZE)
|
|
497 return sgn * tab[q];
|
|
498
|
|
499 return sgn * pow(q, 4./3.);
|
|
500 #endif
|
10725
|
501 }
|
|
502
|
|
503 void inverse_quantization(real_t *x_invquant, int16_t *x_quant, uint16_t frame_len)
|
|
504 {
|
|
505 int16_t i;
|
|
506 real_t *tab = iq_table;
|
|
507
|
10989
|
508 for(i = 0; i < frame_len; i+=4)
|
10725
|
509 {
|
10989
|
510 x_invquant[i] = iquant(x_quant[i], tab);
|
|
511 x_invquant[i+1] = iquant(x_quant[i+1], tab);
|
|
512 x_invquant[i+2] = iquant(x_quant[i+2], tab);
|
|
513 x_invquant[i+3] = iquant(x_quant[i+3], tab);
|
10725
|
514 }
|
|
515 }
|
|
516
|
|
517 #ifndef FIXED_POINT
|
|
518 static INLINE real_t get_scale_factor_gain(uint16_t scale_factor, real_t *pow2_table)
|
|
519 {
|
|
520 if (scale_factor < POW_TABLE_SIZE)
|
|
521 return pow2_table[scale_factor];
|
|
522 else
|
|
523 return REAL_CONST(pow(2.0, 0.25 * (scale_factor - 100)));
|
|
524 }
|
|
525 #else
|
|
526 static real_t pow2_table[] =
|
|
527 {
|
|
528 COEF_CONST(0.59460355750136),
|
|
529 COEF_CONST(0.70710678118655),
|
|
530 COEF_CONST(0.84089641525371),
|
|
531 COEF_CONST(1.0),
|
|
532 COEF_CONST(1.18920711500272),
|
|
533 COEF_CONST(1.41421356237310),
|
|
534 COEF_CONST(1.68179283050743)
|
|
535 };
|
|
536 #endif
|
|
537
|
|
538 void apply_scalefactors(faacDecHandle hDecoder, ic_stream *ics, real_t *x_invquant,
|
|
539 uint16_t frame_len)
|
|
540 {
|
|
541 uint8_t g, sfb;
|
|
542 uint16_t top;
|
|
543 #ifndef FIXED_POINT
|
|
544 real_t scale;
|
|
545 #else
|
|
546 int32_t exp, frac;
|
|
547 #endif
|
|
548 uint8_t groups = 0;
|
|
549 uint16_t nshort = frame_len/8;
|
|
550
|
10989
|
551 static real_t max_fp = 0;
|
|
552 static real_t max_exp = 0;
|
|
553 static real_t max_frac = 0;
|
|
554
|
10725
|
555 for (g = 0; g < ics->num_window_groups; g++)
|
|
556 {
|
|
557 uint16_t k = 0;
|
|
558
|
10989
|
559 /* using this nshort*groups doesn't hurt long blocks, because
|
10725
|
560 long blocks only have 1 group, so that means 'groups' is
|
|
561 always 0 for long blocks
|
|
562 */
|
|
563 for (sfb = 0; sfb < ics->max_sfb; sfb++)
|
|
564 {
|
|
565 top = ics->sect_sfb_offset[g][sfb+1];
|
|
566
|
|
567 #ifndef FIXED_POINT
|
10989
|
568 scale = get_scale_factor_gain(ics->scale_factors[g][sfb], hDecoder->pow2_table);
|
10725
|
569 #else
|
|
570 exp = (ics->scale_factors[g][sfb] - 100) / 4;
|
|
571 frac = (ics->scale_factors[g][sfb] - 100) % 4;
|
|
572
|
10989
|
573 /* IMDCT pre-scaling */
|
10725
|
574 if (hDecoder->object_type == LD)
|
|
575 {
|
|
576 exp -= 6 /*9*/;
|
|
577 } else {
|
|
578 if (ics->window_sequence == EIGHT_SHORT_SEQUENCE)
|
|
579 exp -= 4 /*7*/;
|
|
580 else
|
|
581 exp -= 7 /*10*/;
|
|
582 }
|
|
583 #endif
|
|
584
|
|
585 /* minimum size of a sf band is 4 and always a multiple of 4 */
|
|
586 for ( ; k < top; k += 4)
|
|
587 {
|
|
588 #ifndef FIXED_POINT
|
10989
|
589 x_invquant[k+(groups*nshort)] = x_invquant[k+(groups*nshort)] * scale;
|
|
590 x_invquant[k+(groups*nshort)+1] = x_invquant[k+(groups*nshort)+1] * scale;
|
|
591 x_invquant[k+(groups*nshort)+2] = x_invquant[k+(groups*nshort)+2] * scale;
|
|
592 x_invquant[k+(groups*nshort)+3] = x_invquant[k+(groups*nshort)+3] * scale;
|
10725
|
593 #else
|
|
594 if (exp < 0)
|
|
595 {
|
10989
|
596 x_invquant[k+(groups*nshort)] >>= -exp;
|
|
597 x_invquant[k+(groups*nshort)+1] >>= -exp;
|
|
598 x_invquant[k+(groups*nshort)+2] >>= -exp;
|
|
599 x_invquant[k+(groups*nshort)+3] >>= -exp;
|
10725
|
600 } else {
|
10989
|
601 x_invquant[k+(groups*nshort)] <<= exp;
|
|
602 x_invquant[k+(groups*nshort)+1] <<= exp;
|
|
603 x_invquant[k+(groups*nshort)+2] <<= exp;
|
|
604 x_invquant[k+(groups*nshort)+3] <<= exp;
|
10725
|
605 }
|
|
606
|
|
607 if (frac)
|
|
608 {
|
10989
|
609 x_invquant[k+(groups*nshort)] = MUL_R_C(x_invquant[k+(groups*nshort)],pow2_table[frac + 3]);
|
|
610 x_invquant[k+(groups*nshort)+1] = MUL_R_C(x_invquant[k+(groups*nshort)+1],pow2_table[frac + 3]);
|
|
611 x_invquant[k+(groups*nshort)+2] = MUL_R_C(x_invquant[k+(groups*nshort)+2],pow2_table[frac + 3]);
|
|
612 x_invquant[k+(groups*nshort)+3] = MUL_R_C(x_invquant[k+(groups*nshort)+3],pow2_table[frac + 3]);
|
10725
|
613 }
|
|
614 #endif
|
|
615 }
|
|
616 }
|
|
617 groups += ics->window_group_length[g];
|
|
618 }
|
|
619 }
|