changeset 239:b8e095a9e360

efrtest: new program gsmefr-cod2gsmx
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 08 May 2023 07:19:26 +0000
parents de1b52304d26
children 3aeb33d835ad
files .hgignore efrtest/Makefile efrtest/cod2gsmx.c
diffstat 3 files changed, 65 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon May 08 05:21:12 2023 +0000
+++ b/.hgignore	Mon May 08 07:19:26 2023 +0000
@@ -30,6 +30,7 @@
 ^dev/u2s-regen\.out$
 
 ^efrtest/gsmefr-cod-parse$
+^efrtest/gsmefr-cod2gsmx$
 ^efrtest/gsmefr-dec-parse$
 ^efrtest/gsmefr-decode$
 ^efrtest/gsmefr-decode-r$
--- a/efrtest/Makefile	Mon May 08 05:21:12 2023 +0000
+++ b/efrtest/Makefile	Mon May 08 07:19:26 2023 +0000
@@ -1,8 +1,9 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	gsmefr-cod-parse gsmefr-dec-parse gsmefr-decode gsmefr-decode-r \
-	gsmefr-dlcap-dec gsmefr-dlcap-gsmx gsmefr-dlcap-parse gsmefr-encode \
-	gsmefr-encode-r gsmefr-etsi-dec gsmefr-etsi-enc gsmefr-rec2etsi
+PROGS=	gsmefr-cod-parse gsmefr-cod2gsmx gsmefr-dec-parse gsmefr-decode \
+	gsmefr-decode-r gsmefr-dlcap-dec gsmefr-dlcap-gsmx gsmefr-dlcap-parse \
+	gsmefr-encode gsmefr-encode-r gsmefr-etsi-dec gsmefr-etsi-enc \
+	gsmefr-rec2etsi
 LIBEFR=	../libgsmefr/libgsmefr.a
 LIBTEST=../libtest/libtest.a
 INSTBIN=/opt/freecalypso/bin
@@ -12,6 +13,9 @@
 gsmefr-cod-parse:	cod-parse.o etsi-bit-rd.o ${LIBEFR}
 	${CC} ${CFLAGS} -o $@ cod-parse.o etsi-bit-rd.o ${LIBEFR}
 
+gsmefr-cod2gsmx:	cod2gsmx.o etsi-bit-rd.o
+	${CC} ${CFLAGS} -o $@ cod2gsmx.o etsi-bit-rd.o
+
 gsmefr-dec-parse:	dec-parse.o etsi-bit-rd.o ${LIBEFR}
 	${CC} ${CFLAGS} -o $@ dec-parse.o etsi-bit-rd.o ${LIBEFR}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/efrtest/cod2gsmx.c	Mon May 08 07:19:26 2023 +0000
@@ -0,0 +1,57 @@
+/*
+ * This program reads an EFR *.cod file in ETSI test sequence format
+ * and converts it into Themyscira gsmx format.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "../libgsmefr/gsm_efr.h"
+#include "etsi.h"
+
+main(argc, argv)
+	char **argv;
+{
+	char *infname, *outfname;
+	FILE *inf, *outf;
+	int big_endian;
+	unsigned frame_no;
+	uint8_t input_bits[ETSI_ENC_NWORDS], frame[EFR_RTP_FRAME_LEN];
+	int rc;
+
+	if (argc == 3 && argv[1][0] != '-') {
+		big_endian = 0;
+		infname = argv[1];
+		outfname = argv[2];
+	} else if (argc == 4 && !strcmp(argv[1], "-b")) {
+		big_endian = 1;
+		infname = argv[2];
+		outfname = argv[3];
+	} else {
+		fprintf(stderr, "usage: %s [-b] input.cod output.gsmx\n",
+			argv[0]);
+		exit(1);
+	}
+	inf = fopen(infname, "r");
+	if (!inf) {
+		perror(infname);
+		exit(1);
+	}
+	outf = fopen(outfname, "w");
+	if (!outf) {
+		perror(outfname);
+		exit(1);
+	}
+	for (frame_no = 0; ; frame_no++) {
+		rc = read_etsi_bits(inf, big_endian, input_bits,
+				    ETSI_ENC_NWORDS, infname);
+		if (!rc)
+			break;
+		bits2frame(input_bits, frame, infname, frame_no);
+		fwrite(frame, 1, sizeof frame, outf);
+	}
+	fclose(outf);
+	exit(0);
+}