changeset 5:bf5c9fb431b8

trau-parse: implement EFR decoding
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 24 May 2024 09:34:36 +0000
parents d9c095357c32
children 50f73e4d09e8
files trau-decode/Makefile trau-decode/parse-efr.c trau-decode/parse-main.c
diffstat 3 files changed, 60 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/trau-decode/Makefile	Fri May 24 09:16:35 2024 +0000
+++ b/trau-decode/Makefile	Fri May 24 09:34:36 2024 +0000
@@ -5,7 +5,7 @@
 all:	${PROGS}
 
 trau-parse:	crc8gen.o parse-fr.o parse-efr.o parse-main.o
-	${CC} ${CFLAGS} -o $@ $^ -lgsmfr2
+	${CC} ${CFLAGS} -o $@ $^ -lgsmfr2 -lgsmefr
 
 clean:
 	rm -f *.o ${PROGS}
--- a/trau-decode/parse-efr.c	Fri May 24 09:16:35 2024 +0000
+++ b/trau-decode/parse-efr.c	Fri May 24 09:34:36 2024 +0000
@@ -83,3 +83,61 @@
 		rc3 ? "bad" : "good", rc4 ? "bad" : "good",
 		rc5 ? "bad" : "good");
 }
+
+static void
+dbits_to_frame(d_bits, frame)
+	ubit_t *d_bits;
+	uint8_t *frame;
+{
+	ubit_t intermed[248], *ip;
+	uint8_t *op, mask;
+	unsigned nb;
+
+	intermed[0] = 1;
+	intermed[1] = 1;
+	intermed[2] = 0;
+	intermed[3] = 0;
+	bcopy(d_bits + 1, intermed + 4, 38);
+	bcopy(d_bits + 42, intermed + 42, 53);
+	bcopy(d_bits + 98, intermed + 95, 50);
+	bcopy(d_bits + 151, intermed + 145, 53);
+	bcopy(d_bits + 207, intermed + 198, 50);
+	ip = intermed;
+	op = frame;
+	for (nb = 0; nb < EFR_RTP_FRAME_LEN; nb++) {
+		*op = 0;
+		for (mask = 0x80; mask; mask >>= 1) {
+			if (*ip)
+				*op |= mask;
+			ip++;
+		}
+		op++;
+	}
+}
+
+void
+print_efr_frame(d_bits)
+	ubit_t *d_bits;
+{
+	uint8_t frame[EFR_RTP_FRAME_LEN];
+	int16_t params[EFR_NUM_PARAMS];
+	int i, j, n, sid;
+
+	dbits_to_frame(d_bits, frame);
+	EFR_frame2params(frame, params);
+	fputs("  EFR frame:\n    LPC", stdout);
+	n = 0;
+	for (i = 0; i < 5; i++)
+		printf(" %d", params[n++]);
+	putchar('\n');
+	for (i = 0; i < 4; i++) {
+		fputs("   ", stdout);
+		for (j = 0; j < 13; j++)
+			printf(" %d", params[n++]);
+		putchar('\n');
+	}
+	sid = EFR_sid_classify(frame);
+	printf("    SID recompute: %d\n", sid);
+	if (!bcmp(frame, EFR_decoder_homing_frame, EFR_RTP_FRAME_LEN))
+		puts("    Matches DHF");
+}
--- a/trau-decode/parse-main.c	Fri May 24 09:16:35 2024 +0000
+++ b/trau-decode/parse-main.c	Fri May 24 09:34:36 2024 +0000
@@ -122,6 +122,7 @@
 	case 0x1A:
 		collect_d_bits();
 		check_efr_crc(d_bits);
+		print_efr_frame(d_bits);
 		break;
 	}
 	printf("  C16=%u C17=%u C18=%u C19=%u C20=%u C21=%u\n",