comparison amrtest/mode_file.c @ 422:1ceda5586d01

implement twamr-tseq-enc test program
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 07 May 2024 06:27:20 +0000
parents
children
comparison
equal deleted inserted replaced
421:09534cdc59ec 422:1ceda5586d01
1 /*
2 * The functions in this module implement reading per-frame encoder mode
3 * instructions from a file, as in 3GPP test sequences and code.
4 */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <strings.h>
10 #include "../libtwamr/tw_amr.h"
11
12 static FILE *mode_file;
13 static int lineno;
14 static char *filename_for_errs;
15
16 void
17 open_mode_file(filename)
18 char *filename;
19 {
20 mode_file = fopen(filename, "r");
21 if (!mode_file) {
22 perror(filename);
23 exit(1);
24 }
25 }
26
27 void
28 read_mode_file_line(mode_out)
29 enum Mode *mode_out;
30 {
31 char linebuf[16], *cp;
32 int rc;
33
34 if (!fgets(linebuf, sizeof linebuf, mode_file)) {
35 fprintf(stderr, "error: %s ends before speech input\n",
36 filename_for_errs);
37 exit(1);
38 }
39 lineno++;
40 cp = index(linebuf, '\n');
41 if (!cp) {
42 fprintf(stderr, "%s line %d: too long or missing newline\n",
43 filename_for_errs, lineno);
44 exit(1);
45 }
46 if (cp > linebuf && cp[-1] == '\r')
47 cp--;
48 *cp = '\0';
49 rc = grok_mode_name(linebuf, mode_out);
50 if (rc < 0) {
51 fprintf(stderr, "%s line %d: invalid mode setting\n",
52 filename_for_errs, lineno);
53 exit(1);
54 }
55 }