FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/a_refl.c @ 436:e80632ccb745
simplify test program Makefiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 08 May 2024 05:32:27 +0000 |
parents | 07f936338de1 |
children |
rev | line source |
---|---|
253
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ******************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ******************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : a_refl.c |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * Purpose : Convert from direct form coefficients to |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * reflection coefficients |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 * |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 ******************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 /* |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 ******************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 * MODULE INCLUDE FILE AND VERSION ID |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 ******************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "namespace.h" |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #include "a_refl.h" |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 /* |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 ******************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 * INCLUDE FILES |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 ******************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #include "typedef.h" |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "basic_op.h" |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #include "oper_32b.h" |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 #include "no_count.h" |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 #include "cnst.h" |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 /* |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 ******************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 * LOCAL VARIABLES AND TABLES |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 ******************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 /* |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 ******************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 * PUBLIC PROGRAM CODE |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 ******************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 /* |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 ************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 * |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 * Function : A_Refl |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 * |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 ************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 void A_Refl( |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 Word16 a[], /* i : Directform coefficients */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 Word16 refl[] /* o : Reflection coefficients */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 ) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 /* local variables */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 Word16 i,j; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 Word16 aState[M]; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 Word16 bState[M]; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 Word16 normShift; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 Word16 normProd; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 Word32 L_acc; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 Word16 scale; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 Word32 L_temp; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 Word16 temp; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 Word16 mult; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 /* initialize states */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 for (i = 0; i < M; i++) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 aState[i] = a[i]; move16 (); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 /* backward Levinson recursion */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 for (i = M-1; i >= 0; i--) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 if (sub(abs_s(aState[i]), 4096) >= 0) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 goto ExitRefl; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 refl[i] = shl(aState[i], 3); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 L_temp = L_mult(refl[i], refl[i]); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 L_acc = L_sub(MAX_32, L_temp); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 normShift = norm_l(L_acc); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 scale = sub(15, normShift); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 L_acc = L_shl(L_acc, normShift); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 normProd = round(L_acc); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 mult = div_s(16384, normProd); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 for (j = 0; j < i; j++) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 L_acc = L_deposit_h(aState[j]); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 L_acc = L_msu(L_acc, refl[i], aState[i-j-1]); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 temp = round(L_acc); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 L_temp = L_mult(mult, temp); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 L_temp = L_shr_r(L_temp, scale); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 if (L_sub(L_abs(L_temp), 32767) > 0) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 goto ExitRefl; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 } |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 bState[j] = extract_l(L_temp); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 } |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 for (j = 0; j < i; j++) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 aState[j] = bState[j]; move16 (); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 } |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 } |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 return; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 ExitRefl: |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 for (i = 0; i < M; i++) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 refl[i] = 0; move16 (); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 } |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 } |