changeset 629:32cc4b709e0e

hrutil: new program gsmhr-encode-r
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 12 Mar 2026 05:59:37 +0000
parents c53ce88d67a7
children f85ef5c4d044
files .hgignore hrutil/Makefile hrutil/encode-r.c
diffstat 3 files changed, 79 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Thu Mar 12 05:49:23 2026 +0000
+++ b/.hgignore	Thu Mar 12 05:59:37 2026 +0000
@@ -91,6 +91,7 @@
 ^hrutil/gsmhr-decode$
 ^hrutil/gsmhr-decode-r$
 ^hrutil/gsmhr-encode$
+^hrutil/gsmhr-encode-r$
 ^hrutil/gsmhr-etsi-dec$
 ^hrutil/gsmhr-etsi-enc$
 ^hrutil/gsmhr-hex2dec$
--- a/hrutil/Makefile	Thu Mar 12 05:49:23 2026 +0000
+++ b/hrutil/Makefile	Thu Mar 12 05:59:37 2026 +0000
@@ -1,7 +1,7 @@
 PROGS=	gsmhr-cod-craft gsmhr-cod-parse gsmhr-cod2hex gsmhr-dec-craft \
 	gsmhr-dec-parse gsmhr-dec2hex gsmhr-decode gsmhr-decode-r gsmhr-encode \
-	gsmhr-etsi-dec gsmhr-etsi-enc gsmhr-hex2dec gsmhr-hex2rpf gsmhr-rpf2hex\
-	gsmhr-tfo-xfrm gsmhr-tfo-xfrm-dc tw5b-dump
+	gsmhr-encode-r gsmhr-etsi-dec gsmhr-etsi-enc gsmhr-hex2dec \
+	gsmhr-hex2rpf gsmhr-rpf2hex gsmhr-tfo-xfrm gsmhr-tfo-xfrm-dc tw5b-dump
 LIBHR1=	../libgsmhr1/libgsmhr1.a
 LIBTEST=../libtest/libtest.a
 LIBS=	${LIBHR1} ${LIBTEST}
@@ -37,6 +37,9 @@
 gsmhr-encode:	encode.o tw5b-out-cod.o ${LIBS}
 	${CC} ${CFLAGS} -o $@ $^
 
+gsmhr-encode-r:	encode-r.o tw5b-out-cod.o ${LIBS}
+	${CC} ${CFLAGS} -o $@ $^
+
 gsmhr-etsi-dec:	etsi-dec.o etsi-pcm-out.o read-dec.o ${LIBS}
 	${CC} ${CFLAGS} -o $@ $^
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hrutil/encode-r.c	Thu Mar 12 05:59:37 2026 +0000
@@ -0,0 +1,73 @@
+/*
+ * This file is the main module for gsmhr-encode-r utility.  This utility
+ * is intended to serve as the "precision" speech encoder for GSM-HR,
+ * reading speech input in robe format and emitting GSM-HR output in
+ * TW-TS-005 Annex B hex format.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+#include "../libgsmhr1/tw_gsmhr.h"
+#include "../libtest/roberead.h"
+
+main(argc, argv)
+	char **argv;
+{
+	char *infname, *outfname;
+	FILE *inf, *outf;
+	struct gsmhr_encoder_state *state;
+	int16_t pcm[160];
+	int16_t prm_out[GSMHR_NUM_PARAMS_ENC];
+	int opt, rc, dtx = 0, emit_5993 = 0;
+	extern int optind;
+
+	while ((opt = getopt(argc, argv, "dx")) != EOF) {
+		switch (opt) {
+		case 'd':
+			dtx = 1;
+			continue;
+		case 'x':
+			emit_5993 = 1;
+			continue;
+		default:
+		usage:
+			fprintf(stderr,
+				"usage: %s [-d] [-x] input.robe output.hex\n",
+				argv[0]);
+			exit(1);
+		}
+	}
+	if (argc != optind + 2)
+		goto usage;
+	infname = argv[optind];
+	outfname = argv[optind+1];
+
+	inf = fopen(infname, "r");
+	if (!inf) {
+		perror(infname);
+		exit(1);
+	}
+	outf = fopen(outfname, "w");
+	if (!outf) {
+		perror(outfname);
+		exit(1);
+	}
+	state = gsmhr_encoder_create(dtx);
+	if (!state) {
+		perror("gsmhr_encoder_create()");
+		exit(1);
+	}
+	for (;;) {
+		rc = robe_get_pcm_block(inf, pcm);
+		if (!rc)
+			break;
+		gsmhr_encode_frame(state, pcm, prm_out);
+		emit_cod_to_tw5b(outf, prm_out, emit_5993);
+	}
+	fclose(outf);
+	exit(0);
+}