annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement our handling of BFI frame gaps.
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <stdint.h>
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <string.h>
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include "gsm_fr_preproc.h"
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "internal.h"
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 static int reduce_xmaxc(gsm_byte *frame)
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 {
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 int mute_flag = 1;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 unsigned sub, xmaxc;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 for (sub = 0; sub < 4; sub++) {
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 xmaxc = ((frame[sub*7+6] & 0x1F) << 1) | (frame[sub*7+7] >> 7);
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 if (xmaxc > 4) {
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 xmaxc -= 4;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 mute_flag = 0;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 } else
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 xmaxc = 0;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 frame[sub*7+6] &= 0xE0;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 frame[sub*7+6] |= xmaxc >> 1;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 frame[sub*7+7] &= 0x7F;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 frame[sub*7+7] |= (xmaxc & 1) << 7;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return mute_flag;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 void gsmfr_preproc_bfi(struct gsmfr_preproc_state *st, int taf, gsm_byte *frame)
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 int mute;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 switch (st->rx_state) {
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 case NO_DATA:
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 memcpy(frame, &gsmfr_preproc_silence_frame, sizeof(gsm_frame));
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 return;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 case SPEECH:
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 memcpy(frame, &st->speech_frame, sizeof(gsm_frame));
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 st->rx_state = SPEECH_MUTING;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 case SPEECH_MUTING:
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 mute = reduce_xmaxc(st->speech_frame);
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 memcpy(frame, &st->speech_frame, sizeof(gsm_frame));
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (mute)
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 st->rx_state = NO_DATA;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 case COMFORT_NOISE:
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 gsmfr_preproc_gen_cn(st, frame);
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (taf)
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 st->rx_state = LOST_SID;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 return;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 case LOST_SID:
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 gsmfr_preproc_gen_cn(st, frame);
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (taf)
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 st->rx_state = NO_DATA;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 return;
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }
b2255a5d0519 libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }