FreeCalypso > hg > gsm-codec-lib
comparison libgsmefr/dtx_dec.c @ 192:0303ba213e1c
libgsmefr/dtx_dec.c: perf opt
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 03 Jan 2023 04:51:51 +0000 |
parents | c1d53064b410 |
children | 17f690749099 |
comparison
equal
deleted
inserted
replaced
191:7bc011aceb7f | 192:0303ba213e1c |
---|---|
108 /* Frame classification according to bfi-flag and ternary-valued | 108 /* Frame classification according to bfi-flag and ternary-valued |
109 SID flag. The frames between SID updates (not actually trans- | 109 SID flag. The frames between SID updates (not actually trans- |
110 mitted) are also classified here; they will be discarded later | 110 mitted) are also classified here; they will be discarded later |
111 and provided with "NO TRANSMISSION"-flag */ | 111 and provided with "NO TRANSMISSION"-flag */ |
112 | 112 |
113 if ((sub (SID_flag, 2) == 0) && (bfi == 0)) | 113 if ((SID_flag == 2) && (bfi == 0)) |
114 { | 114 { |
115 frame_type = VALID_SID_FRAME; move16 (); | 115 frame_type = VALID_SID_FRAME; move16 (); |
116 } | 116 } |
117 else if ((SID_flag == 0) && (bfi == 0)) | 117 else if ((SID_flag == 0) && (bfi == 0)) |
118 { | 118 { |
129 | 129 |
130 /* Update of decoder state */ | 130 /* Update of decoder state */ |
131 /* Previous frame was classified as a speech frame */ | 131 /* Previous frame was classified as a speech frame */ |
132 if ((st->rxdtx_ctrl & RX_SP_FLAG) != 0) | 132 if ((st->rxdtx_ctrl & RX_SP_FLAG) != 0) |
133 { | 133 { |
134 if (sub (frame_type, VALID_SID_FRAME) == 0) | 134 if (frame_type == VALID_SID_FRAME) |
135 { | 135 { |
136 st->rxdtx_ctrl = RX_FIRST_SID_UPDATE; | 136 st->rxdtx_ctrl = RX_FIRST_SID_UPDATE; |
137 } | 137 } |
138 else if (sub (frame_type, INVALID_SID_FRAME) == 0) | 138 else if (frame_type == INVALID_SID_FRAME) |
139 { | 139 { |
140 st->rxdtx_ctrl = RX_FIRST_SID_UPDATE | 140 st->rxdtx_ctrl = RX_FIRST_SID_UPDATE |
141 | RX_INVALID_SID_FRAME; | 141 | RX_INVALID_SID_FRAME; |
142 } | 142 } |
143 else if (sub (frame_type, UNUSABLE_FRAME) == 0) | 143 else if (frame_type == UNUSABLE_FRAME) |
144 { | 144 { |
145 st->rxdtx_ctrl = RX_SP_FLAG; | 145 st->rxdtx_ctrl = RX_SP_FLAG; |
146 } | 146 } |
147 else if (sub (frame_type, GOOD_SPEECH_FRAME) == 0) | 147 else if (frame_type == GOOD_SPEECH_FRAME) |
148 { | 148 { |
149 st->rxdtx_ctrl = RX_SP_FLAG; | 149 st->rxdtx_ctrl = RX_SP_FLAG; |
150 } | 150 } |
151 } | 151 } |
152 else | 152 else |
153 { | 153 { |
154 if (sub (frame_type, VALID_SID_FRAME) == 0) | 154 if (frame_type == VALID_SID_FRAME) |
155 { | 155 { |
156 st->rxdtx_ctrl = RX_CONT_SID_UPDATE; | 156 st->rxdtx_ctrl = RX_CONT_SID_UPDATE; |
157 } | 157 } |
158 else if (sub (frame_type, INVALID_SID_FRAME) == 0) | 158 else if (frame_type == INVALID_SID_FRAME) |
159 { | 159 { |
160 st->rxdtx_ctrl = RX_CONT_SID_UPDATE | 160 st->rxdtx_ctrl = RX_CONT_SID_UPDATE |
161 | RX_INVALID_SID_FRAME; | 161 | RX_INVALID_SID_FRAME; |
162 } | 162 } |
163 else if (sub (frame_type, UNUSABLE_FRAME) == 0) | 163 else if (frame_type == UNUSABLE_FRAME) |
164 { | 164 { |
165 st->rxdtx_ctrl = RX_CNI_BFI; | 165 st->rxdtx_ctrl = RX_CNI_BFI; |
166 } | 166 } |
167 else if (sub (frame_type, GOOD_SPEECH_FRAME) == 0) | 167 else if (frame_type == GOOD_SPEECH_FRAME) |
168 { | 168 { |
169 /* If the previous frame (during CNI period) was muted, | 169 /* If the previous frame (during CNI period) was muted, |
170 raise the RX_PREV_DTX_MUTING flag */ | 170 raise the RX_PREV_DTX_MUTING flag */ |
171 if ((st->rxdtx_ctrl & RX_DTX_MUTING) != 0) | 171 if ((st->rxdtx_ctrl & RX_DTX_MUTING) != 0) |
172 { | 172 { |
197 /* SID frame detected, but not the first SID */ | 197 /* SID frame detected, but not the first SID */ |
198 if ((st->rxdtx_ctrl & RX_CONT_SID_UPDATE) != 0) | 198 if ((st->rxdtx_ctrl & RX_CONT_SID_UPDATE) != 0) |
199 { | 199 { |
200 st->prev_SID_frames_lost = 0; | 200 st->prev_SID_frames_lost = 0; |
201 | 201 |
202 if (sub (frame_type, VALID_SID_FRAME) == 0) | 202 if (frame_type == VALID_SID_FRAME) |
203 { | 203 { |
204 st->rx_dtx_state = 0; | 204 st->rx_dtx_state = 0; |
205 } | 205 } |
206 else if (sub (frame_type, INVALID_SID_FRAME) == 0) | 206 else if (frame_type == INVALID_SID_FRAME) |
207 { | 207 { |
208 if (sub(st->rx_dtx_state, (CN_INT_PERIOD - 1)) < 0) | 208 if (st->rx_dtx_state < (CN_INT_PERIOD - 1)) |
209 { | 209 { |
210 st->rx_dtx_state = add(st->rx_dtx_state, 1); | 210 st->rx_dtx_state++; |
211 } | 211 } |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
215 /* Bad frame received in CNI mode */ | 215 /* Bad frame received in CNI mode */ |
216 if ((st->rxdtx_ctrl & RX_CNI_BFI) != 0) | 216 if ((st->rxdtx_ctrl & RX_CNI_BFI) != 0) |
217 { | 217 { |
218 if (sub (st->rx_dtx_state, (CN_INT_PERIOD - 1)) < 0) | 218 if (st->rx_dtx_state < (CN_INT_PERIOD - 1)) |
219 { | 219 { |
220 st->rx_dtx_state = add (st->rx_dtx_state, 1); | 220 st->rx_dtx_state++; |
221 } | 221 } |
222 | 222 |
223 /* If an unusable frame is received during CNI period | 223 /* If an unusable frame is received during CNI period |
224 when TAF == 1, the frame is classified as a lost | 224 when TAF == 1, the frame is classified as a lost |
225 SID frame */ | 225 SID frame */ |
226 if (sub (TAF, 1) == 0) | 226 if (TAF == 1) |
227 { | 227 { |
228 st->rxdtx_ctrl = st->rxdtx_ctrl | RX_LOST_SID_FRAME; | 228 st->rxdtx_ctrl = st->rxdtx_ctrl | RX_LOST_SID_FRAME; |
229 st->prev_SID_frames_lost = add (st->prev_SID_frames_lost, 1); | 229 st->prev_SID_frames_lost = add (st->prev_SID_frames_lost, 1); |
230 } | 230 } |
231 else /* No transmission occurred */ | 231 else /* No transmission occurred */ |
232 { | 232 { |
233 st->rxdtx_ctrl = st->rxdtx_ctrl | RX_NO_TRANSMISSION; | 233 st->rxdtx_ctrl = st->rxdtx_ctrl | RX_NO_TRANSMISSION; |
234 } | 234 } |
235 | 235 |
236 if (sub (st->prev_SID_frames_lost, 1) > 0) | 236 if (st->prev_SID_frames_lost > 1) |
237 { | 237 { |
238 st->rxdtx_ctrl = st->rxdtx_ctrl | RX_DTX_MUTING; | 238 st->rxdtx_ctrl = st->rxdtx_ctrl | RX_DTX_MUTING; |
239 } | 239 } |
240 } | 240 } |
241 } | 241 } |
249 { | 249 { |
250 st->rxdtx_aver_period = DTX_HANGOVER; | 250 st->rxdtx_aver_period = DTX_HANGOVER; |
251 } | 251 } |
252 else | 252 else |
253 { | 253 { |
254 if (sub (st->rxdtx_N_elapsed, DTX_ELAPSED_THRESHOLD) > 0) | 254 if (st->rxdtx_N_elapsed > DTX_ELAPSED_THRESHOLD) |
255 { | 255 { |
256 st->rxdtx_ctrl |= RX_UPD_SID_QUANT_MEM; | 256 st->rxdtx_ctrl |= RX_UPD_SID_QUANT_MEM; |
257 st->rxdtx_N_elapsed = 0; | 257 st->rxdtx_N_elapsed = 0; |
258 st->rxdtx_aver_period = 0; | 258 st->rxdtx_aver_period = 0; |
259 st->L_pn_seed_rx = PN_INITIAL_SEED; | 259 st->L_pn_seed_rx = PN_INITIAL_SEED; |
262 { | 262 { |
263 st->rxdtx_N_elapsed = 0; | 263 st->rxdtx_N_elapsed = 0; |
264 } | 264 } |
265 else | 265 else |
266 { | 266 { |
267 st->rxdtx_aver_period = sub (st->rxdtx_aver_period, 1); | 267 st->rxdtx_aver_period--; |
268 } | 268 } |
269 } | 269 } |
270 | 270 |
271 return; | 271 return; |
272 } | 272 } |
298 ) | 298 ) |
299 { | 299 { |
300 /* Circular buffer */ | 300 /* Circular buffer */ |
301 st->gain_code_old_rx[st->buf_p_rx] = new_gain_code; | 301 st->gain_code_old_rx[st->buf_p_rx] = new_gain_code; |
302 | 302 |
303 if (sub (st->buf_p_rx, (4 * DTX_HANGOVER - 1)) == 0) | 303 if (st->buf_p_rx == (4 * DTX_HANGOVER - 1)) |
304 { | 304 { |
305 st->buf_p_rx = 0; | 305 st->buf_p_rx = 0; |
306 } | 306 } |
307 else | 307 else |
308 { | 308 { |
309 st->buf_p_rx = add (st->buf_p_rx, 1); | 309 st->buf_p_rx++; |
310 } | 310 } |
311 | 311 |
312 return; | 312 return; |
313 } | 313 } |
314 | 314 |