1 /*
2 * AAC decoder
3 * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
4 * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
5 * Copyright (c) 2008-2013 Alex Converse <alex.converse@gmail.com>
6 *
7 * AAC LATM decoder
8 * Copyright (c) 2008-2010 Paul Kendall <paul@kcbbs.gen.nz>
9 * Copyright (c) 2010 Janne Grunau <janne-libav@jannau.net>
10 *
11 * AAC decoder fixed-point implementation
12 * Copyright (c) 2013
13 * MIPS Technologies, Inc., California.
14 *
15 * This file is part of FFmpeg.
16 *
17 * FFmpeg is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
21 *
22 * FFmpeg is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with FFmpeg; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 */
31
32 /**
33 * linear congruential pseudorandom number generator
34 *
35 * @param previous_val pointer to the current state of the generator
36 *
37 * @return Returns a 32-bit pseudorandom integer
38 */
40 {
41 union {
unsigned u;
int s; } v = { previous_val * 1664525
u + 1013904223 };
42 return v.s;
43 }
44
45 /**
46 * Decode spectral data; reference: table 4.50.
47 * Dequantize and scale spectral data; reference: 4.6.3.3.
48 *
49 * @param coef array of dequantized, scaled spectral data
50 * @param sf array of scalefactors or intensity stereo positions
51 * @param pulse_present set if pulses are present
52 * @param pulse pointer to pulse data struct
53 * @param band_type array of the used band type
54 *
55 * @return Returns error status. 0 - OK, !0 - error
56 */
61 {
63 INTFLOAT *coef = sce->AAC_RENAME(coeffs);
67 const INTFLOAT *sf = sce->AAC_RENAME(sf);
68 const enum BandType *band_type = sce->band_type;
70
74
77
79 const unsigned cbt_m1 = band_type[idx] - 1;
82 int group;
83
85 for (group = 0; group < (
AAC_SIGNE)g_len; group++, cfo+=128) {
86 memset(cfo, 0, off_len * sizeof(*cfo));
87 }
89 for (group = 0; group < (
AAC_SIGNE)g_len; group++, cfo+=128) {
91 #if USE_FIXED
92 for (k = 0; k < off_len; k++) {
93 ac->random_state =
lcg_random(ac->random_state);
94 cfo[k] = ac->random_state >> 3;
95 }
96
97 band_energy = ac->fdsp->scalarproduct_fixed(cfo, cfo, off_len);
100 #else
102
103 for (k = 0; k < off_len; k++) {
104 ac->random_state =
lcg_random(ac->random_state);
105 cfo[k] = ac->random_state;
106 }
107
108 band_energy = ac->fdsp->scalarproduct_float(cfo, cfo, off_len);
110 ac->fdsp->vector_fmul_scalar(cfo, cfo,
scale, off_len);
111 #endif /* USE_FIXED */
112 }
113 } else {
114 #if !USE_FIXED
116 #endif /* !USE_FIXED */
119
120 switch (cbt_m1 >> 1) {
121 case 0:
122 for (group = 0; group < (
AAC_SIGNE)g_len; group++, cfo+=128) {
125
126 do {
128 unsigned cb_idx;
129
133 #if USE_FIXED
135 #else
136 cf =
VMUL4(cf, vq, cb_idx, sf + idx);
137 #endif /* USE_FIXED */
139 }
140 break;
141
142 case 1:
143 for (group = 0; group < (
AAC_SIGNE)g_len; group++, cfo+=128) {
146
147 do {
149 unsigned nnz;
150 unsigned cb_idx;
152
156 nnz = cb_idx >> 8 & 15;
159 #if USE_FIXED
161 #else
163 #endif /* USE_FIXED */
165 }
166 break;
167
168 case 2:
169 for (group = 0; group < (
AAC_SIGNE)g_len; group++, cfo+=128) {
172
173 do {
175 unsigned cb_idx;
176
180 #if USE_FIXED
182 #else
183 cf =
VMUL2(cf, vq, cb_idx, sf + idx);
184 #endif /* USE_FIXED */
186 }
187 break;
188
189 case 3:
190 case 4:
191 for (group = 0; group < (
AAC_SIGNE)g_len; group++, cfo+=128) {
194
195 do {
197 unsigned nnz;
198 unsigned cb_idx;
199 unsigned sign;
200
204 nnz = cb_idx >> 8 & 15;
205 sign = nnz ?
SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12) : 0;
207 #if USE_FIXED
209 #else
210 cf =
VMUL2S(cf, vq, cb_idx, sign, sf + idx);
211 #endif /* USE_FIXED */
213 }
214 break;
215
216 default:
217 for (group = 0; group < (
AAC_SIGNE)g_len; group++, cfo+=128) {
218 #if USE_FIXED
219 int *icf = cfo;
220 int v;
221 #else
222 float *cf = cfo;
223 uint32_t *icf = (uint32_t *) cf;
224 #endif /* USE_FIXED */
226
227 do {
229 unsigned nzt, nnz;
230 unsigned cb_idx;
232 int j;
233
237
238 if (cb_idx == 0x0000) {
239 *icf++ = 0;
240 *icf++ = 0;
241 continue;
242 }
243
244 nnz = cb_idx >> 12;
245 nzt = cb_idx >> 8;
248
249 for (j = 0; j < 2; j++) {
250 if (nzt & 1<<j) {
252 int n;
253 /* The total length of escape_sequence must be < 22 bits according
254 to the specification (i.e. max is 111111110xxxxxxxxxxxx). */
258
262 }
263
268 #if USE_FIXED
269 v = n;
271 v = -v;
272 *icf++ = v;
273 #else
275 #endif /* USE_FIXED */
277 } else {
278 #if USE_FIXED
279 v = cb_idx & 15;
281 v = -v;
282 *icf++ = v;
283 #else
284 unsigned v = ((const uint32_t*)vq)[cb_idx & 15];
285 *icf++ = (
bits & 1
U<<31) | v;
286 #endif /* USE_FIXED */
288 }
289 cb_idx >>= 4;
290 }
292 #if !USE_FIXED
293 ac->fdsp->vector_fmul_scalar(cfo, cfo, sf[idx], off_len);
294 #endif /* !USE_FIXED */
295 }
296 }
297
299 }
300 }
301 coef += g_len << 7;
302 }
303
304 if (pulse) {
305 idx = 0;
306 for (
i = 0;
i < pulse->num_pulse;
i++) {
307 INTFLOAT co = coef_base[ pulse->pos[
i] ];
308 while (
offsets[idx + 1] <= pulse->pos[
i])
309 idx++;
310 if (band_type[idx] !=
NOISE_BT && sf[idx]) {
312 #if USE_FIXED
313 if (co) {
314 ico = co + (co > 0 ? -ico : ico);
315 }
316 coef_base[ pulse->pos[
i] ] = ico;
317 #else
318 if (co) {
319 co /= sf[idx];
321 }
322 coef_base[ pulse->pos[
i] ] =
cbrtf(
fabsf(ico)) * ico * sf[idx];
323 #endif /* USE_FIXED */
324 }
325 }
326 }
327 #if USE_FIXED
328 coef = coef_base;
329 idx = 0;
332
334 const unsigned cbt_m1 = band_type[idx] - 1;
337 int group;
338
340 for (group = 0; group < (int)g_len; group++, cfo+=128) {
343 }
344 }
345 }
346 coef += g_len << 7;
347 }
348 #endif /* USE_FIXED */
349 return 0;
350 }
351
352 /**
353 * Decode coupling_channel_element; reference: table 4.8.
354 *
355 * @return Returns error status. 0 - OK, !0 - error
356 */
358 {
359 int num_gain = 0;
361 int sign;
365
369 num_gain++;
375 num_gain++;
376 } else
378 }
380
382 #if USE_FIXED
384 #else
386 #endif
387
390
391 for (
c = 0;
c < num_gain;
c++) {
392 int idx = 0;
393 int cge = 1;
394 int gain = 0;
400 #if USE_FIXED
401 if ((
abs(gain_cache)-1024) >> 3 > 30)
403 #endif
404 }
406 coup->gain[
c][0] = gain_cache;
407 } else {
409 for (sfb = 0; sfb < sce->
ics.
max_sfb; sfb++, idx++) {
411 if (!cge) {
413 if (t) {
415 t = gain += t;
416 if (sign) {
418 t >>= 1;
419 }
421 #if USE_FIXED
422 if ((
abs(gain_cache)-1024) >> 3 > 30)
424 #endif
425 }
426 }
427 coup->gain[
c][idx] = gain_cache;
428 }
429 }
430 }
431 }
432 }
433 return 0;
434 }
435
437 {
438 #define SET(member) aac_proc->member = AAC_RENAME(member)
441 #undef SET
442 #define SET(member) aac_proc->member = AV_JOIN(ff_aac_, AAC_RENAME(member));
443 SET(sbr_ctx_alloc_init);
444 SET(sbr_decode_extension);
447 #undef SET
448 }