FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/log2.c @ 458:e26b974f7ba3
doc/AMR-study-utils: update for the current situation
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 10 May 2024 18:45:36 +0000 |
parents | bfe74a9edd5a |
children |
rev | line source |
---|---|
326
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ******************************************************************************** |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ******************************************************************************** |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : log2.c |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * Purpose : Computes log2(L_x) |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 ******************************************************************************** |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 /* |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 ******************************************************************************** |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 * MODULE INCLUDE FILE AND VERSION ID |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 ******************************************************************************** |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include "namespace.h" |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "log2.h" |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 /* |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 ******************************************************************************** |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 * INCLUDE FILES |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 ******************************************************************************** |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 #include "typedef.h" |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #include "basic_op.h" |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #include "no_count.h" |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 /* |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 ******************************************************************************** |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 * LOCAL VARIABLES AND TABLES |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 ******************************************************************************** |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 #include "log2.tab" /* Table for Log2() */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 /* |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 ******************************************************************************** |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 * PUBLIC PROGRAM CODE |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 ******************************************************************************** |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 /************************************************************************* |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 * |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 * FUNCTION: Log2_norm() |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 * |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 * PURPOSE: Computes log2(L_x, exp), where L_x is positive and |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 * normalized, and exp is the normalisation exponent |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 * If L_x is negative or zero, the result is 0. |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 * |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 * DESCRIPTION: |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 * The function Log2(L_x) is approximated by a table and linear |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 * interpolation. The following steps are used to compute Log2(L_x) |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 * |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 * 1- exponent = 30-norm_exponent |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 * 2- i = bit25-b31 of L_x; 32<=i<=63 (because of normalization). |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 * 3- a = bit10-b24 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 * 4- i -=32 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 * 5- fraction = table[i]<<16 - (table[i] - table[i+1]) * a * 2 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 * |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 *************************************************************************/ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 void Log2_norm ( |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 Word32 L_x, /* (i) : input value (normalized) */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 Word16 exp, /* (i) : norm_l (L_x) */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 Word16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 Word16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 ) |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 { |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 Word16 i, a, tmp; |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 Word32 L_y; |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 test (); |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 if (L_x <= (Word32) 0) |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 { |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 *exponent = 0; move16 (); |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 *fraction = 0; move16 (); |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 return; |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 *exponent = sub (30, exp); move16 (); |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 L_x = L_shr (L_x, 9); |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 i = extract_h (L_x); /* Extract b25-b31 */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 L_x = L_shr (L_x, 1); |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 a = extract_l (L_x); /* Extract b10-b24 of fraction */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 a = a & (Word16) 0x7fff; logic16 (); |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 i = sub (i, 32); |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 L_y = L_deposit_h (table[i]); /* table[i] << 16 */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 tmp = sub (table[i], table[i + 1]); /* table[i] - table[i+1] */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 L_y = L_msu (L_y, tmp, a); /* L_y -= tmp*a*2 */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 *fraction = extract_h (L_y);move16 (); |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 return; |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 } |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 /************************************************************************* |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 * |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 * FUNCTION: Log2() |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 * |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 * PURPOSE: Computes log2(L_x), where L_x is positive. |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 * If L_x is negative or zero, the result is 0. |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 * |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 * DESCRIPTION: |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 * normalizes L_x and then calls Log2_norm(). |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 * |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 *************************************************************************/ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 void Log2 ( |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 Word32 L_x, /* (i) : input value */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 Word16 *exponent, /* (o) : Integer part of Log2. (range: 0<=val<=30) */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 Word16 *fraction /* (o) : Fractional part of Log2. (range: 0<=val<1) */ |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 ) |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 { |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 Word16 exp; |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 exp = norm_l (L_x); |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 Log2_norm (L_shl (L_x, exp), exp, exponent, fraction); |
bfe74a9edd5a
libtwamr: integrate log2.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 } |