comparison libgsmfr2/sidclass.c @ 256:a33edf624061

libgsmfr2: start with API definition and port of libgsmfrp code
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Apr 2024 20:49:53 +0000
parents libgsmfrp/sidclass.c@2b5770c715ee
children
comparison
equal deleted inserted replaced
255:07f936338de1 256:a33edf624061
1 /*
2 * gsmfr_preproc_sid_classify() utility function classifies
3 * a GSM 06.10 frame in RTP encoding according to the rules
4 * of GSM 06.31 (or 3GPP TS 46.031) section 6.1.1, judging it
5 * as SID=0, SID=1 or SID=2.
6 */
7
8 #include <stdint.h>
9 #include "tw_gsmfr.h"
10
11 static const unsigned short sid_field_bits[95] = {
12 57, 58, 60, 61, 63, 64, 66, 67, 69, 70, 72, 73,
13 75, 76, 78, 79, 81, 82, 84, 85, 87, 88, 90, 91,
14 93, 94, 113, 114, 116, 117, 119, 120, 122, 123,
15 125, 126, 128, 129, 131, 132, 134, 135, 137,
16 138, 140, 141, 143, 144, 146, 147, 149, 150,
17 169, 170, 172, 173, 175, 176, 178, 179, 181,
18 182, 184, 185, 187, 188, 190, 191, 193, 194,
19 196, 197, 199, 200, 202, 203, 205, 206, 225,
20 226, 228, 229, 231, 232, 234, 235, 237, 240,
21 243, 246, 249, 252, 255, 258, 261
22 };
23
24 static inline int get_bit(const uint8_t *frame, unsigned bitnum)
25 {
26 unsigned bytenum = bitnum >> 3;
27 unsigned bit_in_byte = 7 - (bitnum & 7);
28 unsigned bitmask = 1 << bit_in_byte;
29
30 if (frame[bytenum] & bitmask)
31 return 1;
32 else
33 return 0;
34 }
35
36 int gsmfr_preproc_sid_classify(const uint8_t *frame)
37 {
38 unsigned idx, n;
39
40 n = 0;
41 for (idx = 0; idx < 95; idx++) {
42 if (get_bit(frame, sid_field_bits[idx]))
43 n++;
44 if (n >= 16)
45 return 0;
46 }
47 if (n < 2)
48 return 2;
49 else
50 return 1;
51 }