diff trau-ul-prep/efrdec2tsrc.c @ 22:8957383370c5

trau-ul-prep: implement efrdec2tsrc
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 23 Jun 2024 22:24:39 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trau-ul-prep/efrdec2tsrc.c	Sun Jun 23 22:24:39 2024 +0000
@@ -0,0 +1,84 @@
+/*
+ * This program reads an EFR *.dec file in ETSI test sequence format
+ * and converts it into ASCII source for TRAU-UL construction.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <unistd.h>
+#include <gsm_efr.h>
+#include "etsi.h"
+
+main(argc, argv)
+	char **argv;
+{
+	char *infname, *outfname;
+	FILE *inf, *outf;
+	int big_endian = 0;
+	unsigned frame_no;
+	uint8_t input_bits[ETSI_DEC_NWORDS], frame[EFR_RTP_FRAME_LEN];
+	int16_t params[EFR_NUM_PARAMS];
+	int rc, i, j, n;
+	extern int optind;
+
+	while ((rc = getopt(argc, argv, "b")) != EOF) {
+		switch (rc) {
+		case 'b':
+			big_endian = 1;
+			continue;
+		default:
+		usage:
+			fprintf(stderr,
+				"usage: %s [-b] input.dec [output.tsrc]\n",
+				argv[0]);
+			exit(1);
+		}
+	}
+	if (argc < optind + 1 || argc > optind + 2)
+		goto usage;
+	infname = argv[optind];
+	outfname = argv[optind+1];
+
+	inf = fopen(infname, "r");
+	if (!inf) {
+		perror(infname);
+		exit(1);
+	}
+	if (outfname) {
+		outf = fopen(outfname, "w");
+		if (!outf) {
+			perror(outfname);
+			exit(1);
+		}
+	} else
+		outf = stdout;
+	for (frame_no = 0; ; frame_no++) {
+		rc = read_etsi_bits(inf, big_endian, input_bits,
+				    ETSI_DEC_NWORDS, infname);
+		if (!rc)
+			break;
+		bits2frame(input_bits + 1, frame, infname, frame_no);
+		fprintf(outf, "# input frame %u\nFrame_EFR {\n", frame_no);
+		if (input_bits[246])
+			fputs("\t# TAF position\n", outf);
+		fprintf(outf, "\tBFI %u\n", input_bits[0]);
+		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", input_bits[245]);
+		fputs("}\n\n", outf);
+	}
+	exit(0);
+}