changeset 490:4d80730683d4

libgsmhr1: implement TS 101 318 packing and unpacking
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 15 Jun 2024 05:33:35 +0000
parents f036e1de5b05
children 45bf34451dd7
files libgsmhr1/Makefile libgsmhr1/bitter-unvoiced libgsmhr1/bitter-voiced libgsmhr1/pack_frame.c libgsmhr1/unpack_frame.c
diffstat 5 files changed, 227 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgsmhr1/Makefile	Sat Jun 15 05:33:35 2024 +0000
@@ -0,0 +1,22 @@
+OBJS=	pack_frame.o unpack_frame.o
+HDRS=	tw_gsmhr.h
+LIB=	libgsmhr1.a
+
+include ../config.defs
+
+all:	${LIB}
+
+${OBJS}:	${HDRS}
+
+${LIB}:	${OBJS}
+	ar rcu $@ ${OBJS}
+	ranlib $@
+
+install:
+#	mkdir -p ${DESTDIR}${includedir}
+#	install -c -m 444 tw_gsmhr.h ${DESTDIR}${includedir}
+#	mkdir -p ${DESTDIR}${libdir}
+#	install -c -m 444 ${LIB} ${DESTDIR}${libdir}
+
+clean:
+	rm -f *.[oa] errs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgsmhr1/bitter-unvoiced	Sat Jun 15 05:33:35 2024 +0000
@@ -0,0 +1,30 @@
+; This file is an input to the old 'bitter' utility from libgsm source
+; package; it will be used to generate C code for TS 101 318 packing and
+; unpacking.  This version is for unvoiced mode.
+
+params[0]	5	; R0
+params[1]	11	; LPC1
+params[2]	9	; LPC2
+params[3]	8	; LPC3
+params[4]	1	; INT LPC
+params[5]	2	; Mode
+
+; subframe 1
+params[6]	7
+params[7]	7
+params[8]	5
+
+; subframe 2
+params[9]	7
+params[10]	7
+params[11]	5
+
+; subframe 3
+params[12]	7
+params[13]	7
+params[14]	5
+
+; subframe 4
+params[15]	7
+params[16]	7
+params[17]	5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgsmhr1/bitter-voiced	Sat Jun 15 05:33:35 2024 +0000
@@ -0,0 +1,30 @@
+; This file is an input to the old 'bitter' utility from libgsm source
+; package; it will be used to generate C code for TS 101 318 packing and
+; unpacking.  This version is for voiced modes.
+
+params[0]	5	; R0
+params[1]	11	; LPC1
+params[2]	9	; LPC2
+params[3]	8	; LPC3
+params[4]	1	; INT LPC
+params[5]	2	; Mode
+
+; subframe 1
+params[6]	8
+params[7]	9
+params[8]	5
+
+; subframe 2
+params[9]	4
+params[10]	9
+params[11]	5
+
+; subframe 3
+params[12]	4
+params[13]	9
+params[14]	5
+
+; subframe 4
+params[15]	4
+params[16]	9
+params[17]	5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgsmhr1/pack_frame.c	Sat Jun 15 05:33:35 2024 +0000
@@ -0,0 +1,77 @@
+/*
+ * This module holds our gsmhr_pack_ts101318() function: packing a single
+ * GSM-HR codec frame from an array of broken-down parameters into TS 101 318
+ * format.
+ */
+
+#include <stdint.h>
+#include "tw_gsmhr.h"
+
+void gsmhr_pack_ts101318(const int16_t *params, uint8_t *payload)
+{
+	uint8_t *c = payload;
+
+	if (params[5]) {
+		/* voiced modes */
+		*c++ =   ((params[0] & 0x1F) << 3)
+		       | ((params[1] >> 8) & 0x7);
+		*c++ =   params[1] & 0xFF;
+		*c++ =   ((params[2] >> 1) & 0xFF);
+		*c++ =   ((params[2] & 0x1) << 7)
+		       | ((params[3] >> 1) & 0x7F);
+		*c++ =   ((params[3] & 0x1) << 7)
+		       | ((params[4] & 0x1) << 6)
+		       | ((params[5] & 0x3) << 4)
+		       | ((params[6] >> 4) & 0xF);
+		*c++ =   ((params[6] & 0xF) << 4)
+		       | ((params[7] >> 5) & 0xF);
+		*c++ =   ((params[7] & 0x1F) << 3)
+		       | ((params[8] >> 2) & 0x7);
+		*c++ =   ((params[8] & 0x3) << 6)
+		       | ((params[9] & 0xF) << 2)
+		       | ((params[10] >> 7) & 0x3);
+		*c++ =   ((params[10] & 0x7F) << 1)
+		       | ((params[11] >> 4) & 0x1);
+		*c++ =   ((params[11] & 0xF) << 4)
+		       | (params[12] & 0xF);
+		*c++ =   ((params[13] >> 1) & 0xFF);
+		*c++ =   ((params[13] & 0x1) << 7)
+		       | ((params[14] & 0x1F) << 2)
+		       | ((params[15] >> 2) & 0x3);
+		*c++ =   ((params[15] & 0x3) << 6)
+		       | ((params[16] >> 3) & 0x3F);
+		*c++ =   ((params[16] & 0x7) << 5)
+		       | (params[17] & 0x1F);
+	} else {
+		/* unvoiced modes */
+		*c++ =   ((params[0] & 0x1F) << 3)
+		       | ((params[1] >> 8) & 0x7);
+		*c++ =   params[1] & 0xFF;
+		*c++ =   ((params[2] >> 1) & 0xFF);
+		*c++ =   ((params[2] & 0x1) << 7)
+		       | ((params[3] >> 1) & 0x7F);
+		*c++ =   ((params[3] & 0x1) << 7)
+		       | ((params[4] & 0x1) << 6)
+		       | ((params[5] & 0x3) << 4)
+		       | ((params[6] >> 3) & 0xF);
+		*c++ =   ((params[6] & 0x7) << 5)
+		       | ((params[7] >> 2) & 0x1F);
+		*c++ =   ((params[7] & 0x3) << 6)
+		       | ((params[8] & 0x1F) << 1)
+		       | ((params[9] >> 6) & 0x1);
+		*c++ =   ((params[9] & 0x3F) << 2)
+		       | ((params[10] >> 5) & 0x3);
+		*c++ =   ((params[10] & 0x1F) << 3)
+		       | ((params[11] >> 2) & 0x7);
+		*c++ =   ((params[11] & 0x3) << 6)
+		       | ((params[12] >> 1) & 0x3F);
+		*c++ =   ((params[12] & 0x1) << 7)
+		       | (params[13] & 0x7F);
+		*c++ =   ((params[14] & 0x1F) << 3)
+		       | ((params[15] >> 4) & 0x7);
+		*c++ =   ((params[15] & 0xF) << 4)
+		       | ((params[16] >> 3) & 0xF);
+		*c++ =   ((params[16] & 0x7) << 5)
+		       | (params[17] & 0x1F);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgsmhr1/unpack_frame.c	Sat Jun 15 05:33:35 2024 +0000
@@ -0,0 +1,68 @@
+/*
+ * This module holds our gsmhr_unpack_ts101318() function: unpacking a single
+ * GSM-HR codec frame from TS 101 318 packed format into the codec's native
+ * array of parameters.
+ */
+
+#include <stdint.h>
+#include "tw_gsmhr.h"
+
+void gsmhr_unpack_ts101318(const uint8_t *payload, int16_t *params)
+{
+	const uint8_t *c = payload;
+
+	params[0]  = (*c >> 3) & 0x1F;
+	params[1]  = (*c++ & 0x7) << 8;
+	params[1] |= *c++;
+	params[2]  = (*c++ & 0xFF) << 1;
+	params[2] |= (*c >> 7) & 0x1;
+	params[3]  = (*c++ & 0x7F) << 1;
+	params[3] |= (*c >> 7) & 0x1;
+	params[4]  = (*c >> 6) & 0x1;
+	params[5]  = (*c >> 4) & 0x3;
+	if (params[5]) {
+		/* voiced modes */
+		params[6]  = (*c++ & 0xF) << 4;
+		params[6] |= (*c >> 4) & 0xF;
+		params[7]  = (*c++ & 0xF) << 5;
+		params[7] |= (*c >> 3) & 0x1F;
+		params[8]  = (*c++ & 0x7) << 2;
+		params[8] |= (*c >> 6) & 0x3;
+		params[9]  = (*c >> 2) & 0xF;
+		params[10]  = (*c++ & 0x3) << 7;
+		params[10] |= (*c >> 1) & 0x7F;
+		params[11]  = (*c++ & 0x1) << 4;
+		params[11] |= (*c >> 4) & 0xF;
+		params[12]  = *c++ & 0xF;
+		params[13]  = (*c++ & 0xFF) << 1;
+		params[13] |= (*c >> 7) & 0x1;
+		params[14]  = (*c >> 2) & 0x1F;
+		params[15]  = (*c++ & 0x3) << 2;
+		params[15] |= (*c >> 6) & 0x3;
+		params[16]  = (*c++ & 0x3F) << 3;
+		params[16] |= (*c >> 5) & 0x7;
+		params[17]  = *c++ & 0x1F;
+	} else {
+		/* unvoiced modes */
+		params[6]  = (*c++ & 0xF) << 3;
+		params[6] |= (*c >> 5) & 0x7;
+		params[7]  = (*c++ & 0x1F) << 2;
+		params[7] |= (*c >> 6) & 0x3;
+		params[8]  = (*c >> 1) & 0x1F;
+		params[9]  = (*c++ & 0x1) << 6;
+		params[9] |= (*c >> 2) & 0x3F;
+		params[10]  = (*c++ & 0x3) << 5;
+		params[10] |= (*c >> 3) & 0x1F;
+		params[11]  = (*c++ & 0x7) << 2;
+		params[11] |= (*c >> 6) & 0x3;
+		params[12]  = (*c++ & 0x3F) << 1;
+		params[12] |= (*c >> 7) & 0x1;
+		params[13]  = *c++ & 0x7F;
+		params[14]  = (*c >> 3) & 0x1F;
+		params[15]  = (*c++ & 0x7) << 4;
+		params[15] |= (*c >> 4) & 0xF;
+		params[16]  = (*c++ & 0xF) << 3;
+		params[16] |= (*c >> 5) & 0x7;
+		params[17]  = *c++ & 0x1F;
+	}
+}