view hrutil/cod2hex.c @ 557:129c895a0564

hrutil: new program gsmhr-cod2hex
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 06 Feb 2025 08:38:27 +0000
parents
children
line wrap: on
line source

/*
 * This program reads an HRv1 *.cod file in ETSI test sequence format
 * (encoder output format) and converts it into TW-TS-005 Annex B
 * hexadecimal format.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include "../libgsmhr1/tw_gsmhr.h"

main(argc, argv)
	char **argv;
{
	char *infname, *outfname;
	FILE *inf, *outf;
	int opt, rc, big_endian = 0, emit_5993 = 0;
	unsigned frame_no;
	int16_t params[GSMHR_NUM_PARAMS_ENC];
	extern int optind;

	while ((opt = getopt(argc, argv, "bx")) != EOF) {
		switch (opt) {
		case 'b':
			big_endian = 1;
			continue;
		case 'x':
			emit_5993 = 1;
			continue;
		default:
		usage:
			fprintf(stderr,
				"usage: %s [-b] [-x] input.cod output.hex\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);
	}

	for (frame_no = 0; ; frame_no++) {
		rc = read_cod_frame(inf, big_endian, params, infname, frame_no);
		if (!rc)
			break;
		emit_cod_to_tw5b(outf, params, emit_5993);
	}
	exit(0);
}