diff hrutil/etsi-dec.c @ 606:bc57dcfa91d0

hrutil: new program gsmhr-etsi-dec
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 04 Dec 2025 21:36:51 +0000
parents efrtest/etsi-dec.c@9f354d2aea13
children
line wrap: on
line diff
--- /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);
+}