view amrtest/mode_file.c @ 508:c275e57132f8

libgsmhr1/{pack,unpack}_frame.c: comment fix there is only one unvoiced mode, hence it should be singular
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 17 Aug 2024 21:45:34 +0000
parents 1ceda5586d01
children
line wrap: on
line source

/*
 * The functions in this module implement reading per-frame encoder mode
 * instructions from a file, as in 3GPP test sequences and code.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "../libtwamr/tw_amr.h"

static FILE *mode_file;
static int lineno;
static char *filename_for_errs;

void
open_mode_file(filename)
	char *filename;
{
	mode_file = fopen(filename, "r");
	if (!mode_file) {
		perror(filename);
		exit(1);
	}
}

void
read_mode_file_line(mode_out)
	enum Mode *mode_out;
{
	char linebuf[16], *cp;
	int rc;

	if (!fgets(linebuf, sizeof linebuf, mode_file)) {
		fprintf(stderr, "error: %s ends before speech input\n",
			filename_for_errs);
		exit(1);
	}
	lineno++;
	cp = index(linebuf, '\n');
	if (!cp) {
		fprintf(stderr, "%s line %d: too long or missing newline\n",
			filename_for_errs, lineno);
		exit(1);
	}
	if (cp > linebuf && cp[-1] == '\r')
		cp--;
	*cp = '\0';
	rc = grok_mode_name(linebuf, mode_out);
	if (rc < 0) {
		fprintf(stderr, "%s line %d: invalid mode setting\n",
			filename_for_errs, lineno);
		exit(1);
	}
}