annotate libgsmfr2/sidclass.c @ 581:e2d5cad04cbf

libgsmhr1 RxFE: store CN R0+LPC separately from speech In the original GSM 06.06 code the ECU for speech mode is entirely separate from the CN generator, maintaining separate state. (The main intertie between them is the speech vs CN state variable, distinguishing between speech and CN BFIs, in addition to the CN-specific function of distinguishing between initial and update SIDs.) In the present RxFE implementation I initially thought that we could use the same saved_frame buffer for both ECU and CN, overwriting just the first 4 params (R0 and LPC) when a valid SID comes in. However, I now realize it was a bad idea: the original code has a corner case (long sequence of speech-mode BFIs to put the ECU in state 6, then SID and CN-mode BFIs, then a good speech frame) that would be broken by that buffer reuse approach. We could eliminate this corner case by resetting the ECU state when passing through a CN insertion period, but doing so would needlessly increase the behavioral diffs between GSM 06.06 and our version. Solution: use a separate CN-specific buffer for CN R0+LPC parameters, and match the behavior of GSM 06.06 code in this regard.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 13 Feb 2025 10:02:45 +0000
parents a33edf624061
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * gsmfr_preproc_sid_classify() utility function classifies
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * a GSM 06.10 frame in RTP encoding according to the rules
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * of GSM 06.31 (or 3GPP TS 46.031) section 6.1.1, judging it
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * as SID=0, SID=1 or SID=2.
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 */
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
256
a33edf624061 libgsmfr2: start with API definition and port of libgsmfrp code
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
8 #include <stdint.h>
a33edf624061 libgsmfr2: start with API definition and port of libgsmfrp code
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
9 #include "tw_gsmfr.h"
2
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 static const unsigned short sid_field_bits[95] = {
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 57, 58, 60, 61, 63, 64, 66, 67, 69, 70, 72, 73,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 75, 76, 78, 79, 81, 82, 84, 85, 87, 88, 90, 91,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 93, 94, 113, 114, 116, 117, 119, 120, 122, 123,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 125, 126, 128, 129, 131, 132, 134, 135, 137,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 138, 140, 141, 143, 144, 146, 147, 149, 150,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 169, 170, 172, 173, 175, 176, 178, 179, 181,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 182, 184, 185, 187, 188, 190, 191, 193, 194,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 196, 197, 199, 200, 202, 203, 205, 206, 225,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 226, 228, 229, 231, 232, 234, 235, 237, 240,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 243, 246, 249, 252, 255, 258, 261
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 };
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
256
a33edf624061 libgsmfr2: start with API definition and port of libgsmfrp code
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
24 static inline int get_bit(const uint8_t *frame, unsigned bitnum)
2
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 unsigned bytenum = bitnum >> 3;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 unsigned bit_in_byte = 7 - (bitnum & 7);
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 unsigned bitmask = 1 << bit_in_byte;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (frame[bytenum] & bitmask)
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return 1;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 else
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 return 0;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
256
a33edf624061 libgsmfr2: start with API definition and port of libgsmfrp code
Mychaela Falconia <falcon@freecalypso.org>
parents: 2
diff changeset
36 int gsmfr_preproc_sid_classify(const uint8_t *frame)
2
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 unsigned idx, n;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 n = 0;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 for (idx = 0; idx < 95; idx++) {
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (get_bit(frame, sid_field_bits[idx]))
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 n++;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (n >= 16)
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 return 0;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (n < 2)
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 return 2;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 else
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 return 1;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }