view frtest/encode-r.c @ 477:4c9222d95647

libtwamr encoder: always emit frame->mode = mode; In the original implementation of amr_encode_frame(), the 'mode' member of the output struct was set to 0xFF if the output frame type is TX_NO_DATA. This design was made to mimic the mode field (16-bit word) being set to 0xFFFF (or -1) in 3GPP test sequence format - but nothing actually depends on this struct member being set in any way, and amr_frame_to_tseq() generates the needed 0xFFFF on its own, based on frame->type being equal to TX_NO_DATA. It is simpler and more efficient to always set frame->mode to the actual encoding mode in amr_encode_frame(), and this new behavior has already been documented in doc/AMR-library-API description in anticipation of the present change.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 18 May 2024 22:30:42 +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);
}