view tchtools/fc-vm2gsmx.c @ 1014:961efadd530a default tip

fc-shell TCH DL handler: add support for CSD modes TCH DL capture mechanism in FC Tourmaline firmware has been extended to support CSD modes in addition to speech - add the necessary support on the host tools side. It needs to be noted that this mechanism in its present state does NOT provide the debug utility value that was sought: as we learned only after the code was implemented, TI's DSP has a misfeature in that the buffer we are reading (a_dd_0[]) is zeroed out when the IDS block is enabled, i.e., we are reading all zeros and not the real DL bits we were after. But since the code has already been written, we are keeping it - perhaps we can do some tests with IDS disabled.
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 26 Nov 2024 06:27:43 +0000
parents 546bf873ccc8
children
line wrap: on
line source

/*
 * This utility converts old-fashioned (non-AMR) TCS211 voice memo files
 * read out of FFS into Themyscira Wireless gsmx (extended-libgsm) format,
 * allowing further decoding into playable speech with gsmfr-decode.
 */

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

static char *infname;
static FILE *inf, *outf;
static u_long file_offset;

static const u_char bfi_marker[2] = {0xBF, 0x00};

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;
		file_offset++;
	}
	return((b[1] << 8) | b[0]);
}

static void
read_dsp_bytes(bytes)
	u_char *bytes;
{
	int i, dp;
	unsigned word;

	dp = 0;
	for (i = 0; i < 17; i++) {
		word = get_word();
		bytes[dp++] = word >> 8;
		bytes[dp++] = word;
	}
}

static void
convert_speech_sample()
{
	u_char tidsp_bytes[34], libgsm_bytes[33];

	read_dsp_bytes(tidsp_bytes);
	gsm0610_tidsp_to_libgsm(tidsp_bytes, libgsm_bytes);
	fwrite(libgsm_bytes, 1, 33, outf);
}

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

	if (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);
	}
	outf = fopen(argv[2], "w");
	if (!outf) {
		perror(argv[2]);
		exit(1);
	}
	for (;;) {
		first_word = get_word();
		if (first_word == 0xFBFF)	/* SC_VM_END_MASK */
			break;
		if ((first_word & 0xB7FF) == 0x8400) {
			/* skip dummy header words 1 and 2 */
			get_word();
			get_word();
			/* process the actual speech or SID frame */
			convert_speech_sample();
		} else if (first_word == 0x0400) {
			/* it's a skipped frame, aka BFI */
			fwrite(bfi_marker, 1, 2, outf);
		} else {
			fprintf(stderr,
	"error in %s at offset 0x%lx: invalid frame header word 0x%04X\n",
				infname, file_offset, first_word);
			exit(1);
		}
	}
	fclose(outf);
	exit(0);
}