FreeCalypso > hg > gsm-codec-lib
changeset 2:2b5770c715ee
libgsmfrp: compiling utility functions
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 19 Nov 2022 07:21:26 +0000 |
parents | 6780b23654bd |
children | 3cd5ad24b1d4 |
files | libgsmfrp/Makefile libgsmfrp/gsm_fr_preproc.h libgsmfrp/sidclass.c |
diffstat | 3 files changed, 64 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /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
--- 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;
--- /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; +}