annotate amrtest/mode_file.c @ 500:66fb1fd032e6

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