annotate libgsmfrp/sidclass.c @ 242:f081a6850fb5

libgsmfrp: new refined implementation The previous implementation exhibited the following defects, which are now fixed: 1) The last received valid SID was cached forever for the purpose of handling future invalid SIDs - we could have received some valid SID ages ago, then lots of speech or NO_DATA, and if we then get an invalid SID, we would resurrect the last valid SID from ancient history - a bad design. In our new design, we handle invalid SID based on the current state, much like BFI. 2) GSM 06.11 spec says clearly that after the second lost SID (received BFI=1 && TAF=1 in CN state) we need to gradually decrease the output level, rather than jump directly to emitting silence frames - we previously failed to implement such logic. 3) Per GSM 06.12 section 5.2, Xmaxc should be the same in all 4 subframes in a SID frame. What should we do if we receive an otherwise valid SID frame with different Xmaxc? Our previous approach would replicate this Xmaxc oddity in every subsequent generated CN frame, which is rather bad. In our new design, the very first CN frame (which can be seen as a transformation of the SID frame itself) retains the original 4 distinct Xmaxc, but all subsequent CN frames are based on the Xmaxc from the last subframe of the most recent SID.
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 09 May 2023 05:16:31 +0000
parents 2b5770c715ee
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
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "gsm_fr_preproc.h"
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 static const unsigned short sid_field_bits[95] = {
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 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
12 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
13 93, 94, 113, 114, 116, 117, 119, 120, 122, 123,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 125, 126, 128, 129, 131, 132, 134, 135, 137,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 138, 140, 141, 143, 144, 146, 147, 149, 150,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 169, 170, 172, 173, 175, 176, 178, 179, 181,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 182, 184, 185, 187, 188, 190, 191, 193, 194,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 196, 197, 199, 200, 202, 203, 205, 206, 225,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 226, 228, 229, 231, 232, 234, 235, 237, 240,
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 243, 246, 249, 252, 255, 258, 261
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 };
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 static inline int get_bit(const gsm_byte *frame, unsigned bitnum)
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 {
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 unsigned bytenum = bitnum >> 3;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 unsigned bit_in_byte = 7 - (bitnum & 7);
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 unsigned bitmask = 1 << bit_in_byte;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (frame[bytenum] & bitmask)
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return 1;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 else
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return 0;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
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 int gsmfr_preproc_sid_classify(const gsm_byte *frame)
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 unsigned idx, n;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 n = 0;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 for (idx = 0; idx < 95; idx++) {
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (get_bit(frame, sid_field_bits[idx]))
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 n++;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (n >= 16)
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 return 0;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 }
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (n < 2)
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return 2;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 else
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 return 1;
2b5770c715ee libgsmfrp: compiling utility functions
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }