changeset 606:bc57dcfa91d0

hrutil: new program gsmhr-etsi-dec
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 04 Dec 2025 21:36:51 +0000
parents 63f774192906
children cdf3f5c618b8
files .hgignore hrutil/Makefile hrutil/etsi-dec.c
diffstat 3 files changed, 91 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Thu Dec 04 21:01:46 2025 +0000
+++ b/.hgignore	Thu Dec 04 21:36:51 2025 +0000
@@ -88,6 +88,7 @@
 ^hrutil/gsmhr-dec-craft$
 ^hrutil/gsmhr-dec-parse$
 ^hrutil/gsmhr-dec2hex$
+^hrutil/gsmhr-etsi-dec$
 ^hrutil/gsmhr-hex2dec$
 ^hrutil/gsmhr-hex2rpf$
 ^hrutil/gsmhr-rpf2hex$
--- a/hrutil/Makefile	Thu Dec 04 21:01:46 2025 +0000
+++ b/hrutil/Makefile	Thu Dec 04 21:36:51 2025 +0000
@@ -1,6 +1,6 @@
 PROGS=	gsmhr-cod-craft gsmhr-cod-parse gsmhr-cod2hex gsmhr-dec-craft \
-	gsmhr-dec-parse gsmhr-dec2hex gsmhr-hex2dec gsmhr-hex2rpf gsmhr-rpf2hex\
-	gsmhr-tfo-xfrm tw5b-dump
+	gsmhr-dec-parse gsmhr-dec2hex gsmhr-etsi-dec gsmhr-hex2dec \
+	gsmhr-hex2rpf gsmhr-rpf2hex gsmhr-tfo-xfrm tw5b-dump
 LIBHR1=	../libgsmhr1/libgsmhr1.a
 LIBTEST=../libtest/libtest.a
 LIBS=	${LIBHR1} ${LIBTEST}
@@ -27,6 +27,9 @@
 gsmhr-dec2hex:	dec2hex.o read-dec.o ${LIBS}
 	${CC} ${CFLAGS} -o $@ $^
 
+gsmhr-etsi-dec:	etsi-dec.o etsi-pcm-out.o read-dec.o ${LIBS}
+	${CC} ${CFLAGS} -o $@ $^
+
 gsmhr-hex2dec:	hex2dec.o ${LIBS}
 	${CC} ${CFLAGS} -o $@ $^
 
@@ -42,6 +45,9 @@
 tw5b-dump:	print-frame.o tw5b-dump.o ${LIBS}
 	${CC} ${CFLAGS} -o $@ $^
 
+etsi-pcm-out.o:	../efrtest/etsi-pcm-out.c
+	${CC} ${CFLAGS} -c -o $@ $<
+
 install:
 	mkdir -p ${DESTDIR}${bindir}
 	install -c ${PROGS} ${DESTDIR}${bindir}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hrutil/etsi-dec.c	Thu Dec 04 21:36:51 2025 +0000
@@ -0,0 +1,82 @@
+/*
+ * gsmhr-etsi-dec is a test program for our GSM-HR decoder: it reads ETSI's
+ * .dec format as input and writes raw 16-bit PCM (same as ETSI's *.out)
+ * as output, allowing our decoder to be tested with ETSI's official test
+ * sequences.
+ *
+ * ETSI input and output files are read and written in the local machine's
+ * native byte order by default; -b and -l options can be used to force
+ * BE or LE, respectively.
+ */
+
+#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/local_endian.h"
+
+main(argc, argv)
+	char **argv;
+{
+	char *infname, *outfname;
+	FILE *inf, *outf;
+	int opt, rc, big_endian;
+	struct gsmhr_decoder_state *state;
+	unsigned frame_no;
+	int16_t params[GSMHR_NUM_PARAMS_DEC];
+	int16_t pcm[160];
+	extern int optind;
+
+	big_endian = is_native_big_endian();
+	while ((opt = getopt(argc, argv, "bl")) != EOF) {
+		switch (opt) {
+		case 'b':
+			big_endian = 1;
+			continue;
+		case 'l':
+			big_endian = 0;
+			continue;
+		default:
+		usage:
+			fprintf(stderr,
+				"usage: %s [-b|-l] input.dec output.out\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_decoder_create();
+	if (!state) {
+		perror("gsmhr_decoder_create()");
+		exit(1);
+	}
+	for (frame_no = 0; ; frame_no++) {
+		rc = read_dec_frame(inf, big_endian, params, infname, frame_no);
+		if (!rc)
+			break;
+		gsmhr_decode_frame(state, params, pcm);
+		if (big_endian)
+			write_pcm_be(outf, pcm);
+		else
+			write_pcm_le(outf, pcm);
+	}
+	fclose(outf);
+	exit(0);
+}