changeset 19:2bdcd2ed9a1c

pcmu2efr: generate AMR-EFR version
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 12 May 2024 00:56:42 +0000
parents 6bcb8e4ea669
children f5f541bc9415
files .hgignore pcmu2efr/Makefile pcmu2efr/amrefr-out.c pcmu2efr/gen-amrefr.c
diffstat 4 files changed, 72 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Apr 17 00:03:31 2024 +0000
+++ b/.hgignore	Sun May 12 00:56:42 2024 +0000
@@ -9,6 +9,7 @@
 ^dmw/gen-dmw-bin$
 ^dmw/dmw-[au]law\.
 
+^pcmu2efr/amrefr-out$
 ^pcmu2efr/stdefr-diff$
 ^pcmu2efr/stdefr-out$
 
--- a/pcmu2efr/Makefile	Wed Apr 17 00:03:31 2024 +0000
+++ b/pcmu2efr/Makefile	Sun May 12 00:56:42 2024 +0000
@@ -1,12 +1,16 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	stdefr-diff stdefr-out
+PROGS=	amrefr-out stdefr-diff stdefr-out
 
+AMREFR_OBJS=	amrefr-out.o gen-amrefr.o gen160.o seqsyncu.o ulaw-expand.o
 STDEFR_OBJS=	gen-efr.o gen160.o seqsyncu.o stdefr-out.o ulaw-expand.o
 STDEFRD_OBJS=	gen-efr.o gen160.o seqsyncu.o stdefr-diff.o ulaw-expand.o
 
 all:	${PROGS}
 
+amrefr-out:	${AMREFR_OBJS}
+	${CC} ${CFLAGS} -o $@ ${AMREFR_OBJS} -lgsmefr -ltwamr
+
 stdefr-diff:	${STDEFRD_OBJS}
 	${CC} ${CFLAGS} -o $@ ${STDEFRD_OBJS} -lgsmefr
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pcmu2efr/amrefr-out.c	Sun May 12 00:56:42 2024 +0000
@@ -0,0 +1,31 @@
+/*
+ * This program computes 160 possible EFR encoder outputs using AMR-EFR hybrid,
+ * and writes the result out to a gsmx file.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+extern uint8_t amr_efr[160][31];
+
+main(argc, argv)
+	char **argv;
+{
+	FILE *outf;
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s gsmx-out-file\n", argv[0]);
+		exit(1);
+	}
+	generate_linear_inputs();
+	generate_amr_efr();
+	outf = fopen(argv[1], "w");
+	if (!outf) {
+		perror(argv[1]);
+		exit(1);
+	}
+	fwrite(amr_efr, 31, 160, outf);
+	fclose(outf);
+	exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pcmu2efr/gen-amrefr.c	Sun May 12 00:56:42 2024 +0000
@@ -0,0 +1,35 @@
+/*
+ * The code in this module takes linear_inputs[][] from gen160.c
+ * and generates EFR-format frames by way of libtwamr encoder.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <gsm_efr.h>
+#include <tw_amr.h>
+
+extern uint16_t linear_inputs[160][160];
+
+uint8_t amr_efr[160][31];
+
+void
+generate_amr_efr(void)
+{
+	struct amr_encoder_state *st;
+	struct amr_param_frame amr_frame;
+	unsigned m;
+
+	st = amr_encoder_create(0, 0);
+	if (!st) {
+		fprintf(stderr, "error: amr_encoder_create() failed\n");
+		exit(1);
+	}
+	for (m = 0; m < 160; m++) {
+		amr_encoder_reset(st, 0, 0);
+		amr_encode_frame(st, MR122, (const int16_t *) linear_inputs[m],
+				 &amr_frame);
+		EFR_params2frame(amr_frame.param, amr_efr[m]);
+	}
+	free(st);
+}