view hrutil/encode.c @ 630:f85ef5c4d044 default tip

libgsmhr1: provide sizes of state structures
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 12 Mar 2026 06:19:12 +0000
parents c53ce88d67a7
children
line wrap: on
line source

/*
 * This file is the main module for gsmhr-encode utility.  This utility
 * is intended to serve as the "user-friendly" speech encoder for GSM-HR,
 * reading speech input in WAV format and emitting GSM-HR output in
 * TW-TS-005 Annex B hex format.
 */

#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/wavreader.h"
#include "../libtest/wavrdhelp.h"

main(argc, argv)
	char **argv;
{
	char *infname, *outfname;
	void *wav;
	FILE *outf;
	struct gsmhr_encoder_state *state;
	int16_t pcm[160];
	int16_t prm_out[GSMHR_NUM_PARAMS_ENC];
	int opt, rc, dtx = 0, emit_5993 = 0;
	extern int optind;

	while ((opt = getopt(argc, argv, "dx")) != EOF) {
		switch (opt) {
		case 'd':
			dtx = 1;
			continue;
		case 'x':
			emit_5993 = 1;
			continue;
		default:
		usage:
			fprintf(stderr,
				"usage: %s [-d] [-x] input.wav output.hex\n",
				argv[0]);
			exit(1);
		}
	}
	if (argc != optind + 2)
		goto usage;
	infname = argv[optind];
	outfname = argv[optind+1];

	wav = wav_read_open(infname);
	if (!wav) {
		perror(infname);
		exit(1);
	}
	rc = wavrd_check_header(wav, infname);
	if (rc < 0)
		exit(1);	/* error msg already printed */
	outf = fopen(outfname, "w");
	if (!outf) {
		perror(outfname);
		exit(1);
	}
	state = gsmhr_encoder_create(dtx);
	if (!state) {
		perror("gsmhr_encoder_create()");
		exit(1);
	}
	for (;;) {
		rc = wavrd_get_pcm_block(wav, pcm);
		if (!rc)
			break;
		gsmhr_encode_frame(state, pcm, prm_out);
		emit_cod_to_tw5b(outf, prm_out, emit_5993);
	}
	fclose(outf);
	exit(0);
}