annotate amrefr/tseq-enc.c @ 458:e26b974f7ba3

doc/AMR-study-utils: update for the current situation
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 10 May 2024 18:45:36 +0000
parents ba5031723ab6
children 026bdc1f0dda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
434
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
2 * amrefr-tseq-enc is a test program for our libtwamr-based "alternative EFR"
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
3 * encoder: it functions just like gsmefr-etsi-enc, but uses libtwamr as
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
4 * the encoder engine instead of libgsmefr. Libgsmefr functions are still
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
5 * used for frame packing, but not for actual encoding. Note that there is
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
6 * no -d option in this version, and no DTX encoding support: a DTX-capable
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
7 * AMR-EFR hybrid is a beast that is currently outside our capabilities.
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 *
434
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
9 * The byte order is LE by default or BE with -b option. Practical testing
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
10 * will always require some manual byte-swap conversion: t??_efr.cod files
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
11 * in amr122_efr.zip are shipped in BE, but the corresponding t??.inp files
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
12 * in the 06.74 package are LE.
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 */
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <stdio.h>
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <stdint.h>
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include <stdlib.h>
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include <string.h>
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include <strings.h>
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
20 #include <unistd.h>
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #include "../libgsmefr/gsm_efr.h"
434
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
22 #include "../libtwamr/tw_amr.h"
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 main(argc, argv)
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 char **argv;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 {
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 char *infname, *outfname;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 FILE *inf, *outf;
434
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
29 struct amr_encoder_state *state;
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 int16_t pcm[160];
434
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
31 struct amr_param_frame amr_frame;
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
32 uint8_t efr_frame[EFR_RTP_FRAME_LEN], bits[250];
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
33 int opt, rc, big_endian = 0;
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
34 extern int optind;
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
434
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
36 while ((opt = getopt(argc, argv, "b")) != EOF) {
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
37 switch (opt) {
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
38 case 'b':
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
39 big_endian = 1;
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
40 continue;
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
41 default:
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
42 usage:
434
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
43 fprintf(stderr, "usage: %s [-b] input.inp output.cod\n",
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
44 argv[0]);
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
45 exit(1);
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
46 }
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
48 if (argc != optind + 2)
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
49 goto usage;
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
50 infname = argv[optind];
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
51 outfname = argv[optind+1];
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
52
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 inf = fopen(infname, "r");
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (!inf) {
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 perror(infname);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 exit(1);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 outf = fopen(outfname, "w");
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 if (!outf) {
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 perror(outfname);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 exit(1);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
434
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
63 state = amr_encoder_create(0, 0);
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (!state) {
434
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
65 perror("amr_encoder_create()");
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 exit(1);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 for (;;) {
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
69 rc = read_input(inf, pcm, infname, big_endian);
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (!rc)
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 break;
434
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
72 amr_encode_frame(state, MR122, pcm, &amr_frame);
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
73 amr_dhf_subst_efr(&amr_frame);
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
74 EFR_params2frame(amr_frame.param, efr_frame);
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
75 frame2bits(efr_frame, bits);
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
76 bits[248] = 1;
ba5031723ab6 implement amrefr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 433
diff changeset
77 bits[249] = 1;
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
78 emit_output(outf, bits + 4, 246, big_endian);
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 fclose(outf);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 exit(0);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }