FreeCalypso > hg > gsm-codec-lib
annotate amrtest/tseq-enc.c @ 515:bb36ef735f25
hrutil: starting with gsmhr-cod-parse
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 30 Aug 2024 08:05:07 +0000 |
parents | cf90077b753c |
children |
rev | line source |
---|---|
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
2 * twamr-tseq-enc is a test program for our AMR encoder: it reads raw |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
3 * 16-bit PCM (matching 3GPP *.inp) as input and writes 3GPP *.cod |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
4 * format as output, allowing libtwamr encoder to be tested with the |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * official test sequences. |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
7 * Both input and output are read/written in the host machine's |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
8 * native byte order. |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 */ |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdio.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdint.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <stdlib.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <string.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <strings.h> |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
16 #include <unistd.h> |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
17 #include "../libtwamr/tw_amr.h" |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 static int |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
20 read_input(inf, pcm, filename_for_errs) |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 FILE *inf; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int16_t *pcm; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 char *filename_for_errs; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 int cc; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
27 cc = fread(pcm, 2, 160, inf); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (cc == 0) |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 return 0; |
423
cf90077b753c
twamr-tseq-enc: treat dribble input as non-fatal
Mychaela Falconia <falcon@freecalypso.org>
parents:
422
diff
changeset
|
30 if (cc < 160) { |
cf90077b753c
twamr-tseq-enc: treat dribble input as non-fatal
Mychaela Falconia <falcon@freecalypso.org>
parents:
422
diff
changeset
|
31 fprintf(stderr, "warning: incomplete frame at the end of %s\n", |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 filename_for_errs); |
423
cf90077b753c
twamr-tseq-enc: treat dribble input as non-fatal
Mychaela Falconia <falcon@freecalypso.org>
parents:
422
diff
changeset
|
33 return 0; |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return 1; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 main(argc, argv) |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 char **argv; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 { |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
41 char *infname, *outfname, *mode_arg; |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 FILE *inf, *outf; |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
43 struct amr_encoder_state *state; |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
44 enum Mode mode_val; |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 int16_t pcm[160]; |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
46 struct amr_param_frame frame; |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
47 uint16_t cod_words[AMR_COD_WORDS]; |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
48 int opt, dtx = 0, vad2 = 0, use_mode_file = 0, rc; |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
49 extern int optind; |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
51 while ((opt = getopt(argc, argv, "d2")) != EOF) { |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
52 switch (opt) { |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
53 case 'd': |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
54 dtx = 1; |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
55 continue; |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
56 case '2': |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
57 vad2 = 1; |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
58 continue; |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
59 default: |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
60 usage: |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
61 fprintf(stderr, |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
62 "usage: %s [-d] [-2] input.inp mode output.cod\n", |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
63 argv[0]); |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
64 exit(1); |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
65 } |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
67 if (argc != optind + 3) |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
68 goto usage; |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
69 infname = argv[optind]; |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
70 mode_arg = argv[optind+1]; |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
71 outfname = argv[optind+2]; |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
72 |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 inf = fopen(infname, "r"); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (!inf) { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 perror(infname); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 exit(1); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
78 if (!strncmp(mode_arg, "file:", 5)) { |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
79 open_mode_file(mode_arg + 5); |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
80 use_mode_file = 1; |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
81 } else { |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
82 rc = grok_mode_name(mode_arg, &mode_val); |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
83 if (rc < 0) { |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
84 fprintf(stderr, "error: invalid mode argument \"%s\"\n", |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
85 mode_arg); |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
86 exit(1); |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
87 } |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
88 } |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 outf = fopen(outfname, "w"); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (!outf) { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 perror(outfname); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 exit(1); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 } |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
94 state = amr_encoder_create(dtx, vad2); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 if (!state) { |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
96 perror("amr_encoder_create()"); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 exit(1); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 for (;;) { |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
100 rc = read_input(inf, pcm, infname); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 if (!rc) |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 break; |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
103 if (use_mode_file) |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
104 read_mode_file_line(&mode_val); |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
105 amr_encode_frame(state, mode_val, pcm, &frame); |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
106 amr_frame_to_tseq(&frame, cod_words); |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
107 fwrite(cod_words, 2, AMR_COD_WORDS, outf); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 fclose(outf); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 exit(0); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 } |