FreeCalypso > hg > gsm-codec-lib
comparison libtwamr/ton_stab.c @ 405:8fff74ca83e8
libtwamr: integrate ton_stab.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 06 May 2024 23:23:40 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
404:a37687c6ff22 | 405:8fff74ca83e8 |
---|---|
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 : ton_stab.c | |
11 * | |
12 ***************************************************************************** | |
13 */ | |
14 | |
15 /* | |
16 ***************************************************************************** | |
17 * MODULE INCLUDE FILE AND VERSION ID | |
18 ***************************************************************************** | |
19 */ | |
20 #include "namespace.h" | |
21 #include "ton_stab.h" | |
22 | |
23 /* | |
24 ***************************************************************************** | |
25 * INCLUDE FILES | |
26 ***************************************************************************** | |
27 */ | |
28 #include "typedef.h" | |
29 #include "basic_op.h" | |
30 #include "no_count.h" | |
31 #include "oper_32b.h" | |
32 #include "cnst.h" | |
33 #include "memops.h" | |
34 | |
35 /* | |
36 ***************************************************************************** | |
37 * LOCAL VARIABLES AND TABLES | |
38 ***************************************************************************** | |
39 */ | |
40 | |
41 /* | |
42 ***************************************************************************** | |
43 * PUBLIC PROGRAM CODE | |
44 ***************************************************************************** | |
45 */ | |
46 | |
47 /************************************************************************* | |
48 * | |
49 * Function: ton_stab_reset | |
50 * Purpose: Initializes state memory to zero | |
51 * | |
52 ************************************************************************** | |
53 */ | |
54 void ton_stab_reset (tonStabState *st) | |
55 { | |
56 /* initialize tone stabilizer state */ | |
57 st->count = 0; | |
58 Set_zero(st->gp, N_FRAME); /* Init Gp_Clipping */ | |
59 } | |
60 | |
61 /*************************************************************************** | |
62 * * | |
63 * Function: check_lsp() * | |
64 * Purpose: Check the LSP's to detect resonances * | |
65 * * | |
66 **************************************************************************** | |
67 */ | |
68 Word16 check_lsp(tonStabState *st, /* i/o : State struct */ | |
69 Word16 *lsp /* i : unquantized LSP's */ | |
70 ) | |
71 { | |
72 Word16 i, dist, dist_min1, dist_min2, dist_th; | |
73 | |
74 /* Check for a resonance: */ | |
75 /* Find minimum distance between lsp[i] and lsp[i+1] */ | |
76 | |
77 dist_min1 = MAX_16; move16 (); | |
78 for (i = 3; i < M-2; i++) | |
79 { | |
80 dist = sub(lsp[i], lsp[i+1]); | |
81 | |
82 test (); | |
83 if (sub(dist, dist_min1) < 0) | |
84 { | |
85 dist_min1 = dist; move16 (); | |
86 } | |
87 } | |
88 | |
89 dist_min2 = MAX_16; move16 (); | |
90 for (i = 1; i < 3; i++) | |
91 { | |
92 dist = sub(lsp[i], lsp[i+1]); | |
93 | |
94 test (); | |
95 if (sub(dist, dist_min2) < 0) | |
96 { | |
97 dist_min2 = dist; move16 (); | |
98 } | |
99 } | |
100 | |
101 if (test (), sub(lsp[1], 32000) > 0) | |
102 { | |
103 dist_th = 600; move16 (); | |
104 } | |
105 else if (test (), sub(lsp[1], 30500) > 0) | |
106 { | |
107 dist_th = 800; move16 (); | |
108 } | |
109 else | |
110 { | |
111 dist_th = 1100; move16 (); | |
112 } | |
113 | |
114 test (); test (); | |
115 if (sub(dist_min1, 1500) < 0 || | |
116 sub(dist_min2, dist_th) < 0) | |
117 { | |
118 st->count = add(st->count, 1); | |
119 } | |
120 else | |
121 { | |
122 st->count = 0; move16 (); | |
123 } | |
124 | |
125 /* Need 12 consecutive frames to set the flag */ | |
126 test (); | |
127 if (sub(st->count, 12) >= 0) | |
128 { | |
129 st->count = 12; move16 (); | |
130 return 1; | |
131 } | |
132 else | |
133 { | |
134 return 0; | |
135 } | |
136 } | |
137 | |
138 /*************************************************************************** | |
139 * | |
140 * Function: Check_Gp_Clipping() | |
141 * Purpose: Verify that the sum of the last (N_FRAME+1) pitch | |
142 * gains is under a certain threshold. | |
143 * | |
144 *************************************************************************** | |
145 */ | |
146 Word16 check_gp_clipping(tonStabState *st, /* i/o : State struct */ | |
147 Word16 g_pitch /* i : pitch gain */ | |
148 ) | |
149 { | |
150 Word16 i, sum; | |
151 | |
152 sum = shr(g_pitch, 3); /* Division by 8 */ | |
153 for (i = 0; i < N_FRAME; i++) | |
154 { | |
155 sum = add(sum, st->gp[i]); | |
156 } | |
157 | |
158 test (); | |
159 if (sub(sum, GP_CLIP) > 0) | |
160 { | |
161 return 1; | |
162 } | |
163 else | |
164 { | |
165 return 0; | |
166 } | |
167 } | |
168 | |
169 /*************************************************************************** | |
170 * | |
171 * Function: Update_Gp_Clipping() | |
172 * Purpose: Update past pitch gain memory | |
173 * | |
174 *************************************************************************** | |
175 */ | |
176 void update_gp_clipping(tonStabState *st, /* i/o : State struct */ | |
177 Word16 g_pitch /* i : pitch gain */ | |
178 ) | |
179 { | |
180 Copy(&st->gp[1], &st->gp[0], N_FRAME-1); | |
181 st->gp[N_FRAME-1] = shr(g_pitch, 3); | |
182 } |