changeset 145:8ed838709897

efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 14 Dec 2022 08:02:00 +0000
parents 30c7bc064218
children 0fa0cd251a31
files efrtest/Makefile efrtest/etsi-bit-rd.c efrtest/etsi-dec.c efrtest/etsi.h
diffstat 4 files changed, 92 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/efrtest/Makefile	Wed Dec 14 07:25:46 2022 +0000
+++ b/efrtest/Makefile	Wed Dec 14 08:02:00 2022 +0000
@@ -23,8 +23,8 @@
 gsmefr-encode:	encode.o ${LIBTEST} ${LIBEFR}
 	${CC} ${CFLAGS} -o $@ encode.o ${LIBTEST} ${LIBEFR}
 
-gsmefr-etsi-dec:	etsi-dec.o ${LIBEFR}
-	${CC} ${CFLAGS} -o $@ etsi-dec.o ${LIBEFR}
+gsmefr-etsi-dec:	etsi-dec.o etsi-bit-rd.o ${LIBEFR}
+	${CC} ${CFLAGS} -o $@ etsi-dec.o etsi-bit-rd.o ${LIBEFR}
 
 gsmefr-etsi-enc:	etsi-enc.o ${LIBEFR}
 	${CC} ${CFLAGS} -o $@ etsi-enc.o ${LIBEFR}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/efrtest/etsi-bit-rd.c	Wed Dec 14 08:02:00 2022 +0000
@@ -0,0 +1,83 @@
+/*
+ * In this module we implement utility functions for reading ETSI *.cod
+ * and *.dec files in either LE or BE format.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "../libgsmefr/gsm_efr.h"
+#include "etsi.h"
+
+read_etsi_bits(inf, big_endian, bitvec, nwords, filename_for_errs)
+	FILE *inf;
+	uint8_t *bitvec;
+	unsigned nwords;
+	char *filename_for_errs;
+{
+	uint8_t file_bytes[ETSI_DEC_NWORDS * 2], *sp;
+	int cc;
+	unsigned n, upper;
+
+	cc = fread(file_bytes, 2, nwords, inf);
+	if (cc == 0)
+		return 0;
+	if (cc != nwords) {
+		fprintf(stderr, "error: short read from %s\n",
+			filename_for_errs);
+		exit(1);
+	}
+	sp = file_bytes;
+	for (n = 0; n < nwords; n++) {
+		if (big_endian) {
+			upper = sp[0];
+			bitvec[n] = sp[1];
+		} else {
+			bitvec[n] = sp[0];
+			upper = sp[1];
+		}
+		if (upper) {
+			fprintf(stderr,
+		"error in %s: non-zero in what should be %s upper byte\n",
+				filename_for_errs, big_endian ? "BE" : "LE");
+			exit(1);
+		}
+		sp += 2;
+	}
+	return 1;
+}
+
+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;
+	}
+}
--- a/efrtest/etsi-dec.c	Wed Dec 14 07:25:46 2022 +0000
+++ b/efrtest/etsi-dec.c	Wed Dec 14 08:02:00 2022 +0000
@@ -14,73 +14,7 @@
 #include <string.h>
 #include <strings.h>
 #include "../libgsmefr/gsm_efr.h"
-
-#define	ETSI_DEC_NWORDS	247
-
-static int
-read_input(inf, bitvec, filename_for_errs)
-	FILE *inf;
-	uint8_t *bitvec;
-	char *filename_for_errs;
-{
-	uint8_t file_bytes[ETSI_DEC_NWORDS * 2], *sp;
-	int cc;
-	unsigned n;
-
-	cc = fread(file_bytes, 2, ETSI_DEC_NWORDS, inf);
-	if (cc == 0)
-		return 0;
-	if (cc != ETSI_DEC_NWORDS) {
-		fprintf(stderr, "error: short read from %s\n",
-			filename_for_errs);
-		exit(1);
-	}
-	sp = file_bytes;
-	for (n = 0; n < ETSI_DEC_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;
-	}
-}
+#include "etsi.h"
 
 static void
 write_pcm_le(outf, pcm)
@@ -130,7 +64,8 @@
 		exit(1);
 	}
 	for (frame_no = 0; ; frame_no++) {
-		rc = read_input(inf, input_bits, argv[1]);
+		rc = read_etsi_bits(inf, 0, input_bits, ETSI_DEC_NWORDS,
+				    argv[1]);
 		if (!rc)
 			break;
 		if (input_bits[0] > 1) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/efrtest/etsi.h	Wed Dec 14 08:02:00 2022 +0000
@@ -0,0 +1,4 @@
+/* definitions for ETSI *.cod and *.dec files */
+
+#define	ETSI_ENC_NWORDS	246
+#define	ETSI_DEC_NWORDS	247