view efrtest/etsi-enc.c @ 474:285381a001fc

new program gsmfr-dlcap-sync
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 15 May 2024 06:20:59 +0000
parents 51678b070c7a
children
line wrap: on
line source

/*
 * gsmefr-etsi-enc is a test program for our EFR encoder: it reads raw
 * 16-bit PCM (matching ETSI's *.inp) as input and writes ETSI's *.cod
 * format as output, allowing our encoder to be tested with ETSI's
 * official test sequences.
 *
 * ETSI input and output files are read and written in LE byte order,
 * matching the official test sequences in ts_100725v050200p0.zip.
 */

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include "../libgsmefr/gsm_efr.h"

main(argc, argv)
	char **argv;
{
	char *infname, *outfname;
	FILE *inf, *outf;
	struct EFR_encoder_state *state;
	int16_t pcm[160];
	uint8_t frame[EFR_RTP_FRAME_LEN], bits[250];
	int opt, dtx = 0, rc, sp, vad, big_endian = 0;
	extern int optind;

	while ((opt = getopt(argc, argv, "bd")) != EOF) {
		switch (opt) {
		case 'b':
			big_endian = 1;
			continue;
		case 'd':
			dtx = 1;
			continue;
		default:
		usage:
			fprintf(stderr,
				"usage: %s [-b] [-d] input.inp output.cod\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 = EFR_encoder_create(dtx);
	if (!state) {
		perror("EFR_encoder_create()");
		exit(1);
	}
	for (;;) {
		rc = read_input(inf, pcm, infname, big_endian);
		if (!rc)
			break;
		EFR_encode_frame(state, pcm, frame, &sp, &vad);
		frame2bits(frame, bits);
		bits[248] = vad;
		bits[249] = sp;
		emit_output(outf, bits + 4, 246, big_endian);
	}
	fclose(outf);
	exit(0);
}