FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/a_refl.c @ 253:54f6bc41ed10
libtwamr: integrate a* modules
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 05 Apr 2024 06:08:15 +0000 |
parents | |
children | 07f936338de1 |
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 const char a_refl_id[] = "@(#)$Id $" a_refl_h; |
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 ******************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 * INCLUDE FILES |
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 */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "typedef.h" |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #include "basic_op.h" |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 #include "oper_32b.h" |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 #include "no_count.h" |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 #include "cnst.h" |
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 ******************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 * LOCAL VARIABLES AND TABLES |
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 ******************************************************************************** |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 * PUBLIC PROGRAM CODE |
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 * |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 * Function : A_Refl |
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 */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 void A_Refl( |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 Word16 a[], /* i : Directform coefficients */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 Word16 refl[] /* o : Reflection coefficients */ |
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 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 /* local variables */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 Word16 i,j; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 Word16 aState[M]; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 Word16 bState[M]; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 Word16 normShift; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 Word16 normProd; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 Word32 L_acc; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 Word16 scale; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 Word32 L_temp; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 Word16 temp; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 Word16 mult; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 /* initialize states */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 for (i = 0; i < M; i++) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 aState[i] = a[i]; move16 (); |
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 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 /* backward Levinson recursion */ |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 for (i = M-1; i >= 0; i--) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (sub(abs_s(aState[i]), 4096) >= 0) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 goto ExitRefl; |
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 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 refl[i] = shl(aState[i], 3); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 L_temp = L_mult(refl[i], refl[i]); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 L_acc = L_sub(MAX_32, L_temp); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 normShift = norm_l(L_acc); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 scale = sub(15, normShift); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 L_acc = L_shl(L_acc, normShift); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 normProd = round(L_acc); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 mult = div_s(16384, normProd); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 for (j = 0; j < i; j++) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 L_acc = L_deposit_h(aState[j]); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 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
|
103 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 temp = round(L_acc); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 L_temp = L_mult(mult, temp); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 L_temp = L_shr_r(L_temp, scale); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 if (L_sub(L_abs(L_temp), 32767) > 0) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 goto ExitRefl; |
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 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 bState[j] = extract_l(L_temp); |
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 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 for (j = 0; j < i; j++) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 aState[j] = bState[j]; move16 (); |
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 } |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 return; |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 ExitRefl: |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 for (i = 0; i < M; i++) |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 { |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 refl[i] = 0; move16 (); |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 } |
54f6bc41ed10
libtwamr: integrate a* modules
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 } |