annotate efrtest/etsi-enc.c @ 181:3a0ee08a3b9d

doc/EFR-rationale: typo fix
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 02 Jan 2023 20:09:07 +0000
parents a13b1605142b
children d4f47d0962e7
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 /*
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * gsmefr-etsi-enc is a test program for our EFR encoder: it reads raw
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * 16-bit PCM (matching ETSI's *.inp) as input and writes ETSI's *.cod
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * format as output, allowing our decoder to be tested with ETSI's
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 *
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * ETSI input and output files are read and written in LE byte order,
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 * matching the official test sequences in ts_100725v050200p0.zip.
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>
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "../libgsmefr/gsm_efr.h"
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
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
20 read_input(inf, pcm, filename_for_errs, big_endian)
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 uint8_t file_bytes[320], *sp;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 int cc;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 unsigned n;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 cc = fread(file_bytes, 2, 160, inf);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (cc == 0)
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return 0;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (cc != 160) {
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 fprintf(stderr, "error: short read from %s\n",
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 filename_for_errs);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 exit(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 sp = file_bytes;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 for (n = 0; n < 160; n++) {
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
39 if (big_endian)
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
40 pcm[n] = (sp[0] << 8) | sp[1];
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
41 else
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
42 pcm[n] = sp[0] | (sp[1] << 8);
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 sp += 2;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 return 1;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 static void
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 frame2bits(frame, bits)
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 uint8_t *frame, *bits;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 {
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 unsigned nb, byte, mask, bit;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 for (nb = 0; nb < EFR_RTP_FRAME_LEN; nb++) {
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 byte = *frame++;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 for (mask = 0x80; mask; mask >>= 1) {
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (byte & mask)
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 bit = 1;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 else
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 bit = 0;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 *bits++ = bit;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 static void
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
67 emit_output(outf, bits, nbits, big_endian)
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 FILE *outf;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 uint8_t *bits;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 unsigned nbits;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 {
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 unsigned n;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 for (n = 0; n < nbits; n++) {
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
75 if (big_endian) {
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
76 putc(0, outf);
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
77 putc(bits[n], outf);
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
78 } else {
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
79 putc(bits[n], outf);
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
80 putc(0, outf);
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
81 }
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 main(argc, argv)
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 char **argv;
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 char *infname, *outfname;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 FILE *inf, *outf;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 struct EFR_encoder_state *state;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 int16_t pcm[160];
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 uint8_t frame[EFR_RTP_FRAME_LEN], bits[250];
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
93 int opt, dtx = 0, rc, sp, vad, big_endian = 0;
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
94 extern int optind;
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
96 while ((opt = getopt(argc, argv, "bd")) != EOF) {
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
97 switch (opt) {
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
98 case 'b':
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
99 big_endian = 1;
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
100 continue;
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
101 case 'd':
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
102 dtx = 1;
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
103 continue;
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
104 default:
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
105 usage:
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
106 fprintf(stderr,
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
107 "usage: %s [-b] [-d] input.inp output.cod\n",
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
108 argv[0]);
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
109 exit(1);
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
110 }
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
112 if (argc != optind + 2)
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
113 goto usage;
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
114 infname = argv[optind];
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
115 outfname = argv[optind+1];
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
116
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 inf = fopen(infname, "r");
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 if (!inf) {
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 perror(infname);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 exit(1);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 outf = fopen(outfname, "w");
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 if (!outf) {
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 perror(outfname);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 exit(1);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 state = EFR_encoder_create(dtx);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 if (!state) {
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 perror("EFR_encoder_create()");
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 exit(1);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 for (;;) {
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
133 rc = read_input(inf, pcm, infname, big_endian);
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 if (!rc)
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 break;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 EFR_encode_frame(state, pcm, frame, &sp, &vad);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 frame2bits(frame, bits);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 bits[248] = vad;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 bits[249] = sp;
151
a13b1605142b gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents: 114
diff changeset
140 emit_output(outf, bits + 4, 246, big_endian);
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 }
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 fclose(outf);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 exit(0);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 }