view hrutil/tfo-xfrm-dc.c @ 609:a2b2ca082dd7 default tip

hrutil: new program gsmhr-tfo-xfrm-dc
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 24 Feb 2026 04:16:57 +0000
parents hrutil/tfo-xfrm.c@fc7a59deb3c3
children
line wrap: on
line source

/*
 * This program exercises our ThemWi implementation of TFO transform for
 * GSM-HR.  The present variant reads radio leg A Rx frames from an
 * ETSI-format *.dec file and writes the "pristine" stream intended for
 * radio leg B Tx into an ETSI-format *.cod file.  This variant exercises
 * libgsmhr1 TFO transform function in its most native form.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include "../libgsmhr1/tw_gsmhr.h"
#include "../libtest/local_endian.h"

main(argc, argv)
	char **argv;
{
	char *infname, *outfname;
	FILE *inf, *outf;
	int big_endian;
	unsigned frame_no;
	struct gsmhr_rxfe_state *state;
	int16_t prm_in[GSMHR_NUM_PARAMS_DEC], prm_out[GSMHR_NUM_PARAMS_ENC];
	int opt, rc, dtxd = 0;
	extern int optind;

	big_endian = is_native_big_endian();
	while ((opt = getopt(argc, argv, "bdl")) != EOF) {
		switch (opt) {
		case 'b':
			big_endian = 1;
			continue;
		case 'd':
			dtxd = 1;
			continue;
		case 'l':
			big_endian = 0;
			continue;
		default:
		usage:
			fprintf(stderr,
				"usage: %s [-b|-l] [-d] input.dec output.cod\n",
				argv[0]);
			exit(1);
		}
	}
	if (argc != optind + 2)
		goto usage;
	infname = argv[optind];
	outfname = argv[optind+1];

	inf = fopen(infname, "r");
	if (!inf) {
		perror(infname);
		exit(1);
	}
	outf = fopen(outfname, "w");
	if (!outf) {
		perror(outfname);
		exit(1);
	}
	state = gsmhr_rxfe_create();
	if (!state) {
		fprintf(stderr, "gsmhr_rxfe_create() failed!\n");
		exit(1);
	}
	for (frame_no = 0; ; frame_no++) {
		rc = read_dec_frame(inf, big_endian, prm_in, infname, frame_no);
		if (!rc)
			break;
		gsmhr_tfo_xfrm(state, dtxd, prm_in, prm_out);
		emit_cod_to_endian(outf, prm_out, big_endian);
	}
	fclose(outf);
	exit(0);
}