FreeCalypso > hg > gsm-codec-lib
comparison libgsmfrp/bad_frame.c @ 6:b2255a5d0519
libgsmfrp: implement BFI handling
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 19 Nov 2022 21:18:53 +0000 |
parents | |
children | 2361a7d8c1eb |
comparison
equal
deleted
inserted
replaced
5:4812e00bc100 | 6:b2255a5d0519 |
---|---|
1 /* | |
2 * In this module we implement our handling of BFI frame gaps. | |
3 */ | |
4 | |
5 #include <stdint.h> | |
6 #include <string.h> | |
7 #include "gsm_fr_preproc.h" | |
8 #include "internal.h" | |
9 | |
10 static int reduce_xmaxc(gsm_byte *frame) | |
11 { | |
12 int mute_flag = 1; | |
13 unsigned sub, xmaxc; | |
14 | |
15 for (sub = 0; sub < 4; sub++) { | |
16 xmaxc = ((frame[sub*7+6] & 0x1F) << 1) | (frame[sub*7+7] >> 7); | |
17 if (xmaxc > 4) { | |
18 xmaxc -= 4; | |
19 mute_flag = 0; | |
20 } else | |
21 xmaxc = 0; | |
22 frame[sub*7+6] &= 0xE0; | |
23 frame[sub*7+6] |= xmaxc >> 1; | |
24 frame[sub*7+7] &= 0x7F; | |
25 frame[sub*7+7] |= (xmaxc & 1) << 7; | |
26 } | |
27 return mute_flag; | |
28 } | |
29 | |
30 void gsmfr_preproc_bfi(struct gsmfr_preproc_state *st, int taf, gsm_byte *frame) | |
31 { | |
32 int mute; | |
33 | |
34 switch (st->rx_state) { | |
35 case NO_DATA: | |
36 memcpy(frame, &gsmfr_preproc_silence_frame, sizeof(gsm_frame)); | |
37 return; | |
38 case SPEECH: | |
39 memcpy(frame, &st->speech_frame, sizeof(gsm_frame)); | |
40 st->rx_state = SPEECH_MUTING; | |
41 return; | |
42 case SPEECH_MUTING: | |
43 mute = reduce_xmaxc(st->speech_frame); | |
44 memcpy(frame, &st->speech_frame, sizeof(gsm_frame)); | |
45 if (mute) | |
46 st->rx_state = NO_DATA; | |
47 return; | |
48 case COMFORT_NOISE: | |
49 gsmfr_preproc_gen_cn(st, frame); | |
50 if (taf) | |
51 st->rx_state = LOST_SID; | |
52 return; | |
53 case LOST_SID: | |
54 gsmfr_preproc_gen_cn(st, frame); | |
55 if (taf) | |
56 st->rx_state = NO_DATA; | |
57 return; | |
58 } | |
59 } |