FreeCalypso > hg > gsm-codec-lib
comparison libgsmfrp/sidclass.c @ 2:2b5770c715ee
libgsmfrp: compiling utility functions
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sat, 19 Nov 2022 07:21:26 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:6780b23654bd | 2:2b5770c715ee |
|---|---|
| 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 "gsm_fr_preproc.h" | |
| 9 | |
| 10 static const unsigned short sid_field_bits[95] = { | |
| 11 57, 58, 60, 61, 63, 64, 66, 67, 69, 70, 72, 73, | |
| 12 75, 76, 78, 79, 81, 82, 84, 85, 87, 88, 90, 91, | |
| 13 93, 94, 113, 114, 116, 117, 119, 120, 122, 123, | |
| 14 125, 126, 128, 129, 131, 132, 134, 135, 137, | |
| 15 138, 140, 141, 143, 144, 146, 147, 149, 150, | |
| 16 169, 170, 172, 173, 175, 176, 178, 179, 181, | |
| 17 182, 184, 185, 187, 188, 190, 191, 193, 194, | |
| 18 196, 197, 199, 200, 202, 203, 205, 206, 225, | |
| 19 226, 228, 229, 231, 232, 234, 235, 237, 240, | |
| 20 243, 246, 249, 252, 255, 258, 261 | |
| 21 }; | |
| 22 | |
| 23 static inline int get_bit(const gsm_byte *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 gsmfr_preproc_sid_classify(const gsm_byte *frame) | |
| 36 { | |
| 37 unsigned idx, n; | |
| 38 | |
| 39 n = 0; | |
| 40 for (idx = 0; idx < 95; idx++) { | |
| 41 if (get_bit(frame, sid_field_bits[idx])) | |
| 42 n++; | |
| 43 if (n >= 16) | |
| 44 return 0; | |
| 45 } | |
| 46 if (n < 2) | |
| 47 return 2; | |
| 48 else | |
| 49 return 1; | |
| 50 } |
