comparison 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
comparison
equal deleted inserted replaced
252:57b4053559ff 253:54f6bc41ed10
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 : a_refl.c
11 * Purpose : Convert from direct form coefficients to
12 * reflection coefficients
13 *
14 ********************************************************************************
15 */
16 /*
17 ********************************************************************************
18 * MODULE INCLUDE FILE AND VERSION ID
19 ********************************************************************************
20 */
21 #include "namespace.h"
22 #include "a_refl.h"
23 const char a_refl_id[] = "@(#)$Id $" a_refl_h;
24
25
26 /*
27 ********************************************************************************
28 * INCLUDE FILES
29 ********************************************************************************
30 */
31 #include "typedef.h"
32 #include "basic_op.h"
33 #include "oper_32b.h"
34 #include "no_count.h"
35 #include "cnst.h"
36
37 /*
38 ********************************************************************************
39 * LOCAL VARIABLES AND TABLES
40 ********************************************************************************
41 */
42
43 /*
44 ********************************************************************************
45 * PUBLIC PROGRAM CODE
46 ********************************************************************************
47 */
48 /*
49 **************************************************************************
50 *
51 * Function : A_Refl
52 *
53 **************************************************************************
54 */
55 void A_Refl(
56 Word16 a[], /* i : Directform coefficients */
57 Word16 refl[] /* o : Reflection coefficients */
58 )
59 {
60 /* local variables */
61 Word16 i,j;
62 Word16 aState[M];
63 Word16 bState[M];
64 Word16 normShift;
65 Word16 normProd;
66 Word32 L_acc;
67 Word16 scale;
68 Word32 L_temp;
69 Word16 temp;
70 Word16 mult;
71
72 /* initialize states */
73 for (i = 0; i < M; i++)
74 {
75 aState[i] = a[i]; move16 ();
76 }
77
78 /* backward Levinson recursion */
79 for (i = M-1; i >= 0; i--)
80 {
81 if (sub(abs_s(aState[i]), 4096) >= 0)
82 {
83 goto ExitRefl;
84 }
85
86 refl[i] = shl(aState[i], 3);
87
88 L_temp = L_mult(refl[i], refl[i]);
89 L_acc = L_sub(MAX_32, L_temp);
90
91 normShift = norm_l(L_acc);
92 scale = sub(15, normShift);
93
94 L_acc = L_shl(L_acc, normShift);
95 normProd = round(L_acc);
96
97 mult = div_s(16384, normProd);
98
99 for (j = 0; j < i; j++)
100 {
101 L_acc = L_deposit_h(aState[j]);
102 L_acc = L_msu(L_acc, refl[i], aState[i-j-1]);
103
104 temp = round(L_acc);
105 L_temp = L_mult(mult, temp);
106 L_temp = L_shr_r(L_temp, scale);
107
108 if (L_sub(L_abs(L_temp), 32767) > 0)
109 {
110 goto ExitRefl;
111 }
112
113 bState[j] = extract_l(L_temp);
114 }
115
116 for (j = 0; j < i; j++)
117 {
118 aState[j] = bState[j]; move16 ();
119 }
120 }
121 return;
122
123 ExitRefl:
124 for (i = 0; i < M; i++)
125 {
126 refl[i] = 0; move16 ();
127 }
128 }