comparison libgsmefr/sid_class.c @ 36:b5726d659915

libgsmefr: rename sidclass.c to sid_class.c, in preparation for adding sid_insert.c
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 24 Nov 2022 02:36:47 +0000
parents libgsmefr/sidclass.c@19a90fa1f608
children
comparison
equal deleted inserted replaced
35:3b5958f28a40 36:b5726d659915
1 /*
2 * EFR_sid_classify() utility function classifies an EFR frame
3 * in RTP encoding according to the rules of GSM 06.81 section 6.1.1,
4 * judging it as SID=0, SID=1 or SID=2.
5 */
6
7 #include "gsm_efr.h"
8
9 static const uint8_t SID_codeword_bit_idx[95] =
10 {
11 45, 46, 48, 49, 50, 51, 52, 53, 54, 55,
12 56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
13 66, 67, 68, 94, 95, 96, 98, 99, 100, 101,
14 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
15 112, 113, 114, 115, 116, 117, 118, 148, 149, 150,
16 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
17 161, 162, 163, 164, 165, 166, 167, 168, 169, 170,
18 171, 196, 197, 198, 199, 200, 201, 202, 203, 204,
19 205, 206, 207, 208, 209, 212, 213, 214, 215, 216,
20 217, 218, 219, 220, 221
21 };
22
23 static inline int get_bit(const uint8_t *frame, unsigned bitnum)
24 {
25 unsigned bytenum = bitnum >> 3;
26 unsigned bit_in_byte = 7 - (bitnum & 7);
27 unsigned bitmask = 1 << bit_in_byte;
28
29 if (frame[bytenum] & bitmask)
30 return 1;
31 else
32 return 0;
33 }
34
35 int EFR_sid_classify(const uint8_t *frame)
36 {
37 unsigned idx, n;
38
39 n = 0;
40 for (idx = 0; idx < 95; idx++) {
41 if (!get_bit(frame, SID_codeword_bit_idx[idx] + 4))
42 n++;
43 if (n >= 16)
44 return 0;
45 }
46 if (n < 2)
47 return 2;
48 else
49 return 1;
50 }