view libgsmfr2/sidclass.c @ 467:ad032051166a

doc: AMR-EFR-hybrid-emu new article
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 12 May 2024 23:54:43 +0000
parents a33edf624061
children
line wrap: on
line source

/*
 * 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 <stdint.h>
#include "tw_gsmfr.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 uint8_t *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 uint8_t *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;
}