annotate amrtest/encode-r.c @ 542:f2d0f2f15d5f

libgsmefr: add wrapper for TW-TS-001 RTP input
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 28 Sep 2024 06:38:08 +0000
parents 30cff6b60890
children
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 /*
445
30cff6b60890 amrtest: implement twamr-encode-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 443
diff changeset
2 * twamr-encode-r is a speech encoder utility going from "robe" (raw BE)
30cff6b60890 amrtest: implement twamr-encode-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 443
diff changeset
3 * input to RFC 4867 storage format (.amr) output.
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
11 #include <unistd.h>
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
12 #include "../libtwamr/tw_amr.h"
445
30cff6b60890 amrtest: implement twamr-encode-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 443
diff changeset
13 #include "../libtest/roberead.h"
114
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 main(argc, argv)
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char **argv;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
18 char *infname, *outfname, *mode_arg;
445
30cff6b60890 amrtest: implement twamr-encode-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 443
diff changeset
19 FILE *inf, *outf;
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
20 struct amr_encoder_state *state;
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
21 enum Mode mode_val;
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int16_t pcm[160];
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
23 struct amr_param_frame frame;
443
526a7f0e027d amrtest: implement twamr-encode
Mychaela Falconia <falcon@freecalypso.org>
parents: 423
diff changeset
24 uint8_t out_bytes[AMR_IETF_MAX_PL];
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
25 int opt, dtx = 0, vad2 = 0, use_mode_file = 0, rc;
443
526a7f0e027d amrtest: implement twamr-encode
Mychaela Falconia <falcon@freecalypso.org>
parents: 423
diff changeset
26 unsigned nbytes;
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
27 extern int optind;
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
29 while ((opt = getopt(argc, argv, "d2")) != EOF) {
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
30 switch (opt) {
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
31 case 'd':
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
32 dtx = 1;
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
33 continue;
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
34 case '2':
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
35 vad2 = 1;
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
36 continue;
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
37 default:
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
38 usage:
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
39 fprintf(stderr,
445
30cff6b60890 amrtest: implement twamr-encode-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 443
diff changeset
40 "usage: %s [-d] [-2] input.robe mode output.amr\n",
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
41 argv[0]);
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
42 exit(1);
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
43 }
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
45 if (argc != optind + 3)
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
46 goto usage;
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
47 infname = argv[optind];
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
48 mode_arg = argv[optind+1];
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
49 outfname = argv[optind+2];
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
50
445
30cff6b60890 amrtest: implement twamr-encode-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 443
diff changeset
51 inf = fopen(infname, "r");
30cff6b60890 amrtest: implement twamr-encode-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 443
diff changeset
52 if (!inf) {
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 perror(infname);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 exit(1);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
56 if (!strncmp(mode_arg, "file:", 5)) {
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
57 open_mode_file(mode_arg + 5);
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
58 use_mode_file = 1;
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
59 } else {
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
60 rc = grok_mode_name(mode_arg, &mode_val);
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
61 if (rc < 0) {
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
62 fprintf(stderr, "error: invalid mode argument \"%s\"\n",
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
63 mode_arg);
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
64 exit(1);
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
65 }
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
66 }
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 outf = fopen(outfname, "w");
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (!outf) {
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 perror(outfname);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 exit(1);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
72 state = amr_encoder_create(dtx, vad2);
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 if (!state) {
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
74 perror("amr_encoder_create()");
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 exit(1);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }
443
526a7f0e027d amrtest: implement twamr-encode
Mychaela Falconia <falcon@freecalypso.org>
parents: 423
diff changeset
77 fwrite(amr_file_header_magic, 1, AMR_IETF_HDR_LEN, outf);
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 for (;;) {
445
30cff6b60890 amrtest: implement twamr-encode-r
Mychaela Falconia <falcon@freecalypso.org>
parents: 443
diff changeset
79 rc = robe_get_pcm_block(inf, pcm);
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 if (!rc)
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 break;
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
82 if (use_mode_file)
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
83 read_mode_file_line(&mode_val);
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
84 amr_encode_frame(state, mode_val, pcm, &frame);
443
526a7f0e027d amrtest: implement twamr-encode
Mychaela Falconia <falcon@freecalypso.org>
parents: 423
diff changeset
85 nbytes = amr_frame_to_ietf(&frame, out_bytes);
526a7f0e027d amrtest: implement twamr-encode
Mychaela Falconia <falcon@freecalypso.org>
parents: 423
diff changeset
86 fwrite(out_bytes, 1, nbytes, outf);
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 fclose(outf);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 exit(0);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 }