1 /*
2 * AAC Spectral Band Replication decoding functions
3 * Copyright (c) 2008-2009 Robert Swain ( rob opendot cl )
4 * Copyright (c) 2009-2010 Alex Converse <alex.converse@gmail.com>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 * Note: Rounding-to-nearest used unless otherwise stated
23 *
24 */
25
27
32
34 {
36 uint64_t accu = 0,
round;
37 uint64_t accu0 = 0, accu1 = 0, accu2 = 0, accu3 = 0;
40
41 nz = 0;
42 for (
i = 0;
i < n;
i += 2) {
43 accu0 += (
int64_t)x[
i + 0][0] * x[
i + 0][0];
44 accu1 += (
int64_t)x[
i + 0][1] * x[
i + 0][1];
45 accu2 += (
int64_t)x[
i + 1][0] * x[
i + 1][0];
46 accu3 += (
int64_t)x[
i + 1][1] * x[
i + 1][1];
47 if ((accu0|accu1|accu2|accu3) > UINT64_MAX - INT32_MIN*(
int64_t)INT32_MIN ||
i+2>=n) {
48 accu0 >>= nz;
49 accu1 >>= nz;
50 accu2 >>= nz;
51 accu3 >>= nz;
52 while ((accu0|accu1|accu2|accu3) > (UINT64_MAX - accu) >> 2) {
53 accu0 >>= 1;
54 accu1 >>= 1;
55 accu2 >>= 1;
56 accu3 >>= 1;
57 accu >>= 1;
58 nz ++;
59 }
60 accu += accu0 + accu1 + accu2 + accu3;
61 accu0 = accu1 = accu2 = accu3 = 0;
62 }
63 }
64
65 nz0 = 15 - nz;
66
69 nz = 33;
70 while (
u < 0x80000000U) {
72 nz--;
73 }
74 } else
75 nz = 1;
76
77 round = 1ULL << (nz-1);
78 u = ((accu +
round) >> nz);
81
83 }
84
86 {
88 for (
i = 1;
i < 64;
i += 2)
89 x[
i] = -(
unsigned)x[
i];
90 }
91
93 {
94 int k;
95 z[64] = z[0];
96 z[65] = z[1];
97 for (k = 1; k < 32; k++) {
98 z[64+2*k ] = -z[64 - k];
99 z[64+2*k+1] = z[ k + 1];
100 }
101 }
102
104 {
105 int k;
106 for (k = 0; k < 32; k++) {
109 }
110 }
111
113 {
115 for (
i = 0;
i < 32;
i++) {
116 v[
i] = (int)(0x10U +
src[63 - 2*
i ]) >> 5;
117 v[63 -
i] = (int)(0x10U -
src[63 - 2*
i - 1]) >> 5;
118 }
119 }
120
122 {
123 int nz, mant, expo;
125 int i = (int)(accu >> 32);
127 nz = 1;
128 } else {
129 nz = 0;
130 while (
FFABS(
i) < 0x40000000) {
132 nz++;
133 }
134 nz = 32-nz;
135 }
136
138 mant = (int)((accu +
round) >> nz);
139 mant = (mant + 0x40LL)>>7;
140 mant *= 64;
141 expo = nz + 15;
143 }
144
146 {
149 int64_t accu_re = 0, accu_im = 0;
150
151 if (lag) {
152 for (
i = 1;
i < 38;
i++) {
153 accu_re += (uint64_t)x[
i][0] * x[
i+lag][0];
154 accu_re += (uint64_t)x[
i][1] * x[
i+lag][1];
155 accu_im += (uint64_t)x[
i][0] * x[
i+lag][1];
156 accu_im -= (uint64_t)x[
i][1] * x[
i+lag][0];
157 }
158
159 real_sum = accu_re;
160 imag_sum = accu_im;
161
162 accu_re += (uint64_t)x[ 0][0] * x[lag][0];
163 accu_re += (uint64_t)x[ 0][1] * x[lag][1];
164 accu_im += (uint64_t)x[ 0][0] * x[lag][1];
165 accu_im -= (uint64_t)x[ 0][1] * x[lag][0];
166
169
170 if (lag == 1) {
171 accu_re = real_sum;
172 accu_im = imag_sum;
173 accu_re += (uint64_t)x[38][0] * x[39][0];
174 accu_re += (uint64_t)x[38][1] * x[39][1];
175 accu_im += (uint64_t)x[38][0] * x[39][1];
176 accu_im -= (uint64_t)x[38][1] * x[39][0];
177
180 }
181 } else {
182 for (
i = 1;
i < 38;
i++) {
183 accu_re += (uint64_t)x[
i][0] * x[
i][0];
184 accu_re += (uint64_t)x[
i][1] * x[
i][1];
185 }
186 real_sum = accu_re;
187 accu_re += (uint64_t)x[ 0][0] * x[ 0][0];
188 accu_re += (uint64_t)x[ 0][1] * x[ 0][1];
189
191
192 accu_re = real_sum;
193 accu_re += (uint64_t)x[38][0] * x[38][0];
194 accu_re += (uint64_t)x[38][1] * x[38][1];
195
197 }
198 }
199
201 {
205 }
206
208 const int alpha0[2], const int alpha1[2],
209 int bw, int start, int end)
210 {
214
215 accu = (
int64_t)alpha0[0] * bw;
216 alpha[2] = (int)((accu + 0x40000000) >> 31);
217 accu = (
int64_t)alpha0[1] * bw;
218 alpha[3] = (int)((accu + 0x40000000) >> 31);
220 bw = (int)((accu + 0x40000000) >> 31);
221 accu = (
int64_t)alpha1[0] * bw;
222 alpha[0] = (int)((accu + 0x40000000) >> 31);
223 accu = (
int64_t)alpha1[1] * bw;
224 alpha[1] = (int)((accu + 0x40000000) >> 31);
225
226 for (
i = start;
i < end;
i++) {
227 accu = (
int64_t)X_low[
i][0] * 0x20000000;
232 X_high[
i][0] = (int)((accu + 0x10000000) >> 29);
233
234 accu = (
int64_t)X_low[
i][1] * 0x20000000;
239 X_high[
i][1] = (int)((accu + 0x10000000) >> 29);
240 }
241 }
242
244 const SoftFloat *g_filt,
int m_max, intptr_t ixh)
245 {
246 int m;
248
249 for (m = 0; m < m_max; m++) {
250 if (22 - g_filt[m].
exp < 61) {
252 accu = (
int64_t)X_high[m][ixh][0] * ((g_filt[m].mant + 0x40)>>7);
253 Y[m][0] = (int)((accu +
r) >> (23-g_filt[m].
exp));
254
255 accu = (
int64_t)X_high[m][ixh][1] * ((g_filt[m].mant + 0x40)>>7);
256 Y[m][1] = (int)((accu +
r) >> (23-g_filt[m].
exp));
257 }
258 }
259 }
260
265 int phi_sign0,
266 int phi_sign1,
267 int m_max)
268 {
269 int m;
270
271 for (m = 0; m < m_max; m++) {
272 unsigned y0 =
Y[m][0];
273 unsigned y1 =
Y[m][1];
275 if (s_m[m].mant) {
277
282 }
else if (
shift < 30) {
286 }
287 } else {
290
295 }
else if (
shift < 30) {
297
298 accu = (
int64_t)q_filt[m].mant * ff_sbr_noise_table_fixed[
noise][0];
299 tmp = (int)((accu + 0x40000000) >> 31);
301
302 accu = (
int64_t)q_filt[m].mant * ff_sbr_noise_table_fixed[
noise][1];
303 tmp = (int)((accu + 0x40000000) >> 31);
305 }
306 }
309 phi_sign1 = -phi_sign1;
310 }
311 return 0;
312 }
313