FreeCalypso > hg > gsm-codec-lib
changeset 337:190c4c9a3693
libtwamr: integrate pow2.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 18 Apr 2024 23:06:59 +0000 |
parents | 7f99b8ed30e5 |
children | 5db2c920fc23 |
files | libtwamr/Makefile libtwamr/pow2.c libtwamr/pow2.h libtwamr/pow2.tab |
diffstat | 4 files changed, 146 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libtwamr/Makefile Thu Apr 18 23:02:35 2024 +0000 +++ b/libtwamr/Makefile Thu Apr 18 23:06:59 2024 +0000 @@ -4,8 +4,8 @@ bitno.o bits2prm.o c1035pf.o c2_11pf.o c2_9pf.o c3_14pf.o c4_17pf.o \ c8_31pf.o c_g_aver.o calc_cor.o calc_en.o cbsearch.o convolve.o cor_h.o\ d1035pf.o d2_11pf.o d2_9pf.o d3_14pf.o d4_17pf.o d8_31pf.o gc_pred.o \ - gmed_n.o graytab.o inv_sqrt.o log2.o oper_32b.o prmno.o s10_8pf.o \ - set_sign.o sqrt_l.o tls_flags.o window.o + gmed_n.o graytab.o inv_sqrt.o log2.o oper_32b.o pow2.o prmno.o \ + s10_8pf.o set_sign.o sqrt_l.o tls_flags.o window.o LIB= libtwamr.a INSTALL_PREFIX= /usr/local
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtwamr/pow2.c Thu Apr 18 23:06:59 2024 +0000 @@ -0,0 +1,81 @@ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 +* R99 Version 3.3.0 +* REL-4 Version 4.1.0 +* +******************************************************************************** +* +* File : pow2.c +* Purpose : computes L_x = pow(2.0, exponent.fraction) +* +******************************************************************************** +*/ +/* +******************************************************************************** +* MODULE INCLUDE FILE AND VERSION ID +******************************************************************************** +*/ +#include "namespace.h" +#include "pow2.h" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" +#include "basic_op.h" +#include "no_count.h" + +/* +******************************************************************************** +* LOCAL VARIABLES AND TABLES +******************************************************************************** +*/ +#include "pow2.tab" /* Table for Pow2() */ + +/* +******************************************************************************** +* PUBLIC PROGRAM CODE +******************************************************************************** +*/ +/************************************************************************* + * + * FUNCTION: Pow2() + * + * PURPOSE: computes L_x = pow(2.0, exponent.fraction) + * + * DESCRIPTION: + * The function Pow2(L_x) is approximated by a table and linear + * interpolation. + * 1- i = bit10-b15 of fraction, 0 <= i <= 31 + * 2- a = bit0-b9 of fraction + * 3- L_x = table[i]<<16 - (table[i] - table[i+1]) * a * 2 + * 4- L_x = L_x >> (30-exponent) (with rounding) + * + *************************************************************************/ +Word32 Pow2 ( /* (o) : result (range: 0<=val<=0x7fffffff) */ + Word16 exponent, /* (i) : Integer part. (range: 0<=val<=30) */ + Word16 fraction /* (i) : Fractional part. (range: 0.0<=val<1.0) */ +) +{ + Word16 exp, i, a, tmp; + Word32 L_x; + + L_x = L_mult (fraction, 32);/* L_x = fraction<<6 */ + i = extract_h (L_x); /* Extract b10-b16 of fraction */ + L_x = L_shr (L_x, 1); + a = extract_l (L_x); /* Extract b0-b9 of fraction */ + a = a & (Word16) 0x7fff; logic16 (); + + L_x = L_deposit_h (table[i]); /* table[i] << 16 */ + tmp = sub (table[i], table[i + 1]); /* table[i] - table[i+1] */ + L_x = L_msu (L_x, tmp, a); /* L_x -= tmp*a*2 */ + + exp = sub (30, exponent); + L_x = L_shr_r (L_x, exp); + + return (L_x); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtwamr/pow2.h Thu Apr 18 23:06:59 2024 +0000 @@ -0,0 +1,41 @@ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 +* R99 Version 3.3.0 +* REL-4 Version 4.1.0 +* +******************************************************************************** +* +* File : pow2.h +* Purpose : computes L_x = pow(2.0, exponent.fraction) +* +******************************************************************************** +*/ +#ifndef pow2_h +#define pow2_h "$Id $" + +/* +******************************************************************************** +* INCLUDE FILES +******************************************************************************** +*/ +#include "typedef.h" + +/* +******************************************************************************** +* DEFINITION OF DATA TYPES +******************************************************************************** +*/ + +/* +******************************************************************************** +* DECLARATION OF PROTOTYPES +******************************************************************************** +*/ +Word32 Pow2 ( /* (o) : result (range: 0<=val<=0x7fffffff) */ + Word16 exponent, /* (i) : Integer part. (range: 0<=val<=30) */ + Word16 fraction /* (i) : Fractional part. (range: 0.0<=val<1.0) */ +); + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libtwamr/pow2.tab Thu Apr 18 23:06:59 2024 +0000 @@ -0,0 +1,22 @@ +/* +******************************************************************************** +* +* GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 +* R99 Version 3.3.0 +* REL-4 Version 4.1.0 +* +******************************************************************************** +* +* File : pow2.tab +* Purpose : Table for routine Pow2(). +* $Id $ +* +******************************************************************************** +*/ +static const Word16 table[33] = +{ + 16384, 16743, 17109, 17484, 17867, 18258, 18658, 19066, 19484, 19911, + 20347, 20792, 21247, 21713, 22188, 22674, 23170, 23678, 24196, 24726, + 25268, 25821, 26386, 26964, 27554, 28158, 28774, 29405, 30048, 30706, + 31379, 32066, 32767 +};