comparison hrutil/etsi-enc.c @ 627:45e727b53da1

hrutil: new program gsmhr-etsi-enc
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 12 Mar 2026 04:46:03 +0000
parents efrtest/etsi-enc.c@51678b070c7a
children
comparison
equal deleted inserted replaced
626:c15ae3f06ee9 627:45e727b53da1
1 /*
2 * gsmhr-etsi-enc is a test program for our GSM-HR encoder: it reads raw
3 * 16-bit PCM (matching ETSI's *.inp) as input and writes ETSI's *.cod
4 * format as output, allowing our encoder to be tested with ETSI's
5 * official test sequences.
6 *
7 * ETSI input and output files are read and written in the local machine's
8 * native byte order by default; -b and -l options can be used to force
9 * BE or LE, respectively.
10 */
11
12 #include <stdio.h>
13 #include <stdint.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <strings.h>
17 #include <unistd.h>
18 #include "../libgsmhr1/tw_gsmhr.h"
19 #include "../libtest/local_endian.h"
20
21 static int
22 read_input(inf, pcm, filename_for_errs, big_endian)
23 FILE *inf;
24 int16_t *pcm;
25 char *filename_for_errs;
26 {
27 uint8_t file_bytes[320], *sp;
28 int cc;
29 unsigned n;
30
31 cc = fread(file_bytes, 2, 160, inf);
32 if (cc == 0)
33 return 0;
34 if (cc != 160) {
35 fprintf(stderr, "error: short read from %s\n",
36 filename_for_errs);
37 exit(1);
38 }
39 sp = file_bytes;
40 for (n = 0; n < 160; n++) {
41 if (big_endian)
42 pcm[n] = (sp[0] << 8) | sp[1];
43 else
44 pcm[n] = sp[0] | (sp[1] << 8);
45 sp += 2;
46 }
47 return 1;
48 }
49
50 main(argc, argv)
51 char **argv;
52 {
53 char *infname, *outfname;
54 FILE *inf, *outf;
55 int opt, rc, big_endian, dtx = 0;
56 struct gsmhr_encoder_state *state;
57 int16_t pcm[160];
58 int16_t prm_out[GSMHR_NUM_PARAMS_ENC];
59 extern int optind;
60
61 big_endian = is_native_big_endian();
62 while ((opt = getopt(argc, argv, "bdl")) != EOF) {
63 switch (opt) {
64 case 'b':
65 big_endian = 1;
66 continue;
67 case 'd':
68 dtx = 1;
69 continue;
70 case 'l':
71 big_endian = 0;
72 continue;
73 default:
74 usage:
75 fprintf(stderr,
76 "usage: %s [-b|-l] [-d] input.inp output.cod\n",
77 argv[0]);
78 exit(1);
79 }
80 }
81 if (argc != optind + 2)
82 goto usage;
83 infname = argv[optind];
84 outfname = argv[optind+1];
85
86 inf = fopen(infname, "r");
87 if (!inf) {
88 perror(infname);
89 exit(1);
90 }
91 outf = fopen(outfname, "w");
92 if (!outf) {
93 perror(outfname);
94 exit(1);
95 }
96 state = gsmhr_encoder_create(dtx);
97 if (!state) {
98 perror("gsmhr_encoder_create()");
99 exit(1);
100 }
101 for (;;) {
102 rc = read_input(inf, pcm, infname, big_endian);
103 if (!rc)
104 break;
105 gsmhr_encode_frame(state, pcm, prm_out);
106 emit_cod_to_endian(outf, prm_out, big_endian);
107 }
108 fclose(outf);
109 exit(0);
110 }