summaryrefslogtreecommitdiff
path: root/apps/codecs/libfaad/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/libfaad/common.c')
-rw-r--r--apps/codecs/libfaad/common.c133
1 files changed, 51 insertions, 82 deletions
diff --git a/apps/codecs/libfaad/common.c b/apps/codecs/libfaad/common.c
index c838c88d33..0e49896908 100644
--- a/apps/codecs/libfaad/common.c
+++ b/apps/codecs/libfaad/common.c
@@ -248,78 +248,33 @@ uint32_t random_int(void)
248#define TABLE_BITS 6 248#define TABLE_BITS 6
249/* just take the maximum number of bits for interpolation */ 249/* just take the maximum number of bits for interpolation */
250#define INTERP_BITS (REAL_BITS-TABLE_BITS) 250#define INTERP_BITS (REAL_BITS-TABLE_BITS)
251/* precision of values in pow2_tab */ 251
252#define POWTBL_BITS (31-(INTERP_BITS)) 252static const real_t pow2_tab[] = {
253#define POWTBL_PRECIS (1U<<(POWTBL_BITS)) 253 REAL_CONST(1.000000000000000), REAL_CONST(1.010889286051701), REAL_CONST(1.021897148654117),
254static const uint32_t pow2_tab[] ICONST_ATTR = { 254 REAL_CONST(1.033024879021228), REAL_CONST(1.044273782427414), REAL_CONST(1.055645178360557),
255 UFIX_CONST(1.000000000000000,POWTBL_PRECIS), 255 REAL_CONST(1.067140400676824), REAL_CONST(1.078760797757120), REAL_CONST(1.090507732665258),
256 UFIX_CONST(1.010889286051701,POWTBL_PRECIS), 256 REAL_CONST(1.102382583307841), REAL_CONST(1.114386742595892), REAL_CONST(1.126521618608242),
257 UFIX_CONST(1.021897148654117,POWTBL_PRECIS), 257 REAL_CONST(1.138788634756692), REAL_CONST(1.151189229952983), REAL_CONST(1.163724858777578),
258 UFIX_CONST(1.033024879021228,POWTBL_PRECIS), 258 REAL_CONST(1.176396991650281), REAL_CONST(1.189207115002721), REAL_CONST(1.202156731452703),
259 UFIX_CONST(1.044273782427414,POWTBL_PRECIS), 259 REAL_CONST(1.215247359980469), REAL_CONST(1.228480536106870), REAL_CONST(1.241857812073484),
260 UFIX_CONST(1.055645178360557,POWTBL_PRECIS), 260 REAL_CONST(1.255380757024691), REAL_CONST(1.269050957191733), REAL_CONST(1.282870016078778),
261 UFIX_CONST(1.067140400676824,POWTBL_PRECIS), 261 REAL_CONST(1.296839554651010), REAL_CONST(1.310961211524764), REAL_CONST(1.325236643159741),
262 UFIX_CONST(1.078760797757120,POWTBL_PRECIS), 262 REAL_CONST(1.339667524053303), REAL_CONST(1.354255546936893), REAL_CONST(1.369002422974591),
263 UFIX_CONST(1.090507732665258,POWTBL_PRECIS), 263 REAL_CONST(1.383909881963832), REAL_CONST(1.398979672538311), REAL_CONST(1.414213562373095),
264 UFIX_CONST(1.102382583307841,POWTBL_PRECIS), 264 REAL_CONST(1.429613338391970), REAL_CONST(1.445180806977047), REAL_CONST(1.460917794180647),
265 UFIX_CONST(1.114386742595892,POWTBL_PRECIS), 265 REAL_CONST(1.476826145939499), REAL_CONST(1.492907728291265), REAL_CONST(1.509164427593423),
266 UFIX_CONST(1.126521618608242,POWTBL_PRECIS), 266 REAL_CONST(1.525598150744538), REAL_CONST(1.542210825407941), REAL_CONST(1.559004400237837),
267 UFIX_CONST(1.138788634756692,POWTBL_PRECIS), 267 REAL_CONST(1.575980845107887), REAL_CONST(1.593142151342267), REAL_CONST(1.610490331949254),
268 UFIX_CONST(1.151189229952983,POWTBL_PRECIS), 268 REAL_CONST(1.628027421857348), REAL_CONST(1.645755478153965), REAL_CONST(1.663676580326736),
269 UFIX_CONST(1.163724858777578,POWTBL_PRECIS), 269 REAL_CONST(1.681792830507429), REAL_CONST(1.700106353718524), REAL_CONST(1.718619298122478),
270 UFIX_CONST(1.176396991650281,POWTBL_PRECIS), 270 REAL_CONST(1.737333835273706), REAL_CONST(1.756252160373300), REAL_CONST(1.775376492526521),
271 UFIX_CONST(1.189207115002721,POWTBL_PRECIS), 271 REAL_CONST(1.794709075003107), REAL_CONST(1.814252175500399), REAL_CONST(1.834008086409342),
272 UFIX_CONST(1.202156731452703,POWTBL_PRECIS), 272 REAL_CONST(1.853979125083386), REAL_CONST(1.874167634110300), REAL_CONST(1.894575981586966),
273 UFIX_CONST(1.215247359980469,POWTBL_PRECIS), 273 REAL_CONST(1.915206561397147), REAL_CONST(1.936061793492294), REAL_CONST(1.957144124175400),
274 UFIX_CONST(1.228480536106870,POWTBL_PRECIS), 274 REAL_CONST(1.978456026387951), REAL_CONST(2.000000000000000)
275 UFIX_CONST(1.241857812073484,POWTBL_PRECIS),
276 UFIX_CONST(1.255380757024691,POWTBL_PRECIS),
277 UFIX_CONST(1.269050957191733,POWTBL_PRECIS),
278 UFIX_CONST(1.282870016078778,POWTBL_PRECIS),
279 UFIX_CONST(1.296839554651010,POWTBL_PRECIS),
280 UFIX_CONST(1.310961211524764,POWTBL_PRECIS),
281 UFIX_CONST(1.325236643159741,POWTBL_PRECIS),
282 UFIX_CONST(1.339667524053303,POWTBL_PRECIS),
283 UFIX_CONST(1.354255546936893,POWTBL_PRECIS),
284 UFIX_CONST(1.369002422974591,POWTBL_PRECIS),
285 UFIX_CONST(1.383909881963832,POWTBL_PRECIS),
286 UFIX_CONST(1.398979672538311,POWTBL_PRECIS),
287 UFIX_CONST(1.414213562373095,POWTBL_PRECIS),
288 UFIX_CONST(1.429613338391970,POWTBL_PRECIS),
289 UFIX_CONST(1.445180806977047,POWTBL_PRECIS),
290 UFIX_CONST(1.460917794180647,POWTBL_PRECIS),
291 UFIX_CONST(1.476826145939499,POWTBL_PRECIS),
292 UFIX_CONST(1.492907728291265,POWTBL_PRECIS),
293 UFIX_CONST(1.509164427593423,POWTBL_PRECIS),
294 UFIX_CONST(1.525598150744538,POWTBL_PRECIS),
295 UFIX_CONST(1.542210825407941,POWTBL_PRECIS),
296 UFIX_CONST(1.559004400237837,POWTBL_PRECIS),
297 UFIX_CONST(1.575980845107887,POWTBL_PRECIS),
298 UFIX_CONST(1.593142151342267,POWTBL_PRECIS),
299 UFIX_CONST(1.610490331949254,POWTBL_PRECIS),
300 UFIX_CONST(1.628027421857348,POWTBL_PRECIS),
301 UFIX_CONST(1.645755478153965,POWTBL_PRECIS),
302 UFIX_CONST(1.663676580326736,POWTBL_PRECIS),
303 UFIX_CONST(1.681792830507429,POWTBL_PRECIS),
304 UFIX_CONST(1.700106353718524,POWTBL_PRECIS),
305 UFIX_CONST(1.718619298122478,POWTBL_PRECIS),
306 UFIX_CONST(1.737333835273706,POWTBL_PRECIS),
307 UFIX_CONST(1.756252160373300,POWTBL_PRECIS),
308 UFIX_CONST(1.775376492526521,POWTBL_PRECIS),
309 UFIX_CONST(1.794709075003107,POWTBL_PRECIS),
310 UFIX_CONST(1.814252175500399,POWTBL_PRECIS),
311 UFIX_CONST(1.834008086409342,POWTBL_PRECIS),
312 UFIX_CONST(1.853979125083386,POWTBL_PRECIS),
313 UFIX_CONST(1.874167634110300,POWTBL_PRECIS),
314 UFIX_CONST(1.894575981586966,POWTBL_PRECIS),
315 UFIX_CONST(1.915206561397147,POWTBL_PRECIS),
316 UFIX_CONST(1.936061793492294,POWTBL_PRECIS),
317 UFIX_CONST(1.957144124175400,POWTBL_PRECIS),
318 UFIX_CONST(1.978456026387951,POWTBL_PRECIS),
319 UFIX_CONST(2.000000000000000,POWTBL_PRECIS)
320}; 275};
321 276
322static const real_t log2_tab[] ICONST_ATTR_FAAD_LARGE_IRAM = { 277static const real_t log2_tab[] = {
323 REAL_CONST(0.000000000000000), REAL_CONST(0.022367813028455), REAL_CONST(0.044394119358453), 278 REAL_CONST(0.000000000000000), REAL_CONST(0.022367813028455), REAL_CONST(0.044394119358453),
324 REAL_CONST(0.066089190457772), REAL_CONST(0.087462841250339), REAL_CONST(0.108524456778169), 279 REAL_CONST(0.066089190457772), REAL_CONST(0.087462841250339), REAL_CONST(0.108524456778169),
325 REAL_CONST(0.129283016944966), REAL_CONST(0.149747119504682), REAL_CONST(0.169925001442312), 280 REAL_CONST(0.129283016944966), REAL_CONST(0.149747119504682), REAL_CONST(0.169925001442312),
@@ -356,19 +311,26 @@ uint32_t pow2_fix(real_t val)
356 int32_t rest = val - (whole << REAL_BITS); 311 int32_t rest = val - (whole << REAL_BITS);
357 312
358 /* index into pow2_tab */ 313 /* index into pow2_tab */
359 int32_t index = rest >> (REAL_BITS-TABLE_BITS); 314 int32_t index = (rest >> (REAL_BITS-TABLE_BITS)) & ((1<<TABLE_BITS)-1);
315
316
317 if (val == 0)
318 return (1<<REAL_BITS);
360 319
361 /* leave INTERP_BITS bits */ 320 /* leave INTERP_BITS bits */
362 index_frac = rest >> (REAL_BITS-TABLE_BITS-INTERP_BITS); 321 index_frac = rest >> (REAL_BITS-TABLE_BITS-INTERP_BITS);
363 index_frac = index_frac & ((1<<INTERP_BITS)-1); 322 index_frac = index_frac & ((1<<INTERP_BITS)-1);
364 323
365 x1 = pow2_tab[index & ((1<<TABLE_BITS)-1)]; 324 if (whole >= 0)
366 x2 = pow2_tab[(index & ((1<<TABLE_BITS)-1)) + 1]; 325 retval = REAL_CONST(1) << whole;
367 errcorr = ( (index_frac*(x2-x1))); 326 else
327 retval = REAL_CONST(1) >> -whole;
368 328
369 retval = errcorr + (x1<<INTERP_BITS); 329 x1 = pow2_tab[index ];
330 x2 = pow2_tab[index + 1];
331 errcorr = (index_frac*(x2-x1)) >> INTERP_BITS;
370 332
371 retval = DESCALE_SHIFT(retval, whole, POWTBL_BITS + INTERP_BITS - REAL_BITS); 333 retval = MUL_R(retval, (errcorr + x1));
372 334
373 return retval; 335 return retval;
374} 336}
@@ -385,19 +347,26 @@ uint32_t pow2_int(real_t val)
385 int32_t rest = val - (whole << REAL_BITS); 347 int32_t rest = val - (whole << REAL_BITS);
386 348
387 /* index into pow2_tab */ 349 /* index into pow2_tab */
388 int32_t index = rest >> (REAL_BITS-TABLE_BITS); 350 int32_t index = (rest >> (REAL_BITS-TABLE_BITS)) & ((1<<TABLE_BITS)-1);
351
352
353 if (val == 0)
354 return 1;
389 355
390 /* leave INTERP_BITS bits */ 356 /* leave INTERP_BITS bits */
391 index_frac = rest >> (REAL_BITS-TABLE_BITS-INTERP_BITS); 357 index_frac = rest >> (REAL_BITS-TABLE_BITS-INTERP_BITS);
392 index_frac = index_frac & ((1<<INTERP_BITS)-1); 358 index_frac = index_frac & ((1<<INTERP_BITS)-1);
393 359
394 x1 = pow2_tab[index & ((1<<TABLE_BITS)-1)]; 360 if (whole >= 0)
395 x2 = pow2_tab[(index & ((1<<TABLE_BITS)-1)) + 1]; 361 retval = 1 << whole;
396 errcorr = ( (index_frac*(x2-x1))); 362 else
363 retval = 1 >> -whole;
397 364
398 retval = errcorr + (x1<<INTERP_BITS); 365 x1 = pow2_tab[index ];
366 x2 = pow2_tab[index + 1];
367 errcorr = (index_frac*(x2-x1)) >> INTERP_BITS;
399 368
400 retval = DESCALE_SHIFT(retval, whole, POWTBL_BITS + INTERP_BITS); 369 retval = MUL_R(retval, (errcorr + x1));
401 370
402 return retval; 371 return retval;
403} 372}