changeset 147:90b9c7c3fa3b

gsmefr-cod-parse: use factored-out ETSI bit reader
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 14 Dec 2022 08:09:52 +0000
parents 0fa0cd251a31
children bbe5669f0f29
files efrtest/Makefile efrtest/cod-parse.c
diffstat 2 files changed, 5 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/efrtest/Makefile	Wed Dec 14 08:05:08 2022 +0000
+++ b/efrtest/Makefile	Wed Dec 14 08:09:52 2022 +0000
@@ -8,8 +8,8 @@
 
 all:	${PROGS}
 
-gsmefr-cod-parse:	cod-parse.o ${LIBEFR}
-	${CC} ${CFLAGS} -o $@ cod-parse.o ${LIBEFR}
+gsmefr-cod-parse:	cod-parse.o etsi-bit-rd.o ${LIBEFR}
+	${CC} ${CFLAGS} -o $@ cod-parse.o etsi-bit-rd.o ${LIBEFR}
 
 gsmefr-dec-parse:	dec-parse.o etsi-bit-rd.o ${LIBEFR}
 	${CC} ${CFLAGS} -o $@ dec-parse.o etsi-bit-rd.o ${LIBEFR}
--- a/efrtest/cod-parse.c	Wed Dec 14 08:05:08 2022 +0000
+++ b/efrtest/cod-parse.c	Wed Dec 14 08:09:52 2022 +0000
@@ -11,73 +11,7 @@
 #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;
-	}
-}
+#include "etsi.h"
 
 main(argc, argv)
 	char **argv;
@@ -98,7 +32,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_ENC_NWORDS,
+				    argv[1]);
 		if (!rc)
 			break;
 		bits2frame(input_bits, frame, argv[1], frame_no);