changeset 34:307fe06fabec

dhf: generate EFR hex DHF in C form
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 14 May 2024 03:36:31 +0000
parents c1aa6a4160f6
children 6bb1651f8c11
files .hgignore dhf/Makefile dhf/efr-dhf-hexout.c
diffstat 3 files changed, 28 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon May 13 22:49:21 2024 +0000
+++ b/.hgignore	Tue May 14 03:36:31 2024 +0000
@@ -6,8 +6,9 @@
 ^amrdiff/readone-amr$
 ^amrdiff/readone-efr$
 
-^dhf/efr-dhf-hex\.txt$
+^dhf/efr-dhf-bytes\.c$
 ^dhf/efr-dhf-hexout$
+^dhf/mr122-dhf-bytes\.c$
 
 ^dmw/gen-dmw-bin$
 ^dmw/dmw-[au]law\.
--- a/dhf/Makefile	Mon May 13 22:49:21 2024 +0000
+++ b/dhf/Makefile	Tue May 14 03:36:31 2024 +0000
@@ -1,15 +1,15 @@
 CC=	gcc
 CFLAGS=	-O2
 PROG=	efr-dhf-hexout
-OUTFILE=efr-dhf-hex.txt
+COUT=	efr-dhf-bytes.c mr122-dhf-bytes.c
 
-all:	${PROG} ${OUTFILE}
+all:	${PROG} ${COUT}
 
 ${PROG}:	${PROG}.c
 	${CC} ${CFLAGS} -o $@ $@.c -lgsmefr -ltwamr
 
-${OUTFILE}:	${PROG}
-	./${PROG} > $@
+${COUT}:	efr-dhf-hexout
+	./efr-dhf-hexout efr-dhf-bytes.c mr122-dhf-bytes.c
 
 clean:
-	rm -f *.o ${PROG} *.txt
+	rm -f *.o ${PROG} ${COUT}
--- a/dhf/efr-dhf-hexout.c	Mon May 13 22:49:21 2024 +0000
+++ b/dhf/efr-dhf-hexout.c	Tue May 14 03:36:31 2024 +0000
@@ -12,27 +12,40 @@
 #include <tw_amr.h>
 
 static void
-emit_one_frame(params, name)
+emit_one_frame(params, filename, cname)
 	const int16_t *params;
-	char *name;
+	char *filename, *cname;
 {
 	uint8_t efr_rtp[EFR_RTP_FRAME_LEN];
+	FILE *outf;
 	unsigned n;
 
 	EFR_params2frame(params, efr_rtp);
-	printf("%s:\n\n", name);
+	outf = fopen(filename, "w");
+	if (!outf) {
+		perror(filename);
+		exit(1);
+	}
+	fputs("#include <stdint.h>\n\n", outf);
+	fprintf(outf, "const uint8_t %s[31] = {\n", cname);
 	for (n = 0; n < EFR_RTP_FRAME_LEN; n++) {
-		printf("0x%02X,", efr_rtp[n]);
+		fprintf(outf, "0x%02X,", efr_rtp[n]);
 		if (n == 15 || n == 30)
-			putchar('\n');
+			putc('\n', outf);
 	}
-	putchar('\n');
+	fputs("};\n", outf);
+	fclose(outf);
 }
 
 main(argc, argv)
 	char **argv;
 {
-	emit_one_frame(amr_dhf_gsmefr, "EFR DHF");
-	emit_one_frame(amr_dhf_mr122, "MR122 DHF");
+	if (argc != 3) {
+		fprintf(stderr, "usage: %s efr-dhf-out mr122-dhf-out\n",
+			argv[0]);
+		exit(1);
+	}
+	emit_one_frame(amr_dhf_gsmefr, argv[1], "efr_dhf_bytes");
+	emit_one_frame(amr_dhf_mr122, argv[2], "mr122_dhf_bytes");
 	exit(0);
 }