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: sbr_e_nf.c,v 1.2 2003/10/03 22:22:27 alex Exp $
|
10725
|
26 **/
|
|
27
|
|
28 #include "common.h"
|
|
29 #include "structs.h"
|
|
30
|
|
31 #ifdef SBR_DEC
|
|
32
|
|
33 #include <stdlib.h>
|
|
34
|
|
35 #include "sbr_syntax.h"
|
|
36 #include "sbr_e_nf.h"
|
|
37
|
12527
|
38 ALIGN static const real_t pow2deq[] = {
|
|
39 REAL_CONST(2.9103830456733704E-011), REAL_CONST(5.8207660913467407E-011),
|
|
40 REAL_CONST(1.1641532182693481E-010), REAL_CONST(2.3283064365386963E-010),
|
|
41 REAL_CONST(4.6566128730773926E-010), REAL_CONST(9.3132257461547852E-010),
|
|
42 REAL_CONST(1.862645149230957E-009), REAL_CONST(3.7252902984619141E-009),
|
|
43 REAL_CONST(7.4505805969238281E-009), REAL_CONST(1.4901161193847656E-008),
|
|
44 REAL_CONST(2.9802322387695313E-008), REAL_CONST(5.9604644775390625E-008),
|
|
45 REAL_CONST(1.1920928955078125E-007), REAL_CONST(2.384185791015625E-007),
|
|
46 REAL_CONST(4.76837158203125E-007), REAL_CONST(9.5367431640625E-007),
|
|
47 REAL_CONST(1.9073486328125E-006), REAL_CONST(3.814697265625E-006),
|
|
48 REAL_CONST(7.62939453125E-006), REAL_CONST(1.52587890625E-005),
|
|
49 REAL_CONST(3.0517578125E-005), REAL_CONST(6.103515625E-005),
|
|
50 REAL_CONST(0.0001220703125), REAL_CONST(0.000244140625),
|
|
51 REAL_CONST(0.00048828125), REAL_CONST(0.0009765625),
|
|
52 REAL_CONST(0.001953125), REAL_CONST(0.00390625),
|
|
53 REAL_CONST(0.0078125), REAL_CONST(0.015625),
|
|
54 REAL_CONST(0.03125), REAL_CONST(0.0625),
|
|
55 REAL_CONST(0.125), REAL_CONST(0.25),
|
|
56 REAL_CONST(0.5), REAL_CONST(1.0),
|
|
57 REAL_CONST(2.0), REAL_CONST(4.0),
|
|
58 REAL_CONST(8.0), REAL_CONST(16.0),
|
|
59 REAL_CONST(32.0), REAL_CONST(64.0),
|
|
60 REAL_CONST(128.0), REAL_CONST(256.0),
|
|
61 REAL_CONST(512.0), REAL_CONST(1024.0),
|
|
62 REAL_CONST(2048.0), REAL_CONST(4096.0),
|
|
63 REAL_CONST(8192.0), REAL_CONST(16384.0),
|
|
64 REAL_CONST(32768.0), REAL_CONST(65536.0),
|
|
65 REAL_CONST(131072.0), REAL_CONST(262144.0),
|
|
66 REAL_CONST(524288.0), REAL_CONST(1048576.0),
|
|
67 REAL_CONST(2097152.0), REAL_CONST(4194304.0),
|
|
68 REAL_CONST(8388608.0), REAL_CONST(16777216.0),
|
|
69 REAL_CONST(33554432.0), REAL_CONST(67108864.0),
|
|
70 REAL_CONST(134217728.0), REAL_CONST(268435456.0),
|
|
71 REAL_CONST(536870912.0), REAL_CONST(1073741824.0),
|
|
72 REAL_CONST(2147483648.0), REAL_CONST(4294967296.0),
|
|
73 REAL_CONST(8589934592.0), REAL_CONST(17179869184.0),
|
|
74 REAL_CONST(34359738368.0), REAL_CONST(68719476736.0),
|
|
75 REAL_CONST(137438953472.0), REAL_CONST(274877906944.0),
|
|
76 REAL_CONST(549755813888.0), REAL_CONST(1099511627776.0),
|
|
77 REAL_CONST(2199023255552.0), REAL_CONST(4398046511104.0),
|
|
78 REAL_CONST(8796093022208.0), REAL_CONST(17592186044416.0),
|
|
79 REAL_CONST(35184372088832.0), REAL_CONST(70368744177664.0),
|
|
80 REAL_CONST(140737488355328.0), REAL_CONST(281474976710656.0),
|
|
81 REAL_CONST(562949953421312.0), REAL_CONST(1125899906842624.0),
|
|
82 REAL_CONST(2251799813685248.0), REAL_CONST(4503599627370496.0),
|
|
83 REAL_CONST(9007199254740992.0), REAL_CONST(18014398509481984.0),
|
|
84 REAL_CONST(36028797018963968.0), REAL_CONST(72057594037927936.0),
|
|
85 REAL_CONST(144115188075855870.0), REAL_CONST(288230376151711740.0),
|
|
86 REAL_CONST(576460752303423490.0), REAL_CONST(1152921504606847000.0),
|
|
87 REAL_CONST(2305843009213694000.0), REAL_CONST(4611686018427387900.0),
|
|
88 REAL_CONST(9223372036854775800.0), REAL_CONST(1.8446744073709552E+019),
|
|
89 REAL_CONST(3.6893488147419103E+019), REAL_CONST(7.3786976294838206E+019),
|
|
90 REAL_CONST(1.4757395258967641E+020), REAL_CONST(2.9514790517935283E+020),
|
|
91 REAL_CONST(5.9029581035870565E+020), REAL_CONST(1.1805916207174113E+021),
|
|
92 REAL_CONST(2.3611832414348226E+021), REAL_CONST(4.7223664828696452E+021),
|
|
93 REAL_CONST(9.4447329657392904E+021), REAL_CONST(1.8889465931478581E+022),
|
|
94 REAL_CONST(3.7778931862957162E+022), REAL_CONST(7.5557863725914323E+022),
|
|
95 REAL_CONST(1.5111572745182865E+023), REAL_CONST(3.0223145490365729E+023),
|
|
96 REAL_CONST(6.0446290980731459E+023), REAL_CONST(1.2089258196146292E+024),
|
|
97 REAL_CONST(2.4178516392292583E+024), REAL_CONST(4.8357032784585167E+024),
|
|
98 REAL_CONST(9.6714065569170334E+024), REAL_CONST(1.9342813113834067E+025),
|
|
99 REAL_CONST(3.8685626227668134E+025), REAL_CONST(7.7371252455336267E+025),
|
|
100 REAL_CONST(1.5474250491067253E+026), REAL_CONST(3.0948500982134507E+026),
|
|
101 REAL_CONST(6.1897001964269014E+026), REAL_CONST(1.2379400392853803E+027),
|
|
102 REAL_CONST(2.4758800785707605E+027)
|
|
103 };
|
|
104
|
|
105 /* 1.0 / (1.0 + pow(2.0, x - 12) */
|
|
106 ALIGN static const real_t pow2deq_rcp[] = {
|
|
107 FRAC_CONST(0.99975591896509641),
|
|
108 FRAC_CONST(0.99951195705222062),
|
|
109 FRAC_CONST(0.99902439024390244),
|
|
110 FRAC_CONST(0.99805068226120852),
|
|
111 FRAC_CONST(0.99610894941634243),
|
|
112 FRAC_CONST(0.99224806201550386),
|
|
113 FRAC_CONST(0.98461538461538467),
|
|
114 FRAC_CONST(0.96969696969696972),
|
|
115 FRAC_CONST(0.94117647058823528),
|
|
116 FRAC_CONST(0.88888888888888884),
|
|
117 FRAC_CONST(0.80000000000000004),
|
|
118 FRAC_CONST(0.66666666666666663),
|
|
119 FRAC_CONST(0.5),
|
|
120 FRAC_CONST(0.33333333333333331),
|
|
121 FRAC_CONST(0.20000000000000001),
|
|
122 FRAC_CONST(0.1111111111111111),
|
|
123 FRAC_CONST(0.058823529411764705),
|
|
124 FRAC_CONST(0.030303030303030304),
|
|
125 FRAC_CONST(0.015384615384615385),
|
|
126 FRAC_CONST(0.0077519379844961239),
|
|
127 FRAC_CONST(0.0038910505836575876),
|
|
128 FRAC_CONST(0.0019493177387914229),
|
|
129 FRAC_CONST(0.00097560975609756097),
|
|
130 FRAC_CONST(0.0004880429477794046),
|
|
131 FRAC_CONST(0.00024408103490358799),
|
|
132 FRAC_CONST(0.00012205541315757354),
|
|
133 FRAC_CONST(6.1031431187061336E-005),
|
|
134 FRAC_CONST(3.0516646830846227E-005),
|
|
135 FRAC_CONST(1.5258556235409006E-005),
|
|
136 FRAC_CONST(7.6293363240331724E-006),
|
|
137 FRAC_CONST(3.8146827137652828E-006),
|
|
138 FRAC_CONST(1.9073449948406318E-006),
|
|
139 FRAC_CONST(9.5367340691241559E-007)
|
|
140 };
|
|
141
|
10725
|
142 void extract_envelope_data(sbr_info *sbr, uint8_t ch)
|
|
143 {
|
|
144 uint8_t l, k;
|
|
145
|
|
146 for (l = 0; l < sbr->L_E[ch]; l++)
|
|
147 {
|
|
148 if (sbr->bs_df_env[ch][l] == 0)
|
|
149 {
|
|
150 for (k = 1; k < sbr->n[sbr->f[ch][l]]; k++)
|
|
151 {
|
|
152 sbr->E[ch][k][l] = sbr->E[ch][k - 1][l] + sbr->E[ch][k][l];
|
|
153 }
|
|
154
|
|
155 } else { /* bs_df_env == 1 */
|
|
156
|
|
157 uint8_t g = (l == 0) ? sbr->f_prev[ch] : sbr->f[ch][l-1];
|
|
158 int16_t E_prev;
|
|
159
|
|
160 if (sbr->f[ch][l] == g)
|
|
161 {
|
|
162 for (k = 0; k < sbr->n[sbr->f[ch][l]]; k++)
|
|
163 {
|
|
164 if (l == 0)
|
|
165 E_prev = sbr->E_prev[ch][k];
|
|
166 else
|
|
167 E_prev = sbr->E[ch][k][l - 1];
|
|
168
|
|
169 sbr->E[ch][k][l] = E_prev + sbr->E[ch][k][l];
|
|
170 }
|
|
171
|
|
172 } else if ((g == 1) && (sbr->f[ch][l] == 0)) {
|
|
173 uint8_t i;
|
|
174
|
|
175 for (k = 0; k < sbr->n[sbr->f[ch][l]]; k++)
|
|
176 {
|
|
177 for (i = 0; i < sbr->N_high; i++)
|
|
178 {
|
|
179 if (sbr->f_table_res[HI_RES][i] == sbr->f_table_res[LO_RES][k])
|
|
180 {
|
|
181 if (l == 0)
|
|
182 E_prev = sbr->E_prev[ch][i];
|
|
183 else
|
|
184 E_prev = sbr->E[ch][i][l - 1];
|
|
185
|
|
186 sbr->E[ch][k][l] = E_prev + sbr->E[ch][k][l];
|
|
187 }
|
|
188 }
|
|
189 }
|
|
190
|
|
191 } else if ((g == 0) && (sbr->f[ch][l] == 1)) {
|
|
192 uint8_t i;
|
|
193
|
|
194 for (k = 0; k < sbr->n[sbr->f[ch][l]]; k++)
|
|
195 {
|
|
196 for (i = 0; i < sbr->N_low; i++)
|
|
197 {
|
|
198 if ((sbr->f_table_res[LO_RES][i] <= sbr->f_table_res[HI_RES][k]) &&
|
|
199 (sbr->f_table_res[HI_RES][k] < sbr->f_table_res[LO_RES][i + 1]))
|
|
200 {
|
|
201 if (l == 0)
|
|
202 E_prev = sbr->E_prev[ch][i];
|
|
203 else
|
|
204 E_prev = sbr->E[ch][i][l - 1];
|
|
205
|
|
206 sbr->E[ch][k][l] = E_prev + sbr->E[ch][k][l];
|
|
207 }
|
|
208 }
|
|
209 }
|
|
210 }
|
|
211 }
|
|
212 }
|
|
213 }
|
|
214
|
|
215 void extract_noise_floor_data(sbr_info *sbr, uint8_t ch)
|
|
216 {
|
|
217 uint8_t l, k;
|
|
218
|
|
219 for (l = 0; l < sbr->L_Q[ch]; l++)
|
|
220 {
|
|
221 if (sbr->bs_df_noise[ch][l] == 0)
|
|
222 {
|
|
223 for (k = 1; k < sbr->N_Q; k++)
|
|
224 {
|
|
225 sbr->Q[ch][k][l] = sbr->Q[ch][k][l] + sbr->Q[ch][k-1][l];
|
|
226 }
|
|
227 } else {
|
|
228 if (l == 0)
|
|
229 {
|
|
230 for (k = 0; k < sbr->N_Q; k++)
|
|
231 {
|
|
232 sbr->Q[ch][k][l] = sbr->Q_prev[ch][k] + sbr->Q[ch][k][0];
|
|
233 }
|
|
234 } else {
|
|
235 for (k = 0; k < sbr->N_Q; k++)
|
|
236 {
|
|
237 sbr->Q[ch][k][l] = sbr->Q[ch][k][l - 1] + sbr->Q[ch][k][l];
|
|
238 }
|
|
239 }
|
|
240 }
|
|
241 }
|
|
242 }
|
|
243
|
|
244 void envelope_noise_dequantisation(sbr_info *sbr, uint8_t ch)
|
|
245 {
|
|
246 if (sbr->bs_coupling == 0)
|
|
247 {
|
12527
|
248 int16_t exp;
|
10725
|
249 uint8_t l, k;
|
12527
|
250 uint8_t amp = (sbr->amp_res[ch]) ? 0 : 1;
|
10725
|
251
|
|
252 for (l = 0; l < sbr->L_E[ch]; l++)
|
|
253 {
|
|
254 for (k = 0; k < sbr->n[sbr->f[ch][l]]; k++)
|
|
255 {
|
12527
|
256 /* +6 for the *64 and -10 for the /32 in the synthesis QMF
|
|
257 * since this is a energy value: (x/32)^2 = (x^2)/1024
|
|
258 */
|
|
259 exp = (sbr->E[ch][k][l] >> amp) + 6;
|
|
260
|
|
261 if ((exp < -P2_TABLE_OFFSET) || (exp > P2_TABLE_MAX))
|
|
262 {
|
|
263 sbr->E_orig[ch][k][l] = 0;
|
|
264 } else {
|
|
265 /* FIXED POINT TODO: E_orig: INTEGER!! */
|
|
266 sbr->E_orig[ch][k][l] = pow2deq[exp + P2_TABLE_OFFSET];
|
|
267
|
|
268 /* save half the table size at the cost of 1 multiply */
|
|
269 if (amp && (sbr->E[ch][k][l] & 1))
|
|
270 {
|
|
271 sbr->E_orig[ch][k][l] = MUL_R(sbr->E_orig[ch][k][l], REAL_CONST(1.414213562));
|
|
272 }
|
|
273 }
|
10725
|
274 }
|
|
275 }
|
|
276
|
|
277 for (l = 0; l < sbr->L_Q[ch]; l++)
|
|
278 {
|
|
279 for (k = 0; k < sbr->N_Q; k++)
|
|
280 {
|
|
281 if (sbr->Q[ch][k][l] < 0 || sbr->Q[ch][k][l] > 30)
|
12527
|
282 {
|
10725
|
283 sbr->Q_orig[ch][k][l] = 0;
|
12527
|
284 } else {
|
|
285 exp = NOISE_FLOOR_OFFSET - sbr->Q[ch][k][l];
|
|
286 sbr->Q_orig[ch][k][l] = pow2deq[exp + P2_TABLE_OFFSET];
|
10725
|
287 }
|
|
288 }
|
|
289 }
|
|
290 }
|
|
291 }
|
|
292
|
|
293 void unmap_envelope_noise(sbr_info *sbr)
|
|
294 {
|
12527
|
295 real_t tmp;
|
|
296 int16_t exp0, exp1;
|
10725
|
297 uint8_t l, k;
|
12527
|
298 uint8_t amp0 = (sbr->amp_res[0]) ? 0 : 1;
|
|
299 uint8_t amp1 = (sbr->amp_res[1]) ? 0 : 1;
|
10725
|
300
|
|
301 for (l = 0; l < sbr->L_E[0]; l++)
|
|
302 {
|
|
303 for (k = 0; k < sbr->n[sbr->f[0][l]]; k++)
|
|
304 {
|
12527
|
305 /* +6: * 64 ; +1: * 2 ; -10: /1024 QMF */
|
|
306 exp0 = (sbr->E[0][k][l] >> amp0) + 7;
|
10725
|
307
|
|
308 /* UN_MAP removed: (x / 4096) same as (x >> 12) */
|
12527
|
309 /* E[1] is always even so no need for compensating the divide by 2 with
|
|
310 * an extra multiplication
|
|
311 */
|
|
312 exp1 = (sbr->E[1][k][l] >> amp1) - 12;
|
10725
|
313
|
12527
|
314 if ((exp0 < -P2_TABLE_OFFSET) || (exp0 > P2_TABLE_MAX) ||
|
|
315 (exp1 < -P2_TABLE_RCP_OFFSET) || (exp1 > P2_TABLE_RCP_MAX))
|
|
316 {
|
|
317 sbr->E_orig[1][k][l] = 0;
|
|
318 sbr->E_orig[0][k][l] = 0;
|
|
319 } else {
|
|
320 tmp = pow2deq[exp0 + P2_TABLE_OFFSET];
|
|
321 if (amp0 && (sbr->E[0][k][l] & 1))
|
|
322 tmp = MUL_R(tmp, REAL_CONST(1.414213562));
|
|
323
|
|
324 /* FIXED POINT TODO: E_orig: INTEGER!! */
|
|
325 sbr->E_orig[1][k][l] = MUL_F(tmp, pow2deq_rcp[exp1 + P2_TABLE_RCP_OFFSET]);
|
|
326 sbr->E_orig[0][k][l] = MUL_R(sbr->E_orig[1][k][l], pow2deq[exp1 + P2_TABLE_OFFSET]);
|
|
327 }
|
10725
|
328 }
|
|
329 }
|
|
330 for (l = 0; l < sbr->L_Q[0]; l++)
|
|
331 {
|
|
332 for (k = 0; k < sbr->N_Q; k++)
|
|
333 {
|
|
334 if ((sbr->Q[0][k][l] < 0 || sbr->Q[0][k][l] > 30) ||
|
12527
|
335 (sbr->Q[1][k][l] < 0 || sbr->Q[1][k][l] > 24 /* 2*panOffset(1) */))
|
10725
|
336 {
|
|
337 sbr->Q_orig[0][k][l] = 0;
|
|
338 sbr->Q_orig[1][k][l] = 0;
|
|
339 } else {
|
12527
|
340 exp0 = NOISE_FLOOR_OFFSET - sbr->Q[0][k][l] + 1;
|
|
341 exp1 = sbr->Q[1][k][l] - 12;
|
10725
|
342
|
12527
|
343 sbr->Q_orig[1][k][l] = MUL_F(pow2deq[exp0 + P2_TABLE_OFFSET], pow2deq_rcp[exp1 + P2_TABLE_RCP_OFFSET]);
|
|
344 sbr->Q_orig[0][k][l] = MUL_R(sbr->Q_orig[1][k][l], pow2deq[exp1 + P2_TABLE_OFFSET]);
|
10725
|
345 }
|
|
346 }
|
|
347 }
|
|
348 }
|
|
349
|
|
350 #endif
|