FreeCalypso > hg > gsm-codec-lib
comparison libtwamr/pow2.c @ 337:190c4c9a3693
libtwamr: integrate pow2.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 18 Apr 2024 23:06:59 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
336:7f99b8ed30e5 | 337:190c4c9a3693 |
---|---|
1 /* | |
2 ******************************************************************************** | |
3 * | |
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 | |
5 * R99 Version 3.3.0 | |
6 * REL-4 Version 4.1.0 | |
7 * | |
8 ******************************************************************************** | |
9 * | |
10 * File : pow2.c | |
11 * Purpose : computes L_x = pow(2.0, exponent.fraction) | |
12 * | |
13 ******************************************************************************** | |
14 */ | |
15 /* | |
16 ******************************************************************************** | |
17 * MODULE INCLUDE FILE AND VERSION ID | |
18 ******************************************************************************** | |
19 */ | |
20 #include "namespace.h" | |
21 #include "pow2.h" | |
22 | |
23 /* | |
24 ******************************************************************************** | |
25 * INCLUDE FILES | |
26 ******************************************************************************** | |
27 */ | |
28 #include "typedef.h" | |
29 #include "basic_op.h" | |
30 #include "no_count.h" | |
31 | |
32 /* | |
33 ******************************************************************************** | |
34 * LOCAL VARIABLES AND TABLES | |
35 ******************************************************************************** | |
36 */ | |
37 #include "pow2.tab" /* Table for Pow2() */ | |
38 | |
39 /* | |
40 ******************************************************************************** | |
41 * PUBLIC PROGRAM CODE | |
42 ******************************************************************************** | |
43 */ | |
44 /************************************************************************* | |
45 * | |
46 * FUNCTION: Pow2() | |
47 * | |
48 * PURPOSE: computes L_x = pow(2.0, exponent.fraction) | |
49 * | |
50 * DESCRIPTION: | |
51 * The function Pow2(L_x) is approximated by a table and linear | |
52 * interpolation. | |
53 * 1- i = bit10-b15 of fraction, 0 <= i <= 31 | |
54 * 2- a = bit0-b9 of fraction | |
55 * 3- L_x = table[i]<<16 - (table[i] - table[i+1]) * a * 2 | |
56 * 4- L_x = L_x >> (30-exponent) (with rounding) | |
57 * | |
58 *************************************************************************/ | |
59 Word32 Pow2 ( /* (o) : result (range: 0<=val<=0x7fffffff) */ | |
60 Word16 exponent, /* (i) : Integer part. (range: 0<=val<=30) */ | |
61 Word16 fraction /* (i) : Fractional part. (range: 0.0<=val<1.0) */ | |
62 ) | |
63 { | |
64 Word16 exp, i, a, tmp; | |
65 Word32 L_x; | |
66 | |
67 L_x = L_mult (fraction, 32);/* L_x = fraction<<6 */ | |
68 i = extract_h (L_x); /* Extract b10-b16 of fraction */ | |
69 L_x = L_shr (L_x, 1); | |
70 a = extract_l (L_x); /* Extract b0-b9 of fraction */ | |
71 a = a & (Word16) 0x7fff; logic16 (); | |
72 | |
73 L_x = L_deposit_h (table[i]); /* table[i] << 16 */ | |
74 tmp = sub (table[i], table[i + 1]); /* table[i] - table[i+1] */ | |
75 L_x = L_msu (L_x, tmp, a); /* L_x -= tmp*a*2 */ | |
76 | |
77 exp = sub (30, exponent); | |
78 L_x = L_shr_r (L_x, exp); | |
79 | |
80 return (L_x); | |
81 } |