annotate trau-ul-prep/gsmx2tsrc.c @ 21:453461ad9c15

top Makefile: add trau-ul-prep
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 23 Jun 2024 22:05:17 +0000
parents 7cd046ffefe7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program reads a binary file in ThemWi gsmx format
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * and converts it into ASCII source for TRAU-UL construction.
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdint.h>
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <tw_gsmfr.h>
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <gsm_efr.h>
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "binreader.h"
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 main(argc, argv)
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char **argv;
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 FILE *binf, *outf;
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 unsigned frame_index;
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 uint8_t frame[BINFILE_MAX_FRAME];
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 int16_t params[GSMFR_NUM_PARAMS];
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int rc, i, j, n;
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 if (argc < 2 || argc > 3) {
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 fprintf(stderr, "usage: %s input.gsmx [output.tsrc]\n",
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 argv[0]);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 exit(1);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 binf = fopen(argv[1], "r");
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (!binf) {
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 perror(argv[1]);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 exit(1);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (argc > 2) {
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 outf = fopen(argv[2], "w");
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (!outf) {
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 perror(argv[2]);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 exit(1);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 } else
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 outf = stdout;
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 for (frame_index = 0; ; frame_index++) {
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 rc = binfile_read_frame(binf, frame);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (rc < 0) {
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 fprintf(stderr, "error: garbage in %s\n", argv[1]);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 exit(1);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (!rc)
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 break;
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 switch (frame[0] & 0xF0) {
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 case 0xB0:
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 fprintf(outf, "# input frame %u is BFI\n\n",
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 frame_index);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 break;
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 case 0xC0:
20
7cd046ffefe7 gsmx2tsrc: print input frame number comments on separate lines
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
56 fprintf(outf, "# input frame %u\nFrame_EFR {\n",
19
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 frame_index);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 EFR_frame2params(frame, params);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 n = 0;
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 fputs("\tLPC", outf);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 for (i = 0; i < 5; i++)
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 fprintf(outf, " %d", params[n++]);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 putc('\n', outf);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 for (i = 0; i < 4; i++) {
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 fputs("\tsf", outf);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 for (j = 0; j < 13; j++)
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 fprintf(outf, " %d", params[n++]);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 putc('\n', outf);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 fputs("}\n\n", outf);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 break;
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 case 0xD0:
20
7cd046ffefe7 gsmx2tsrc: print input frame number comments on separate lines
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
73 fprintf(outf, "# input frame %u\nFrame_FR {\n",
19
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 frame_index);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 gsmfr_unpack_to_array(frame, params);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 n = 0;
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 fputs("\tLARc", outf);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 for (i = 0; i < 8; i++)
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 fprintf(outf, " %d", params[n++]);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 putc('\n', outf);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 for (i = 0; i < 4; i++) {
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 fputs("\tsf", outf);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 for (j = 0; j < 17; j++)
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 fprintf(outf, " %d", params[n++]);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 putc('\n', outf);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 fputs("}\n\n", outf);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 break;
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 }
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 exit(0);
4ab8762be333 trau-ul-prep: starting with gsmx2tsrc program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }