FreeCalypso > hg > gsm-codec-lib
annotate libgsmfrp/sidclass.c @ 109:2361a7d8c1eb
libgsmfrp: randomize grid position params when muting speech,
following GSM 06.11 example solution in more detail
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 28 Nov 2022 04:15:20 +0000 |
parents | 2b5770c715ee |
children |
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 } |