diff trau-ul-prep/etsi-bit-rd.c @ 22:8957383370c5

trau-ul-prep: implement efrdec2tsrc
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 23 Jun 2024 22:24:39 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trau-ul-prep/etsi-bit-rd.c	Sun Jun 23 22:24:39 2024 +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 <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;
+	}
+}