changeset 517:2d703e1e9107

hrutil: implement gsmhr-dec-parse
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 30 Aug 2024 08:27:05 +0000
parents 5353d7652f65
children 087a88d25ba2
files .hgignore hrutil/Makefile hrutil/dec-parse.c hrutil/read-dec.c
diffstat 4 files changed, 100 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Aug 30 08:15:41 2024 +0000
+++ b/.hgignore	Fri Aug 30 08:27:05 2024 +0000
@@ -73,6 +73,7 @@
 ^frtest/gsmfr-preproc$
 
 ^hrutil/gsmhr-cod-parse$
+^hrutil/gsmhr-dec-parse$
 
 ^libgsmhr1/dhf_packed\.c$
 ^libgsmhr1/gen-dhf-pack$
--- a/hrutil/Makefile	Fri Aug 30 08:15:41 2024 +0000
+++ b/hrutil/Makefile	Fri Aug 30 08:27:05 2024 +0000
@@ -1,4 +1,4 @@
-PROGS=	gsmhr-cod-parse
+PROGS=	gsmhr-cod-parse gsmhr-dec-parse
 LIBHR1=	../libgsmhr1/libgsmhr1.a
 
 include ../config.defs
@@ -8,6 +8,9 @@
 gsmhr-cod-parse:	cod-parse.o print-frame.o read-cod.o ${LIBHR1}
 	${CC} ${CFLAGS} -o $@ $^
 
+gsmhr-dec-parse:	dec-parse.o print-frame.o read-dec.o ${LIBHR1}
+	${CC} ${CFLAGS} -o $@ $^
+
 install:
 	mkdir -p ${DESTDIR}${bindir}
 	install -c ${PROGS} ${DESTDIR}${bindir}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hrutil/dec-parse.c	Fri Aug 30 08:27:05 2024 +0000
@@ -0,0 +1,47 @@
+/*
+ * This program reads an HRv1 *.dec file in ETSI test sequence format
+ * (decoder input format) and displays its content in human-readable form.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "../libgsmhr1/tw_gsmhr.h"
+
+main(argc, argv)
+	char **argv;
+{
+	char *infname;
+	FILE *inf;
+	int big_endian;
+	unsigned frame_no;
+	int16_t params[GSMHR_NUM_PARAMS_DEC];
+	int rc;
+
+	if (argc == 2 && argv[1][0] != '-') {
+		big_endian = 0;
+		infname = argv[1];
+	} else if (argc == 3 && !strcmp(argv[1], "-b")) {
+		big_endian = 1;
+		infname = argv[2];
+	} else {
+		fprintf(stderr, "usage: %s [-b] file.dec\n", argv[0]);
+		exit(1);
+	}
+	inf = fopen(infname, "r");
+	if (!inf) {
+		perror(infname);
+		exit(1);
+	}
+	for (frame_no = 0; ; frame_no++) {
+		rc = read_dec_frame(inf, big_endian, params, infname, frame_no);
+		if (!rc)
+			break;
+		printf("#%u: BFI=%d UFI=%d SID=%d TAF=%d\n", frame_no,
+			params[18], params[19], params[20], params[21]);
+		print_frame_params(params);
+	}
+	exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hrutil/read-dec.c	Fri Aug 30 08:27:05 2024 +0000
@@ -0,0 +1,48 @@
+/*
+ * In this module we implement the utility function for reading ETSI
+ * GSM-HR *.dec files in either LE or BE format.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "../libgsmhr1/tw_gsmhr.h"
+
+read_dec_frame(inf, big_endian, params, filename_for_errs, frame_no)
+	FILE *inf;
+	int16_t *params;
+	char *filename_for_errs;
+	unsigned frame_no;
+{
+	uint8_t file_bytes[GSMHR_NUM_PARAMS_DEC * 2], *sp;
+	int cc;
+	unsigned n;
+	uint16_t val;
+
+	cc = fread(file_bytes, 2, GSMHR_NUM_PARAMS_DEC, inf);
+	if (cc == 0)
+		return 0;
+	if (cc != GSMHR_NUM_PARAMS_DEC) {
+		fprintf(stderr, "error: short read from %s\n",
+			filename_for_errs);
+		exit(1);
+	}
+	sp = file_bytes;
+	for (n = 0; n < GSMHR_NUM_PARAMS_DEC; n++) {
+		if (big_endian)
+			val = ((uint16_t) sp[0] << 8) | ((uint16_t) sp[1]);
+		else
+			val = ((uint16_t) sp[1] << 8) | ((uint16_t) sp[0]);
+		params[n] = val;
+		sp += 2;
+	}
+	if (gsmhr_check_decoder_params(params) < 0) {
+		fprintf(stderr,
+			"error in %s frame #%u: wrong format or wrong endian\n",
+			filename_for_errs, frame_no);
+		exit(1);
+	}
+	return 1;
+}