FreeCalypso > hg > gsm-codec-lib
annotate libgsmfrp/bad_frame.c @ 155:9814041e8096
gsmfr-encode-r utility put together
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 15 Dec 2022 01:30:59 +0000 |
parents | 2361a7d8c1eb |
children | f081a6850fb5 |
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 |
109
2361a7d8c1eb
libgsmfrp: randomize grid position params when muting speech,
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
30 static void random_grid_pos(struct gsmfr_preproc_state *st, gsm_byte *frame) |
2361a7d8c1eb
libgsmfrp: randomize grid position params when muting speech,
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
31 { |
2361a7d8c1eb
libgsmfrp: randomize grid position params when muting speech,
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
32 unsigned sub, Mc; |
2361a7d8c1eb
libgsmfrp: randomize grid position params when muting speech,
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
33 |
2361a7d8c1eb
libgsmfrp: randomize grid position params when muting speech,
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
34 for (sub = 0; sub < 4; sub++) { |
2361a7d8c1eb
libgsmfrp: randomize grid position params when muting speech,
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
35 Mc = gsmfr_preproc_prng(st, 2); |
2361a7d8c1eb
libgsmfrp: randomize grid position params when muting speech,
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
36 frame[sub*7+6] &= 0x9F; |
2361a7d8c1eb
libgsmfrp: randomize grid position params when muting speech,
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
37 frame[sub*7+6] |= Mc << 5; |
2361a7d8c1eb
libgsmfrp: randomize grid position params when muting speech,
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
38 } |
2361a7d8c1eb
libgsmfrp: randomize grid position params when muting speech,
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
39 } |
2361a7d8c1eb
libgsmfrp: randomize grid position params when muting speech,
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
40 |
6
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 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
|
42 { |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 int mute; |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 switch (st->rx_state) { |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 case NO_DATA: |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 memcpy(frame, &gsmfr_preproc_silence_frame, sizeof(gsm_frame)); |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 return; |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 case SPEECH: |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 memcpy(frame, &st->speech_frame, sizeof(gsm_frame)); |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 st->rx_state = SPEECH_MUTING; |
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 SPEECH_MUTING: |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 mute = reduce_xmaxc(st->speech_frame); |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 memcpy(frame, &st->speech_frame, sizeof(gsm_frame)); |
109
2361a7d8c1eb
libgsmfrp: randomize grid position params when muting speech,
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
56 random_grid_pos(st, frame); |
6
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (mute) |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 st->rx_state = NO_DATA; |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 return; |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 case COMFORT_NOISE: |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 gsmfr_preproc_gen_cn(st, frame); |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (taf) |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 st->rx_state = LOST_SID; |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 return; |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 case LOST_SID: |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 gsmfr_preproc_gen_cn(st, frame); |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (taf) |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 st->rx_state = NO_DATA; |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 return; |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
b2255a5d0519
libgsmfrp: implement BFI handling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |