changeset 515:bb36ef735f25

hrutil: starting with gsmhr-cod-parse
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 30 Aug 2024 08:05:07 +0000
parents 67b13a6a63c9
children 5353d7652f65
files .hgignore hrutil/Makefile hrutil/cod-parse.c hrutil/print-frame.c hrutil/read-cod.c
diffstat 5 files changed, 134 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sun Aug 25 19:14:40 2024 +0000
+++ b/.hgignore	Fri Aug 30 08:05:07 2024 +0000
@@ -72,6 +72,8 @@
 ^frtest/gsmfr-encode-r$
 ^frtest/gsmfr-preproc$
 
+^hrutil/gsmhr-cod-parse$
+
 ^libgsmhr1/dhf_packed\.c$
 ^libgsmhr1/gen-dhf-pack$
 ^libgsmhr1/namespace\.h$
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hrutil/Makefile	Fri Aug 30 08:05:07 2024 +0000
@@ -0,0 +1,16 @@
+PROGS=	gsmhr-cod-parse
+LIBHR1=	../libgsmhr1/libgsmhr1.a
+
+include ../config.defs
+
+all:	${PROGS}
+
+gsmhr-cod-parse:	cod-parse.o print-frame.o read-cod.o ${LIBHR1}
+	${CC} ${CFLAGS} -o $@ $^
+
+install:
+	mkdir -p ${DESTDIR}${bindir}
+	install -c ${PROGS} ${DESTDIR}${bindir}
+
+clean:
+	rm -f *.o *.out ${PROGS}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hrutil/cod-parse.c	Fri Aug 30 08:05:07 2024 +0000
@@ -0,0 +1,46 @@
+/*
+ * This program reads an HRv1 *.cod file in ETSI test sequence format
+ * (encoder output 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_ENC];
+	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.cod\n", argv[0]);
+		exit(1);
+	}
+	inf = fopen(infname, "r");
+	if (!inf) {
+		perror(infname);
+		exit(1);
+	}
+	for (frame_no = 0; ; frame_no++) {
+		rc = read_cod_frame(inf, big_endian, params, infname, frame_no);
+		if (!rc)
+			break;
+		printf("#%u: VAD=%d SP=%d\n", frame_no, params[18], params[19]);
+		print_frame_params(params);
+	}
+	exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hrutil/print-frame.c	Fri Aug 30 08:05:07 2024 +0000
@@ -0,0 +1,22 @@
+/*
+ * Here we implement the common function that prints the parameters body
+ * of each GSM-HR codec frame, whichever file format we read it from.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+
+print_frame_params(params)
+	int16_t *params;
+{
+	printf("  R0=%02x LPC=%03x,%03x,%02x Int=%x Mode=%x\n", params[0],
+		params[1], params[2], params[3], params[4], params[5]);
+	printf(params[5] ? "  s1=%02x,%03x,%02x" : "  s1=%02x,%02x,%02x",
+		params[6], params[7], params[8]);
+	printf(params[5] ? " s2=%x,%03x,%02x" : " s2=%02x,%02x,%02x",
+		params[9], params[10], params[11]);
+	printf(params[5] ? " s3=%x,%03x,%02x" : " s3=%02x,%02x,%02x",
+		params[12], params[13], params[14]);
+	printf(params[5] ? " s4=%x,%03x,%02x\n" : " s4=%02x,%02x,%02x\n",
+		params[15], params[16], params[17]);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hrutil/read-cod.c	Fri Aug 30 08:05:07 2024 +0000
@@ -0,0 +1,48 @@
+/*
+ * In this module we implement the utility function for reading ETSI
+ * GSM-HR *.cod 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_cod_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_ENC * 2], *sp;
+	int cc;
+	unsigned n;
+	uint16_t val;
+
+	cc = fread(file_bytes, 2, GSMHR_NUM_PARAMS_ENC, inf);
+	if (cc == 0)
+		return 0;
+	if (cc != GSMHR_NUM_PARAMS_ENC) {
+		fprintf(stderr, "error: short read from %s\n",
+			filename_for_errs);
+		exit(1);
+	}
+	sp = file_bytes;
+	for (n = 0; n < GSMHR_NUM_PARAMS_ENC; 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_encoder_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;
+}