changeset 115:5a63294fa321

gsmefr-cod-parse test program written
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 29 Nov 2022 22:18:33 +0000
parents ff0372186b59
children d9ad0f5121e8
files .hgignore efrtest/Makefile efrtest/cod-parse.c
diffstat 3 files changed, 126 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Tue Nov 29 20:31:11 2022 +0000
+++ b/.hgignore	Tue Nov 29 22:18:33 2022 +0000
@@ -9,6 +9,7 @@
 ^dev/gsm0611-silence-fr$
 ^dev/gsm0611-silence-fr\.out$
 
+^efrtest/gsmefr-cod-parse$
 ^efrtest/gsmefr-decode$
 ^efrtest/gsmefr-etsi-dec$
 ^efrtest/gsmefr-etsi-enc$
--- a/efrtest/Makefile	Tue Nov 29 20:31:11 2022 +0000
+++ b/efrtest/Makefile	Tue Nov 29 22:18:33 2022 +0000
@@ -1,12 +1,16 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	gsmefr-decode gsmefr-etsi-dec gsmefr-etsi-enc gsmefr-rec2etsi
+PROGS=	gsmefr-cod-parse gsmefr-decode gsmefr-etsi-dec gsmefr-etsi-enc \
+	gsmefr-rec2etsi
 LIBEFR=	../libgsmefr/libgsmefr.a
 LIBTEST=../libtest/libtest.a
 INSTBIN=/opt/freecalypso/bin
 
 all:	${PROGS}
 
+gsmefr-cod-parse:	cod-parse.o ${LIBEFR}
+	${CC} ${CFLAGS} -o $@ cod-parse.o ${LIBEFR}
+
 gsmefr-decode:	decode.o ${LIBTEST} ${LIBEFR}
 	${CC} ${CFLAGS} -o $@ decode.o ${LIBTEST} ${LIBEFR}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/efrtest/cod-parse.c	Tue Nov 29 22:18:33 2022 +0000
@@ -0,0 +1,120 @@
+/*
+ * This program reads an EFR *.cod file in ETSI test sequence format
+ * (output from either ETSI's official coder program or our gsmefr-etsi-enc)
+ * and converts it into human-readable format, similar to what one would get
+ * from our gsmrec-dump utility.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "../libgsmefr/gsm_efr.h"
+
+#define	ETSI_ENC_NWORDS	246
+
+static int
+read_input(inf, bitvec, filename_for_errs)
+	FILE *inf;
+	uint8_t *bitvec;
+	char *filename_for_errs;
+{
+	uint8_t file_bytes[ETSI_ENC_NWORDS * 2], *sp;
+	int cc;
+	unsigned n;
+
+	cc = fread(file_bytes, 2, ETSI_ENC_NWORDS, inf);
+	if (cc == 0)
+		return 0;
+	if (cc != ETSI_ENC_NWORDS) {
+		fprintf(stderr, "error: short read from %s\n",
+			filename_for_errs);
+		exit(1);
+	}
+	sp = file_bytes;
+	for (n = 0; n < ETSI_ENC_NWORDS; n++) {
+		if (sp[1]) {
+			fprintf(stderr,
+		"error in %s: non-zero in what should be LE upper byte\n",
+				filename_for_errs);
+			exit(1);
+		}
+		bitvec[n] = sp[0];
+		sp += 2;
+	}
+	return 1;
+}
+
+static void
+bits2frame(input_bits, frame, filename_for_errs, frame_no)
+	uint8_t *input_bits, *frame;
+	char *filename_for_errs;
+	unsigned frame_no;
+{
+	uint8_t bits[248], *sp, *dp;
+	unsigned nb, byte, mask;
+
+	bits[0] = 1;
+	bits[1] = 1;
+	bits[2] = 0;
+	bits[3] = 0;
+	bcopy(input_bits, bits + 4, 244);
+	sp = bits;
+	dp = frame;
+	for (nb = 0; nb < EFR_RTP_FRAME_LEN; nb++) {
+		byte = 0;
+		for (mask = 0x80; mask; mask >>= 1) {
+			if (*sp > 1) {
+				fprintf(stderr,
+					"error in %s frame #%u: data bit > 1\n",
+					filename_for_errs, frame_no);
+				exit(1);
+			}
+			if (*sp)
+				byte |= mask;
+			sp++;
+		}
+		*dp++ = byte;
+	}
+}
+
+main(argc, argv)
+	char **argv;
+{
+	FILE *inf;
+	unsigned frame_no;
+	uint8_t input_bits[ETSI_ENC_NWORDS], frame[EFR_RTP_FRAME_LEN];
+	int16_t params[EFR_NUM_PARAMS];
+	int rc, i, j, n;
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s file.cod\n", argv[0]);
+		exit(1);
+	}
+	inf = fopen(argv[1], "r");
+	if (!inf) {
+		perror(argv[1]);
+		exit(1);
+	}
+	for (frame_no = 0; ; frame_no++) {
+		rc = read_input(inf, input_bits, argv[1]);
+		if (!rc)
+			break;
+		bits2frame(input_bits, frame, argv[1], frame_no);
+		printf("#%u: VAD=%u SP=%u SID=%d LPC", frame_no,
+			input_bits[244], input_bits[245],
+			EFR_sid_classify(frame));
+		EFR_frame2params(frame, params);
+		n = 0;
+		for (i = 0; i < 5; i++)
+			printf(" %u", params[n++]);
+		putchar('\n');
+		for (i = 0; i < 4; i++) {
+			putchar(' ');
+			for (j = 0; j < 13; j++)
+				printf(" %u", params[n++]);
+			putchar('\n');
+		}
+	}
+}