diff amrdiff/etsi-bit-rd.c @ 0:a03c87a2abc6

amrdiff program written
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 03 Apr 2024 18:44:27 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/amrdiff/etsi-bit-rd.c	Wed Apr 03 18:44:27 2024 +0000
@@ -0,0 +1,50 @@
+/*
+ * The utility function in this module reads the bits from ETSI *.cod
+ * files, both AMR and EFR versions, either LE or BE.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "etsi.h"
+#include "amr_defs.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[COD_FORMAT_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 && (sp[0] != 0xFF || sp[1] != 0xFF)) {
+			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;
+}