changeset 23:2628a34fe75b

pcmu2efr: encode 2nd frame for AMR-EFR offsets 120-159
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 12 May 2024 04:24:15 +0000
parents f4420403219a
children c52fb8080faf
files pcmu2efr/Makefile pcmu2efr/comb-diff.c pcmu2efr/dhf-check.c pcmu2efr/gen-amr-2fr.c
diffstat 4 files changed, 47 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pcmu2efr/Makefile	Sun May 12 03:40:27 2024 +0000
+++ b/pcmu2efr/Makefile	Sun May 12 04:24:15 2024 +0000
@@ -3,9 +3,9 @@
 PROGS=	amrefr-out comb-diff dhf-check stdefr-diff stdefr-out
 
 AMREFR_OBJS=	amrefr-out.o gen-amrefr.o gen160.o seqsyncu.o ulaw-expand.o
-COMB_DIFF_OBJS=	comb-diff.o gen-amrefr.o gen-efr.o gen160.o seqsyncu.o \
+COMB_DIFF_OBJS=	comb-diff.o gen-amr-2fr.o gen-efr.o gen160.o seqsyncu.o \
 		ulaw-expand.o
-DHF_CHECK_OBJS=	dhf-check.o gen-amrefr.o gen-efr.o gen160.o seqsyncu.o \
+DHF_CHECK_OBJS=	dhf-check.o gen-amr-2fr.o gen-efr.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
--- a/pcmu2efr/comb-diff.c	Sun May 12 03:40:27 2024 +0000
+++ b/pcmu2efr/comb-diff.c	Sun May 12 04:24:15 2024 +0000
@@ -24,8 +24,8 @@
 	generate_amr_efr();
 	bcopy(standard_efr, combine, 160*31);
 	bcopy(amr_efr, combine + 160, 160*31);
-	for (m = 0; m < 279; m++) {
-		for (n = m + 1; n < 280; n++) {
+	for (m = 0; m < 319; m++) {
+		for (n = m + 1; n < 320; n++) {
 			if (!memcmp(combine[m], combine[n], 31))
 				printf("Bad: sequences #%u and #%u are equal\n",
 					m, n);
--- a/pcmu2efr/dhf-check.c	Sun May 12 03:40:27 2024 +0000
+++ b/pcmu2efr/dhf-check.c	Sun May 12 04:24:15 2024 +0000
@@ -40,7 +40,7 @@
 	generate_amr_efr();
 	for (n = 0; n < 160; n++)
 		check_for_dhf(standard_efr[n], "std EFR", n);
-	for (n = 0; n < 120; n++)
+	for (n = 0; n < 160; n++)
 		check_for_dhf(amr_efr[n], "AMR-EFR", n);
 	exit(0);
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pcmu2efr/gen-amr-2fr.c	Sun May 12 04:24:15 2024 +0000
@@ -0,0 +1,42 @@
+/*
+ * The code in this module takes linear_input_array[] from gen160.c
+ * and generates EFR-format frames by way of libtwamr encoder.
+ * This version does a second frame pass on offsets 120-159.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <gsm_efr.h>
+#include <tw_amr.h>
+
+extern uint16_t linear_input_array[480];
+
+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_input_array + 160 - m,
+				 &amr_frame);
+		if (m >= 120) {
+			amr_encode_frame(st, MR122,
+				(const int16_t *) linear_input_array + 320 - m,
+				 &amr_frame);
+		}
+		EFR_params2frame(amr_frame.param, amr_efr[m]);
+	}
+	free(st);
+}