# HG changeset patch # User Mychaela Falconia # Date 1668842486 0 # Node ID 2b5770c715ee171890b253314d177c45c5273caf # Parent 6780b23654bd3f44b489a25bc11988a0bbeeb93a libgsmfrp: compiling utility functions diff -r 6780b23654bd -r 2b5770c715ee libgsmfrp/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgsmfrp/Makefile Sat Nov 19 07:21:26 2022 +0000 @@ -0,0 +1,13 @@ +CC= gcc +CFLAGS= -O2 +OBJS= sidclass.o silence_frame.o +LIB= libgsmfrp.a + +all: ${LIB} + +${LIB}: ${OBJS} + ar rcu $@ ${OBJS} + ranlib $@ + +clean: + rm -f *.[oa] errs diff -r 6780b23654bd -r 2b5770c715ee libgsmfrp/gsm_fr_preproc.h --- a/libgsmfrp/gsm_fr_preproc.h Sat Nov 19 04:04:01 2022 +0000 +++ b/libgsmfrp/gsm_fr_preproc.h Sat Nov 19 07:21:26 2022 +0000 @@ -24,7 +24,7 @@ gsm_byte *frame_out); /* utility function */ -extern int gsmfr_preproc_sid_classify(const gsm_frame *frame); +extern int gsmfr_preproc_sid_classify(const gsm_byte *frame); /* utility datum */ extern const gsm_frame gsmfr_preproc_silence_frame; diff -r 6780b23654bd -r 2b5770c715ee libgsmfrp/sidclass.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgsmfrp/sidclass.c Sat Nov 19 07:21:26 2022 +0000 @@ -0,0 +1,50 @@ +/* + * gsmfr_preproc_sid_classify() utility function classifies + * a GSM 06.10 frame in RTP encoding according to the rules + * of GSM 06.31 (or 3GPP TS 46.031) section 6.1.1, judging it + * as SID=0, SID=1 or SID=2. + */ + +#include "gsm_fr_preproc.h" + +static const unsigned short sid_field_bits[95] = { + 57, 58, 60, 61, 63, 64, 66, 67, 69, 70, 72, 73, + 75, 76, 78, 79, 81, 82, 84, 85, 87, 88, 90, 91, + 93, 94, 113, 114, 116, 117, 119, 120, 122, 123, + 125, 126, 128, 129, 131, 132, 134, 135, 137, + 138, 140, 141, 143, 144, 146, 147, 149, 150, + 169, 170, 172, 173, 175, 176, 178, 179, 181, + 182, 184, 185, 187, 188, 190, 191, 193, 194, + 196, 197, 199, 200, 202, 203, 205, 206, 225, + 226, 228, 229, 231, 232, 234, 235, 237, 240, + 243, 246, 249, 252, 255, 258, 261 +}; + +static inline int get_bit(const gsm_byte *frame, unsigned bitnum) +{ + unsigned bytenum = bitnum >> 3; + unsigned bit_in_byte = 7 - (bitnum & 7); + unsigned bitmask = 1 << bit_in_byte; + + if (frame[bytenum] & bitmask) + return 1; + else + return 0; +} + +int gsmfr_preproc_sid_classify(const gsm_byte *frame) +{ + unsigned idx, n; + + n = 0; + for (idx = 0; idx < 95; idx++) { + if (get_bit(frame, sid_field_bits[idx])) + n++; + if (n >= 16) + return 0; + } + if (n < 2) + return 2; + else + return 1; +}