changeset 276:e4ca04586118

dev/gsm0611-silence-fr: rework to eliminate libgsm dependency
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Apr 2024 03:38:09 +0000
parents 5fbb323b2978
children 37dc5c84bbe9
files dev/Makefile dev/gsm0611-silence-fr.c dev/pack_gsmfr_rtp.c
diffstat 3 files changed, 76 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/dev/Makefile	Sun Apr 14 03:06:03 2024 +0000
+++ b/dev/Makefile	Sun Apr 14 03:38:09 2024 +0000
@@ -32,8 +32,8 @@
 efr-tidsp.out:	efr-tidsp
 	./efr-tidsp > $@
 
-gsm0611-silence-fr:	gsm0611-silence-fr.c
-	${CC} ${CFLAGS} -o $@ $@.c -lgsm
+gsm0611-silence-fr:	gsm0611-silence-fr.o pack_gsmfr_rtp.o
+	${CC} ${CFLAGS} -o $@ $@.o pack_gsmfr_rtp.o
 
 gsm0611-silence-fr.out:	gsm0611-silence-fr
 	./gsm0611-silence-fr > $@
--- a/dev/gsm0611-silence-fr.c	Sun Apr 14 03:06:03 2024 +0000
+++ b/dev/gsm0611-silence-fr.c	Sun Apr 14 03:38:09 2024 +0000
@@ -3,40 +3,39 @@
  * libgsm function gsm_implode() to transform the idle frame of GSM 06.11
  * (3GPP TS 46.011) from the table format given in the spec into
  * libgsm/RTP format.
+ *
+ * Later update: this program has been reworked to use the local function
+ * in pack_gsmfr_rtp.c instead of gsm_implode(), in order to eliminate
+ * all build dependencies on old libgsm.
  */
 
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <strings.h>
-#include <gsm.h>
+
+extern void gsmfr_pack_to_rtp(const int16_t *params, uint8_t *frame);
 
-static const gsm_signal lar_params[8] = {42, 39, 21, 10, 9, 4, 3, 2};
-static const gsm_signal subframe_params[17] =
+static const int16_t lar_params[8] = {42, 39, 21, 10, 9, 4, 3, 2};
+static const int16_t subframe_params[17] =
 	{40, 0, 1, 0,  3, 4, 3, 4, 4,  3, 3, 3, 3, 4, 4, 3, 3};
 
 main(argc, argv)
 	char **argv;
 {
-	gsm state;
-	gsm_signal params[76];
-	gsm_byte frame[33];
+	int16_t params[76];
+	uint8_t frame[33];
 	unsigned n;
 
-	/* gsm_implode() requires dummy state */
-	state = gsm_create();
-	if (!state) {
-		fprintf(stderr, "gsm_create() failed!\n");
-		exit(1);
-	}
 	/* gather params */
-	bcopy(lar_params, params, sizeof(gsm_signal) * 8);
-	bcopy(subframe_params, params + 8, sizeof(gsm_signal) * 17);
-	bcopy(subframe_params, params + 25, sizeof(gsm_signal) * 17);
-	bcopy(subframe_params, params + 42, sizeof(gsm_signal) * 17);
-	bcopy(subframe_params, params + 59, sizeof(gsm_signal) * 17);
+	bcopy(lar_params, params, sizeof(int16_t) * 8);
+	bcopy(subframe_params, params + 8, sizeof(int16_t) * 17);
+	bcopy(subframe_params, params + 25, sizeof(int16_t) * 17);
+	bcopy(subframe_params, params + 42, sizeof(int16_t) * 17);
+	bcopy(subframe_params, params + 59, sizeof(int16_t) * 17);
 	/* generate frame */
-	gsm_implode(state, params, frame);
+	gsmfr_pack_to_rtp(params, frame);
 	/* print the frame */
 	for (n = 0; n < 33; n++) {
 		printf("0x%02X,", frame[n]);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dev/pack_gsmfr_rtp.c	Sun Apr 14 03:38:09 2024 +0000
@@ -0,0 +1,57 @@
+/*
+ * The function in this development-only module is a copy of
+ * gsmfr_pack_from_array() from work-in-progress libgsmfr2, which in turn
+ * was created to serve as a drop-in replacement for gsm_implode()
+ * from classic libgsm.  The function is copied here to avoid the
+ * philosophical problem of libgsmfr2 being a dependency for developer aid
+ * programs used in the development of that library.
+ */
+
+#include <stdint.h>
+
+#define	GSM_FR_MAGIC	0xD
+
+void gsmfr_pack_to_rtp(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;
+	}
+}