Mercurial > mplayer.hg
comparison libfaad2/sbr_e_nf.c @ 12527:4a370c80fe5c
update to the 2.0 release of faad, patch by adland
author | diego |
---|---|
date | Wed, 02 Jun 2004 22:59:04 +0000 |
parents | 3185f64f6350 |
children | d81145997036 |
comparison
equal
deleted
inserted
replaced
12526:e183ad37d24c | 12527:4a370c80fe5c |
---|---|
1 /* | 1 /* |
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding | 2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding |
3 ** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com | 3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com |
4 ** | 4 ** |
5 ** This program is free software; you can redistribute it and/or modify | 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 | 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 | 7 ** the Free Software Foundation; either version 2 of the License, or |
8 ** (at your option) any later version. | 8 ** (at your option) any later version. |
20 ** forbidden. | 20 ** forbidden. |
21 ** | 21 ** |
22 ** Commercial non-GPL licensing of this software is possible. | 22 ** Commercial non-GPL licensing of this software is possible. |
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. | 23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. |
24 ** | 24 ** |
25 ** $Id: sbr_e_nf.c,v 1.4 2003/09/09 18:37:32 menno Exp $ | 25 ** $Id: sbr_e_nf.c,v 1.2 2003/10/03 22:22:27 alex Exp $ |
26 **/ | 26 **/ |
27 | 27 |
28 #include "common.h" | 28 #include "common.h" |
29 #include "structs.h" | 29 #include "structs.h" |
30 | 30 |
32 | 32 |
33 #include <stdlib.h> | 33 #include <stdlib.h> |
34 | 34 |
35 #include "sbr_syntax.h" | 35 #include "sbr_syntax.h" |
36 #include "sbr_e_nf.h" | 36 #include "sbr_e_nf.h" |
37 | |
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 }; | |
37 | 141 |
38 void extract_envelope_data(sbr_info *sbr, uint8_t ch) | 142 void extract_envelope_data(sbr_info *sbr, uint8_t ch) |
39 { | 143 { |
40 uint8_t l, k; | 144 uint8_t l, k; |
41 | 145 |
135 } | 239 } |
136 } | 240 } |
137 } | 241 } |
138 } | 242 } |
139 | 243 |
140 /* FIXME: pow() not needed */ | |
141 void envelope_noise_dequantisation(sbr_info *sbr, uint8_t ch) | 244 void envelope_noise_dequantisation(sbr_info *sbr, uint8_t ch) |
142 { | 245 { |
143 if (sbr->bs_coupling == 0) | 246 if (sbr->bs_coupling == 0) |
144 { | 247 { |
248 int16_t exp; | |
145 uint8_t l, k; | 249 uint8_t l, k; |
146 real_t amp = (sbr->amp_res[ch]) ? 1.0f : 0.5f; | 250 uint8_t amp = (sbr->amp_res[ch]) ? 0 : 1; |
147 | 251 |
148 for (l = 0; l < sbr->L_E[ch]; l++) | 252 for (l = 0; l < sbr->L_E[ch]; l++) |
149 { | 253 { |
150 for (k = 0; k < sbr->n[sbr->f[ch][l]]; k++) | 254 for (k = 0; k < sbr->n[sbr->f[ch][l]]; k++) |
151 { | 255 { |
152 /* +6 for the *64 */ | 256 /* +6 for the *64 and -10 for the /32 in the synthesis QMF |
153 sbr->E_orig[ch][k][l] = (real_t)pow(2, sbr->E[ch][k][l]*amp + 6); | 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 } | |
154 } | 274 } |
155 } | 275 } |
156 | 276 |
157 for (l = 0; l < sbr->L_Q[ch]; l++) | 277 for (l = 0; l < sbr->L_Q[ch]; l++) |
158 { | 278 { |
159 for (k = 0; k < sbr->N_Q; k++) | 279 for (k = 0; k < sbr->N_Q; k++) |
160 { | 280 { |
161 if (sbr->Q[ch][k][l] < 0 || sbr->Q[ch][k][l] > 30) | 281 if (sbr->Q[ch][k][l] < 0 || sbr->Q[ch][k][l] > 30) |
282 { | |
162 sbr->Q_orig[ch][k][l] = 0; | 283 sbr->Q_orig[ch][k][l] = 0; |
163 else { | 284 } else { |
164 sbr->Q_orig[ch][k][l] = (real_t)pow(2, NOISE_FLOOR_OFFSET - sbr->Q[ch][k][l]); | 285 exp = NOISE_FLOOR_OFFSET - sbr->Q[ch][k][l]; |
286 sbr->Q_orig[ch][k][l] = pow2deq[exp + P2_TABLE_OFFSET]; | |
165 } | 287 } |
166 } | 288 } |
167 } | 289 } |
168 } | 290 } |
169 } | 291 } |
170 | 292 |
171 void unmap_envelope_noise(sbr_info *sbr) | 293 void unmap_envelope_noise(sbr_info *sbr) |
172 { | 294 { |
295 real_t tmp; | |
296 int16_t exp0, exp1; | |
173 uint8_t l, k; | 297 uint8_t l, k; |
174 real_t amp0 = (sbr->amp_res[0]) ? (real_t)1.0 : (real_t)0.5; | 298 uint8_t amp0 = (sbr->amp_res[0]) ? 0 : 1; |
175 real_t amp1 = (sbr->amp_res[1]) ? (real_t)1.0 : (real_t)0.5; | 299 uint8_t amp1 = (sbr->amp_res[1]) ? 0 : 1; |
176 | 300 |
177 for (l = 0; l < sbr->L_E[0]; l++) | 301 for (l = 0; l < sbr->L_E[0]; l++) |
178 { | 302 { |
179 for (k = 0; k < sbr->n[sbr->f[0][l]]; k++) | 303 for (k = 0; k < sbr->n[sbr->f[0][l]]; k++) |
180 { | 304 { |
181 real_t l_temp, r_temp; | 305 /* +6: * 64 ; +1: * 2 ; -10: /1024 QMF */ |
182 | 306 exp0 = (sbr->E[0][k][l] >> amp0) + 7; |
183 /* +6: * 64 ; +1: * 2 */ | 307 |
184 l_temp = (real_t)pow(2, sbr->E[0][k][l]*amp0 + 7); | |
185 /* UN_MAP removed: (x / 4096) same as (x >> 12) */ | 308 /* UN_MAP removed: (x / 4096) same as (x >> 12) */ |
186 r_temp = (real_t)pow(2, sbr->E[1][k][l]*amp1 - 12); | 309 /* E[1] is always even so no need for compensating the divide by 2 with |
187 | 310 * an extra multiplication |
188 sbr->E_orig[1][k][l] = l_temp / ((real_t)1.0 + r_temp); | 311 */ |
189 sbr->E_orig[0][k][l] = MUL(r_temp, sbr->E_orig[1][k][l]); | 312 exp1 = (sbr->E[1][k][l] >> amp1) - 12; |
313 | |
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 } | |
190 } | 328 } |
191 } | 329 } |
192 for (l = 0; l < sbr->L_Q[0]; l++) | 330 for (l = 0; l < sbr->L_Q[0]; l++) |
193 { | 331 { |
194 for (k = 0; k < sbr->N_Q; k++) | 332 for (k = 0; k < sbr->N_Q; k++) |
195 { | 333 { |
196 if ((sbr->Q[0][k][l] < 0 || sbr->Q[0][k][l] > 30) || | 334 if ((sbr->Q[0][k][l] < 0 || sbr->Q[0][k][l] > 30) || |
197 (sbr->Q[1][k][l] < 0 || sbr->Q[1][k][l] > 30)) | 335 (sbr->Q[1][k][l] < 0 || sbr->Q[1][k][l] > 24 /* 2*panOffset(1) */)) |
198 { | 336 { |
199 sbr->Q_orig[0][k][l] = 0; | 337 sbr->Q_orig[0][k][l] = 0; |
200 sbr->Q_orig[1][k][l] = 0; | 338 sbr->Q_orig[1][k][l] = 0; |
201 } else { | 339 } else { |
202 real_t l_temp, r_temp; | 340 exp0 = NOISE_FLOOR_OFFSET - sbr->Q[0][k][l] + 1; |
203 | 341 exp1 = sbr->Q[1][k][l] - 12; |
204 l_temp = (real_t)pow(2.0, NOISE_FLOOR_OFFSET - sbr->Q[0][k][l] + 1); | 342 |
205 r_temp = (real_t)pow(2.0, sbr->Q[1][k][l] - 12); | 343 sbr->Q_orig[1][k][l] = MUL_F(pow2deq[exp0 + P2_TABLE_OFFSET], pow2deq_rcp[exp1 + P2_TABLE_RCP_OFFSET]); |
206 | 344 sbr->Q_orig[0][k][l] = MUL_R(sbr->Q_orig[1][k][l], pow2deq[exp1 + P2_TABLE_OFFSET]); |
207 sbr->Q_orig[1][k][l] = l_temp / ((real_t)1.0 + r_temp); | |
208 sbr->Q_orig[0][k][l] = MUL(r_temp, sbr->Q_orig[1][k][l]); | |
209 } | 345 } |
210 } | 346 } |
211 } | 347 } |
212 } | 348 } |
213 | 349 |