1 /*
2 * Copyright (c) 2013
3 * MIPS Technologies, Inc., California.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * AAC decoder fixed-point implementation
30 *
31 * Copyright (c) 2005-2006 Oded Shimon ( ods15 ods15 dyndns org )
32 * Copyright (c) 2006-2007 Maxim Gavrilov ( maxim.gavrilov gmail com )
33 *
34 * This file is part of FFmpeg.
35 *
36 * FFmpeg is free software; you can redistribute it and/or
37 * modify it under the terms of the GNU Lesser General Public
38 * License as published by the Free Software Foundation; either
39 * version 2.1 of the License, or (at your option) any later version.
40 *
41 * FFmpeg is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
44 * Lesser General Public License for more details.
45 *
46 * You should have received a copy of the GNU Lesser General Public
47 * License along with FFmpeg; if not, write to the Free Software
48 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
49 */
50
51 /**
52 * @file
53 * AAC decoder
54 * @author Oded Shimon ( ods15 ods15 dyndns org )
55 * @author Maxim Gavrilov ( maxim.gavrilov gmail com )
56 *
57 * Fixed point implementation
58 * @author Stanislav Ocovaj ( stanislav.ocovaj imgtec com )
59 */
60
63
73
84
85 #include <math.h>
86 #include <string.h>
87
90
92 {
101 ps->
var0.mant = 0x20000000;
103 ps->
var1.mant = 0x20000000;
105 }
106
107 static const int exp2tab[4] = {
Q31(1.0000000000/2),
Q31(1.1892071150/2),
Q31(1.4142135624/2),
Q31(1.6817928305/2) };
// 2^0, 2^0.25, 2^0.5, 2^0.75
108
110 {
111 dst[0] = (idx & 15) - 4;
112 dst[1] = (idx >> 4 & 15) - 4;
113
114 return dst + 2;
115 }
116
118 {
119 dst[0] = (idx & 3) - 1;
120 dst[1] = (idx >> 2 & 3) - 1;
121 dst[2] = (idx >> 4 & 3) - 1;
122 dst[3] = (idx >> 6 & 3) - 1;
123
124 return dst + 4;
125 }
126
127 static inline int *
DEC_UPAIR(
int *dst,
unsigned idx,
unsigned sign)
128 {
129 dst[0] = (idx & 15) * (1 - (sign & 0xFFFFFFFE));
130 dst[1] = (idx >> 4 & 15) * (1 - ((sign & 1) * 2));
131
132 return dst + 2;
133 }
134
135 static inline int *
DEC_UQUAD(
int *dst,
unsigned idx,
unsigned sign)
136 {
137 unsigned nz = idx >> 12;
138
139 dst[0] = (idx & 3) * (1 + (((int)sign >> 31) * 2));
140 sign <<= nz & 1;
141 nz >>= 1;
142 dst[1] = (idx >> 2 & 3) * (1 + (((int)sign >> 31) * 2));
143 sign <<= nz & 1;
144 nz >>= 1;
145 dst[2] = (idx >> 4 & 3) * (1 + (((int)sign >> 31) * 2));
146 sign <<= nz & 1;
147 nz >>= 1;
148 dst[3] = (idx >> 6 & 3) * (1 + (((int)sign >> 31) * 2));
149
150 return dst + 4;
151 }
152
154 {
156
159 if (coef < 0)
161 else
164 }
165 }
166
168 {
169 int ssign =
scale < 0 ? -1 : 1;
173
175
179 }
185 }
186 }
else if (
s > -32) {
191 dst[
i] =
out * (unsigned)ssign;
192 }
193 } else {
195 }
196 }
197
199 {
203 int nlz = 0;
204
206 while (band_energy > 0x7fff) {
207 band_energy >>= 1;
208 nlz++;
209 }
211 s = 21 + nlz - (
s >> 2);
212
216 }
220 out = (
int)(((int64_t)coefs[
i] *
c) >> 32);
222 }
223 }
224 else {
231 }
232 } else {
234 coefs[
i] = -(int64_t)coefs[
i] *
c * (1 << -
s);
235 }
236 }
237 }
238
240 {
243
247 tmp.mant = (
tmp.mant + 0x00200000
U) & 0xFFC00000U;
249
251 }
252
254 {
257
261 tmp.mant = (
tmp.mant + 0x001FFFFF
U + (
tmp.mant & 0x00400000
U >> 16)) & 0xFFC00000
U;
263
265 }
266
268 {
271
277
278 return pun;
279 }
280
282 int output_enable)
283 {
284 const SoftFloat a = { 1023410176, 0 };
// 61.0 / 64
293
294 if (var0.
exp > 1 || (var0.
exp == 1 && var0.
mant > 0x20000000)) {
296 }
297 else {
300 }
301
302 if (var1.exp > 1 || (var1.exp == 1 && var1.mant > 0x20000000)) {
304 }
305 else {
308 }
309
312 if (output_enable) {
314
317 *coef += (unsigned)((
pv.mant + (1 << (
shift - 1))) >>
shift);
318 } else
319 *coef += (unsigned)
pv.mant << -
shift;
320 }
321 }
322
325
334
337 }
338
339
342 Q30(1.0905077327),
//2^(1/8)
343 Q30(1.1892071150),
//2^(2/8)
344 Q30(1.2968395547),
//2^(3/8)
345 Q30(1.4142135624),
//2^(4/8)
346 Q30(1.5422108254),
//2^(5/8)
347 Q30(1.6817928305),
//2^(6/8)
348 Q30(1.8340080864),
//2^(7/8)
349 };
350
351 /**
352 * Apply dependent channel coupling (applied before IMDCT).
353 *
354 * @param index index into coupling gain array
355 */
359 {
362 int *dest = target->
coeffs;
364 int g,
i, group, k, idx = 0;
367 "Dependent coupling is not supported together with LTP\n");
368 return;
369 }
375
376 if (gain < 0) {
378 shift = (-gain-1024) >> 3;
379 }
380 else {
382 shift = (gain-1024) >> 3;
383 }
384
386 // Nothing to do
387 }
else if (
shift < 0) {
390
391 for (group = 0; group < ics->
group_len[
g]; group++) {
393 tmp = (
int)(((int64_t)
src[group * 128 + k] *
c + \
394 (int64_t)0x1000000000) >> 37);
396 }
397 }
398 }
399 else {
400 for (group = 0; group < ics->
group_len[
g]; group++) {
402 tmp = (
int)(((int64_t)
src[group * 128 + k] *
c + \
403 (int64_t)0x1000000000) >> 37);
404 dest[group * 128 + k] +=
tmp * (1
U <<
shift);
405 }
406 }
407 }
408 }
409 }
412 }
413 }
414
415 /**
416 * Apply independent channel coupling (applied after IMDCT).
417 *
418 * @param index index into coupling gain array
419 */
423 {
427 unsigned int *dest = target->
ret;
429
431 shift = (gain-1024) >> 3;
433 return;
434 }
else if (
shift < 0) {
437
438 for (
i = 0;
i <
len;
i++) {
439 tmp = (
int)(((int64_t)
src[
i] *
c + (int64_t)0x1000000000) >> 37);
441 }
442 }
443 else {
444 for (
i = 0;
i <
len;
i++) {
445 tmp = (
int)(((int64_t)
src[
i] *
c + (int64_t)0x1000000000) >> 37);
447 }
448 }
449 }
450
452
464 },
470 };