changeset 259:bebae251e5ee

libgsmfr2: implement gsmfr_pack_from_array()
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Apr 2024 22:48:50 +0000
parents c344b4f35eb7
children f0220c141d2c
files libgsmfr2/Makefile libgsmfr2/pack_frame2.c libgsmfr2/tw_gsmfr.h
diffstat 3 files changed, 61 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libgsmfr2/Makefile	Fri Apr 12 22:30:24 2024 +0000
+++ b/libgsmfr2/Makefile	Fri Apr 12 22:48:50 2024 +0000
@@ -1,7 +1,7 @@
 CC=	gcc
 CFLAGS=	-O2
-OBJS=	comfort_noise.o pack_frame.o pp_bad.o pp_good.o pp_state.o prng.o \
-	sidclass.o silence_frame.o xmaxc_mean.o
+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
 HDRS=	pp_internal.h tw_gsmfr.h
 LIB=	libgsmfr2.a
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgsmfr2/pack_frame2.c	Fri Apr 12 22:48:50 2024 +0000
@@ -0,0 +1,54 @@
+/*
+ * This module holds our gsmfr_pack_from_array() function: a drop-in
+ * replacement for gsm_implode() from classic libgsm.
+ */
+
+#include <stdint.h>
+#include "tw_gsmfr.h"
+
+#define	GSM_FR_MAGIC	0xD
+
+void gsmfr_pack_from_array(const int16_t *params, uint8_t *frame)
+{
+	uint8_t *c = frame;
+	unsigned sub;
+
+	*c++ =   (GSM_FR_MAGIC << 4)
+	       | ((params[0] >> 2) & 0xF);
+	*c++ =   ((params[0] & 0x3) << 6)
+	       | (params[1] & 0x3F);
+	*c++ =   ((params[2] & 0x1F) << 3)
+	       | ((params[3] >> 2) & 0x7);
+	*c++ =   ((params[3] & 0x3) << 6)
+	       | ((params[4] & 0xF) << 2)
+	       | ((params[5] >> 2) & 0x3);
+	*c++ =   ((params[5] & 0x3) << 6)
+	       | ((params[6] & 0x7) << 3)
+	       | (params[7] & 0x7);
+	params += 8;
+	for (sub = 0; sub < 4; sub++) {
+		*c++ =   ((params[0] & 0x7F) << 1)
+		       | ((params[1] >> 1) & 0x1);
+		*c++ =   ((params[1] & 0x1) << 7)
+		       | ((params[2] & 0x3) << 5)
+		       | ((params[3] >> 1) & 0x1F);
+		*c++ =   ((params[3] & 0x1) << 7)
+		       | ((params[4] & 0x7) << 4)
+		       | ((params[5] & 0x7) << 1)
+		       | ((params[6] >> 2) & 0x1);
+		*c++ =   ((params[6] & 0x3) << 6)
+		       | ((params[7] & 0x7) << 3)
+		       | (params[8] & 0x7);
+		*c++ =   ((params[9] & 0x7) << 5)
+		       | ((params[10] & 0x7) << 2)
+		       | ((params[11] >> 1) & 0x3);
+		*c++ =   ((params[11] & 0x1) << 7)
+		       | ((params[12] & 0x7) << 4)
+		       | ((params[13] & 0x7) << 1)
+		       | ((params[14] >> 2) & 0x1);
+		*c++ =   ((params[14] & 0x3) << 6)
+		       | ((params[15] & 0x7) << 3)
+		       | (params[16] & 0x7);
+		params += 17;
+	}
+}
--- a/libgsmfr2/tw_gsmfr.h	Fri Apr 12 22:30:24 2024 +0000
+++ b/libgsmfr2/tw_gsmfr.h	Fri Apr 12 22:48:50 2024 +0000
@@ -66,6 +66,11 @@
 void gsmfr_pack_frame(const struct gsmfr_param_frame *param, uint8_t *frame);
 void gsmfr_unpack_frame(const uint8_t *frame, struct gsmfr_param_frame *param);
 
+/* similar conversions with a linear array of params */
+
+void gsmfr_pack_from_array(const int16_t *params, uint8_t *frame);
+void gsmfr_unpack_to_array(const uint8_t *frame, int16_t *params);
+
 /* Rx DTX handler preprocessor portion of the library */
 
 struct gsmfr_preproc_state;	/* opaque to external users */