diff libgsmfr2/unpack_frame.c @ 260:f0220c141d2c

libgsmfr2: implement gsmfr_unpack_frame()
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Apr 2024 23:09:23 +0000
parents libgsmfr2/pack_frame.c@c344b4f35eb7
children
line wrap: on
line diff
--- /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;
+	}
+}