changeset 5:4812e00bc100

libgsmfrp: implement handling of good frames
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 19 Nov 2022 20:46:13 +0000
parents 286d5f097eb4
children b2255a5d0519
files libgsmfrp/Makefile libgsmfrp/good_frame.c
diffstat 2 files changed, 45 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libgsmfrp/Makefile	Sat Nov 19 20:16:09 2022 +0000
+++ b/libgsmfrp/Makefile	Sat Nov 19 20:46:13 2022 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-OBJS=	comfort_noise.o sidclass.o silence_frame.o state.o
+OBJS=	comfort_noise.o good_frame.o sidclass.o silence_frame.o state.o
 LIB=	libgsmfrp.a
 
 all:	${LIB}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgsmfrp/good_frame.c	Sat Nov 19 20:46:13 2022 +0000
@@ -0,0 +1,44 @@
+/*
+ * In this module we implement preprocessing of received good frames.
+ */
+
+#include <stdint.h>
+#include <string.h>
+#include "gsm_fr_preproc.h"
+#include "internal.h"
+
+void gsmfr_preproc_good_frame(struct gsmfr_preproc_state *st, gsm_byte *frame)
+{
+	int sid;
+
+	/* always set correct magic */
+	frame[0] = 0xD0 | frame[0] & 0x0F;
+	/* now classify by SID */
+	sid = gsmfr_preproc_sid_classify(frame);
+	switch (sid) {
+	case 0:		/* good speech frame */
+		memcpy(&st->speech_frame, frame, sizeof(gsm_frame));
+		st->rx_state = SPEECH;
+		return;
+	case 1:		/* invalid SID frame */
+		if (st->got_valid_sid) {
+			st->rx_state = COMFORT_NOISE;
+			gsmfr_preproc_gen_cn(st, frame);
+		} else {
+			st->rx_state = NO_DATA;
+			memcpy(frame, &gsmfr_preproc_silence_frame,
+				sizeof(gsm_frame));
+		}
+		return;
+	case 2:		/* valid SID frame */
+		st->got_valid_sid = 1;
+		memcpy(st->sid_prefix, frame, 5);
+		st->sid_xmaxc[0] = ((frame[6] & 0x1F) << 1) | (frame[7] >> 7);
+		st->sid_xmaxc[1] = ((frame[13] & 0x1F) << 1) | (frame[14] >> 7);
+		st->sid_xmaxc[2] = ((frame[20] & 0x1F) << 1) | (frame[21] >> 7);
+		st->sid_xmaxc[3] = ((frame[27] & 0x1F) << 1) | (frame[28] >> 7);
+		st->rx_state = COMFORT_NOISE;
+		gsmfr_preproc_gen_cn(st, frame);
+		return;
+	}
+}