annotate libgsmfr2/sidclass.c @ 478:936a08cc73ce

doc/AMR-library-API: describe the decoder
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 19 May 2024 21:32:31 +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 }