diff trau-decode/dump-1bit.c @ 27:f508dacf2cf9

trau-decode: new programs dump-1bit and trau-sync8
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 18 Aug 2024 06:26:23 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/trau-decode/dump-1bit.c	Sun Aug 18 06:26:23 2024 +0000
@@ -0,0 +1,47 @@
+/*
+ * This program reads a 64 kbit/s timeslot recording file, focuses on one
+ * bit out of the eight (a single 8 kbit/s subslot) and prints a dump
+ * that shows just this one bit out of each byte.  It is an aid for
+ * development and debugging of frame sync tools for 8 kbit/s submultiplexing.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+main(argc, argv)
+	char **argv;
+{
+	FILE *inf;
+	int subslot, right_shift;
+	unsigned file_offset, mod16;
+	int inb;
+
+	if (argc != 3) {
+		fprintf(stderr, "usage: %s binfile subslot\n", argv[0]);
+		exit(1);
+	}
+	inf = fopen(argv[1], "r");
+	if (!inf) {
+		perror(argv[1]);
+		exit(1);
+	}
+	subslot = atoi(argv[2]);
+	if (subslot < 0 || subslot > 7) {
+		fprintf(stderr, "error: invalid subslot argument\n");
+		exit(1);
+	}
+	right_shift = 7 - subslot;
+	for (file_offset = 0; ; file_offset++) {
+		inb = getc(inf);
+		if (inb < 0)
+			break;
+		mod16 = file_offset & 15;
+		if (mod16 == 0)
+			printf("%08X:", file_offset);
+		if (mod16 == 0 || mod16 == 4 || mod16 == 8 || mod16 == 12)
+			putchar(' ');
+		printf(" %u", (inb >> right_shift) & 1);
+		if (mod16 == 15)
+			putchar('\n');
+	}
+}