changeset 26:f80e64139670

trau-ul-decomp program written
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 24 Jun 2024 01:50:02 +0000
parents 118a4e4268b2
children f508dacf2cf9
files .hgignore trau-ul-compile/Makefile trau-ul-compile/trau-ul-decomp.c
diffstat 3 files changed, 105 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon Jun 24 01:12:22 2024 +0000
+++ b/.hgignore	Mon Jun 24 01:50:02 2024 +0000
@@ -12,6 +12,7 @@
 ^trau-files/.*\.wav$
 
 ^trau-ul-compile/trau-ul-compile$
+^trau-ul-compile/trau-ul-decomp$
 
 ^trau-ul-prep/efrdec2tsrc$
 ^trau-ul-prep/gsmx2tsrc$
--- a/trau-ul-compile/Makefile	Mon Jun 24 01:12:22 2024 +0000
+++ b/trau-ul-compile/Makefile	Mon Jun 24 01:50:02 2024 +0000
@@ -1,11 +1,14 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	trau-ul-compile
+PROGS=	trau-ul-compile trau-ul-decomp
 
 all:	${PROGS}
 
 trau-ul-compile:	trau-ul-compile.c
 	${CC} ${CFLAGS} -o $@ $@.c -lgsmfr2 -lgsmefr
 
+trau-ul-decomp:	trau-ul-decomp.c
+	${CC} ${CFLAGS} -o $@ $@.c -lgsmfr2 -lgsmefr
+
 clean:
 	rm -f *.o ${PROGS}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trau-ul-compile/trau-ul-decomp.c	Mon Jun 24 01:50:02 2024 +0000
@@ -0,0 +1,100 @@
+/*
+ * This program reads a *.tul binary file and disassembles it back
+ * to ASCII form.  It is intended for checking the correctness of
+ * trau-ul-compile, and also for sanity checks during actual TRAU
+ * testing with these tools.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <tw_gsmfr.h>
+#include <gsm_efr.h>
+
+main(argc, argv)
+	char **argv;
+{
+	FILE *binf, *outf;
+	unsigned frame_index;
+	uint8_t frame[34];
+	int16_t params[GSMFR_NUM_PARAMS];
+	int rc, i, j, n;
+
+	if (argc < 2 || argc > 3) {
+		fprintf(stderr, "usage: %s input.tul [output.tsrc]\n",
+			argv[0]);
+		exit(1);
+	}
+	binf = fopen(argv[1], "r");
+	if (!binf) {
+		perror(argv[1]);
+		exit(1);
+	}
+	if (argc > 2) {
+		outf = fopen(argv[2], "w");
+		if (!outf) {
+			perror(argv[2]);
+			exit(1);
+		}
+	} else
+		outf = stdout;
+	for (frame_index = 0; ; frame_index++) {
+		rc = fread(frame, 1, 34, binf);
+		if (!rc)
+			break;
+		if (rc != 34) {
+inv_input:		fprintf(stderr, "error: %s is not in expected format\n",
+				argv[1]);
+			exit(1);
+		}
+		switch (frame[0] & 0xF0) {
+		case 0xC0:
+			fprintf(outf, "# input frame %u\nFrame_EFR {\n",
+				frame_index);
+			if (frame_index % 24 == 23)
+				fputs("\t# TAF position\n", outf);
+			fprintf(outf, "\tBFI %u\n", frame[33] >> 7);
+			EFR_frame2params(frame, params);
+			n = 0;
+			fputs("\tLPC", outf);
+			for (i = 0; i < 5; i++)
+				fprintf(outf, " %d", params[n++]);
+			putc('\n', outf);
+			for (i = 0; i < 4; i++) {
+				fputs("\tsf", outf);
+				for (j = 0; j < 13; j++)
+					fprintf(outf, " %d", params[n++]);
+				putc('\n', outf);
+			}
+			fprintf(outf, "\tSID %u\n", frame[33] & 3);
+			fputs("}\n\n", outf);
+			break;
+		case 0xD0:
+			fprintf(outf, "# input frame %u\nFrame_FR {\n",
+				frame_index);
+			if (frame_index % 24 == 23)
+				fputs("\t# TAF position\n", outf);
+			fprintf(outf, "\tBFI %u\n", frame[33] >> 7);
+			gsmfr_unpack_to_array(frame, params);
+			n = 0;
+			fputs("\tLARc", outf);
+			for (i = 0; i < 8; i++)
+				fprintf(outf, " %d", params[n++]);
+			putc('\n', outf);
+			for (i = 0; i < 4; i++) {
+				fputs("\tsf", outf);
+				for (j = 0; j < 17; j++)
+					fprintf(outf, " %d", params[n++]);
+				putc('\n', outf);
+			}
+			fprintf(outf, "\tSID %u\n", frame[33] & 3);
+			fputs("}\n\n", outf);
+			break;
+		default:
+			goto inv_input;
+		}
+	}
+	exit(0);
+}