view hrutil/etsi-dec.c @ 608:d4e42ec4a688 default tip

hrutil: new program gsmhr-decode-r
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 05 Dec 2025 09:01:14 +0000
parents bc57dcfa91d0
children
line wrap: on
line source

/*
 * gsmhr-etsi-dec is a test program for our GSM-HR decoder: it reads ETSI's
 * .dec format as input and writes raw 16-bit PCM (same as ETSI's *.out)
 * as output, allowing our decoder to be tested with ETSI's official test
 * sequences.
 *
 * ETSI input and output files are read and written in the local machine's
 * native byte order by default; -b and -l options can be used to force
 * BE or LE, respectively.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.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 opt, rc, big_endian;
	struct gsmhr_decoder_state *state;
	unsigned frame_no;
	int16_t params[GSMHR_NUM_PARAMS_DEC];
	int16_t pcm[160];
	extern int optind;

	big_endian = is_native_big_endian();
	while ((opt = getopt(argc, argv, "bl")) != EOF) {
		switch (opt) {
		case 'b':
			big_endian = 1;
			continue;
		case 'l':
			big_endian = 0;
			continue;
		default:
		usage:
			fprintf(stderr,
				"usage: %s [-b|-l] input.dec output.out\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_decoder_create();
	if (!state) {
		perror("gsmhr_decoder_create()");
		exit(1);
	}
	for (frame_no = 0; ; frame_no++) {
		rc = read_dec_frame(inf, big_endian, params, infname, frame_no);
		if (!rc)
			break;
		gsmhr_decode_frame(state, params, pcm);
		if (big_endian)
			write_pcm_be(outf, pcm);
		else
			write_pcm_le(outf, pcm);
	}
	fclose(outf);
	exit(0);
}