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