view frtest/encode-r.c @ 374:61047a2912a2

libtwamr: integrate mac_32.c
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 06 May 2024 04:09:45 +0000
parents 962861d46ccf
children
line wrap: on
line source

/*
 * gsmfr-encode-r is just like gsmfr-encode, but reads the source
 * linear PCM data to be encoded from a raw BE file ("robe")
 * instead of WAV.
 *
 * Addendum: gsmfr-encode-r -h flag enables the later-spec feature
 * of encoder homing.  This option is not replicated in WAV-reading
 * gsmfr-encode because it is deemed to be of no use with WAV.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "../libgsmfr2/tw_gsmfr.h"
#include "../libtest/roberead.h"

main(argc, argv)
	char **argv;
{
	char *infname, *outfname;
	FILE *inf, *binf;
	struct gsmfr_0610_state *enc_state;
	int16_t pcm[160];
	uint8_t frame[33];
	int homing, rc;

	if (argc == 3 && argv[1][0] != '-') {
		homing = 0;
		infname = argv[1];
		outfname = argv[2];
	} else if (argc == 4 && !strcmp(argv[1], "-h")) {
		homing = 1;
		infname = argv[2];
		outfname = argv[3];
	} else {
		fprintf(stderr, "usage: %s [-h] input.robe output.gsm\n",
			argv[0]);
		exit(1);
	}
	inf = fopen(infname, "r");
	if (!inf) {
		perror(infname);
		exit(1);
	}
	binf = fopen(outfname, "w");
	if (!binf) {
		perror(outfname);
		exit(1);
	}
	enc_state = gsmfr_0610_create();
	if (!enc_state) {
		fprintf(stderr, "gsmfr_0610_create() failed!\n");
		exit(1);
	}
	for (;;) {
		rc = robe_get_pcm_block(inf, pcm);
		if (!rc)
			break;
		gsmfr_0610_encode_frame(enc_state, pcm, frame);
		if (homing)
			gsmfr_0610_encoder_homing(enc_state, pcm);
		fwrite(frame, 1, sizeof frame, binf);
	}
	fclose(binf);
	exit(0);
}