comparison hrutil/tfo-xfrm.c @ 584:fc7a59deb3c3 default tip

hrutil: new program gsmhr-tfo-xfrm
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 14 Feb 2025 01:34:48 +0000
parents frtest/tfo-xfrm.c@b26df31124a4
children
comparison
equal deleted inserted replaced
583:9cda792c0dd7 584:fc7a59deb3c3
1 /*
2 * This program exercises our ThemWi implementation of TFO transform for
3 * GSM-HR. It reads a stream of radio leg A Rx frames from a TW-TS-005 Annex B
4 * hex file and writes the "pristine" stream intended for radio leg B Tx
5 * into another TW-TS-005 Annex B hex file. DTXd can be enabled or disabled;
6 * the output can be in either TS 101 318 or RFC 5993 format.
7 */
8
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include "../libgsmhr1/tw_gsmhr.h"
14 #include "../libtest/tw5reader.h"
15
16 main(argc, argv)
17 char **argv;
18 {
19 char *infname, *outfname;
20 FILE *inf, *outf;
21 unsigned lineno;
22 struct gsmhr_rxfe_state *state;
23 uint8_t frame_in[TWTS005_MAX_FRAME];
24 unsigned frame_in_len;
25 int16_t prm_in[GSMHR_NUM_PARAMS_DEC], prm_out[GSMHR_NUM_PARAMS_ENC];
26 int opt, rc, dtxd = 0, emit_5993 = 0;
27 extern int optind;
28
29 while ((opt = getopt(argc, argv, "dx")) != EOF) {
30 switch (opt) {
31 case 'd':
32 dtxd = 1;
33 continue;
34 case 'x':
35 emit_5993 = 1;
36 continue;
37 default:
38 usage:
39 fprintf(stderr,
40 "usage: %s [-d] [-x] input.hex output.hex\n",
41 argv[0]);
42 exit(1);
43 }
44 }
45 if (argc != optind + 2)
46 goto usage;
47 infname = argv[optind];
48 outfname = argv[optind+1];
49
50 inf = fopen(infname, "r");
51 if (!inf) {
52 perror(infname);
53 exit(1);
54 }
55 lineno = 0;
56 outf = fopen(outfname, "w");
57 if (!outf) {
58 perror(outfname);
59 exit(1);
60 }
61 state = gsmhr_rxfe_create();
62 if (!state) {
63 fprintf(stderr, "gsmhr_rxfe_create() failed!\n");
64 exit(1);
65 }
66 for (;;) {
67 rc = twts005_read_frame(inf, &lineno, frame_in, &frame_in_len);
68 if (rc < 0) {
69 fprintf(stderr, "%s line %u: not valid TW-TS-005\n",
70 argv[1], lineno);
71 exit(1);
72 }
73 if (!rc)
74 break;
75 rc = gsmhr_rtp_in_direct(frame_in, frame_in_len, prm_in);
76 if (rc < 0) {
77 fprintf(stderr,
78 "%s line %u: not a valid GSM-HR frame\n",
79 infname, lineno);
80 exit(1);
81 }
82 gsmhr_tfo_xfrm(state, dtxd, prm_in, prm_out);
83 emit_cod_to_tw5b(outf, prm_out, emit_5993);
84 }
85 fclose(outf);
86 exit(0);
87 }