changeset 260:f0220c141d2c

libgsmfr2: implement gsmfr_unpack_frame()
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Apr 2024 23:09:23 +0000
parents bebae251e5ee
children cfcb3ce9c778
files libgsmfr2/Makefile libgsmfr2/unpack_frame.c
diffstat 2 files changed, 50 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libgsmfr2/Makefile	Fri Apr 12 22:48:50 2024 +0000
+++ b/libgsmfr2/Makefile	Fri Apr 12 23:09:23 2024 +0000
@@ -1,7 +1,7 @@
 CC=	gcc
 CFLAGS=	-O2
 OBJS=	comfort_noise.o pack_frame.o pack_frame2.o pp_bad.o pp_good.o \
-	pp_state.o prng.o sidclass.o silence_frame.o xmaxc_mean.o
+	pp_state.o prng.o sidclass.o silence_frame.o unpack_frame.o xmaxc_mean.o
 HDRS=	pp_internal.h tw_gsmfr.h
 LIB=	libgsmfr2.a
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgsmfr2/unpack_frame.c	Fri Apr 12 23:09:23 2024 +0000
@@ -0,0 +1,49 @@
+/*
+ * This module holds our gsmfr_unpack_frame() function: unpacking a single
+ * GSM-FR frame from libgsm/RTP format into a broken-down struct of params.
+ */
+
+#include <stdint.h>
+#include "tw_gsmfr.h"
+
+void gsmfr_unpack_frame(const uint8_t *frame, struct gsmfr_param_frame *param)
+{
+	const uint8_t *c = frame;
+	unsigned sub;
+
+	param->LARc[0]  = (*c++ & 0xF) << 2;
+	param->LARc[0] |= (*c >> 6) & 0x3;
+	param->LARc[1]  = *c++ & 0x3F;
+	param->LARc[2]  = (*c >> 3) & 0x1F;
+	param->LARc[3]  = (*c++ & 0x7) << 2;
+	param->LARc[3] |= (*c >> 6) & 0x3;
+	param->LARc[4]  = (*c >> 2) & 0xF;
+	param->LARc[5]  = (*c++ & 0x3) << 2;
+	param->LARc[5] |= (*c >> 6) & 0x3;
+	param->LARc[6]  = (*c >> 3) & 0x7;
+	param->LARc[7]  = *c++ & 0x7;
+	for (sub = 0; sub < 4; sub++) {
+		param->Nc[sub]  = (*c >> 1) & 0x7F;
+		param->bc[sub]  = (*c++ & 0x1) << 1;
+		param->bc[sub] |= (*c >> 7) & 0x1;
+		param->Mc[sub]  = (*c >> 5) & 0x3;
+		param->xmaxc[sub]  = (*c++ & 0x1F) << 1;
+		param->xmaxc[sub] |= (*c >> 7) & 0x1;
+		param->xMc[sub][0]  = (*c >> 4) & 0x7;
+		param->xMc[sub][1]  = (*c >> 1) & 0x7;
+		param->xMc[sub][2]  = (*c++ & 0x1) << 2;
+		param->xMc[sub][2] |= (*c >> 6) & 0x3;
+		param->xMc[sub][3]  = (*c >> 3) & 0x7;
+		param->xMc[sub][4]  = *c++ & 0x7;
+		param->xMc[sub][5]  = (*c >> 5) & 0x7;
+		param->xMc[sub][6]  = (*c >> 2) & 0x7;
+		param->xMc[sub][7]  = (*c++ & 0x3) << 1;
+		param->xMc[sub][7] |= (*c >> 7) & 0x1;
+		param->xMc[sub][8]  = (*c >> 4) & 0x7;
+		param->xMc[sub][9]  = (*c >> 1) & 0x7;
+		param->xMc[sub][10]  = (*c++ & 0x1) << 2;
+		param->xMc[sub][10] |= (*c >> 6) & 0x3;
+		param->xMc[sub][11]  = (*c >> 3) & 0x7;
+		param->xMc[sub][12]  = *c++ & 0x7;
+	}
+}