view tchtools/fc-vm2hex.c @ 964:a96cb97b66a2

ringtools/imy: fix duplicate definition of tdma_durations[] The bug was reported by Vadim Yanitskiy <fixeria@osmocom.org>, although the present fix is slightly different from the contributed patch: because main.c doesn't need this tdma_durations[] array at all, let's simply remove the reference to this array from main.c rather than turn it into an extern. I no longer remember my original thought flow that resulted (by mistake) in tdma_durations[] being multiply defined in main.c and durations.c. My intent might have been to define all globals in main.c and have the reference in durations.c be an extern - and I missed that extern - but without clear memory, I have no certainty. In any case, having this data array defined in the same module that fills it (durations.c) is sensible, so let's make it the new way.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 31 Aug 2023 19:38:18 +0000
parents 5041bcb8140f
children
line wrap: on
line source

/*
 * This utility converts old-fashioned (non-AMR) TCS211 voice memo files
 * read out of FFS into hex strings that can be analyzed by a human,
 * either directly or with the aid of gsmfr-dlcap-parse utility from
 * Themyscira Wireless GSM codec libraries & utilities package.
 */

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>

char *infname;
FILE *inf, *outf;

static unsigned
get_word()
{
	u_char b[2];
	int i, c;

	for (i = 0; i < 2; i++) {
		c = getc(inf);
		if (c < 0) {
			fprintf(stderr, "error: premature EOF in %s\n",
				infname);
			exit(1);
		}
		b[i] = c;
	}
	return((b[1] << 8) | b[0]);
}

convert_speech_sample()
{
	u_char bytes[34];
	int i, dp;
	unsigned word;

	dp = 0;
	for (i = 0; i < 17; i++) {
		word = get_word();
		bytes[dp++] = word >> 8;
		bytes[dp++] = word;
	}
	for (i = 0; i < 33; i++)
		fprintf(outf, "%02X", bytes[i]);
}

main(argc, argv)
	char **argv;
{
	unsigned first_word;

	if (argc < 2 || argc > 3) {
		fprintf(stderr, "usage: %s infile [outfile]\n", argv[0]);
		exit(1);
	}
	infname = argv[1];
	inf = fopen(infname, "r");
	if (!inf) {
		perror(infname);
		exit(1);
	}
	if (argc > 2) {
		outf = fopen(argv[2], "w");
		if (!outf) {
			perror(argv[2]);
			exit(1);
		}
	} else
		outf = stdout;

	for (;;) {
		first_word = get_word();
		if (first_word == 0xFBFF)	/* SC_VM_END_MASK */
			break;
		fprintf(outf, "%04X", first_word);
		if (first_word & 0x8000) {	/* B_VM_SPEECH */
			fprintf(outf, " %04X", get_word());
			fprintf(outf, " %04X", get_word());
			putc(' ', outf);
			convert_speech_sample();
		}
		putc('\n', outf);
	}
	exit(0);
}