view trau-decode/dump-1bit.c @ 52:4681ad8483d6

d144: edata-input-compile program written
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 25 Sep 2024 03:33:16 +0000
parents f508dacf2cf9
children
line wrap: on
line source

/*
 * 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');
	}
}