comparison trau-ul-compile/trau-ul-decomp.c @ 26:f80e64139670

trau-ul-decomp program written
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 24 Jun 2024 01:50:02 +0000
parents
children
comparison
equal deleted inserted replaced
25:118a4e4268b2 26:f80e64139670
1 /*
2 * This program reads a *.tul binary file and disassembles it back
3 * to ASCII form. It is intended for checking the correctness of
4 * trau-ul-compile, and also for sanity checks during actual TRAU
5 * testing with these tools.
6 */
7
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <strings.h>
13 #include <tw_gsmfr.h>
14 #include <gsm_efr.h>
15
16 main(argc, argv)
17 char **argv;
18 {
19 FILE *binf, *outf;
20 unsigned frame_index;
21 uint8_t frame[34];
22 int16_t params[GSMFR_NUM_PARAMS];
23 int rc, i, j, n;
24
25 if (argc < 2 || argc > 3) {
26 fprintf(stderr, "usage: %s input.tul [output.tsrc]\n",
27 argv[0]);
28 exit(1);
29 }
30 binf = fopen(argv[1], "r");
31 if (!binf) {
32 perror(argv[1]);
33 exit(1);
34 }
35 if (argc > 2) {
36 outf = fopen(argv[2], "w");
37 if (!outf) {
38 perror(argv[2]);
39 exit(1);
40 }
41 } else
42 outf = stdout;
43 for (frame_index = 0; ; frame_index++) {
44 rc = fread(frame, 1, 34, binf);
45 if (!rc)
46 break;
47 if (rc != 34) {
48 inv_input: fprintf(stderr, "error: %s is not in expected format\n",
49 argv[1]);
50 exit(1);
51 }
52 switch (frame[0] & 0xF0) {
53 case 0xC0:
54 fprintf(outf, "# input frame %u\nFrame_EFR {\n",
55 frame_index);
56 if (frame_index % 24 == 23)
57 fputs("\t# TAF position\n", outf);
58 fprintf(outf, "\tBFI %u\n", frame[33] >> 7);
59 EFR_frame2params(frame, params);
60 n = 0;
61 fputs("\tLPC", outf);
62 for (i = 0; i < 5; i++)
63 fprintf(outf, " %d", params[n++]);
64 putc('\n', outf);
65 for (i = 0; i < 4; i++) {
66 fputs("\tsf", outf);
67 for (j = 0; j < 13; j++)
68 fprintf(outf, " %d", params[n++]);
69 putc('\n', outf);
70 }
71 fprintf(outf, "\tSID %u\n", frame[33] & 3);
72 fputs("}\n\n", outf);
73 break;
74 case 0xD0:
75 fprintf(outf, "# input frame %u\nFrame_FR {\n",
76 frame_index);
77 if (frame_index % 24 == 23)
78 fputs("\t# TAF position\n", outf);
79 fprintf(outf, "\tBFI %u\n", frame[33] >> 7);
80 gsmfr_unpack_to_array(frame, params);
81 n = 0;
82 fputs("\tLARc", outf);
83 for (i = 0; i < 8; i++)
84 fprintf(outf, " %d", params[n++]);
85 putc('\n', outf);
86 for (i = 0; i < 4; i++) {
87 fputs("\tsf", outf);
88 for (j = 0; j < 17; j++)
89 fprintf(outf, " %d", params[n++]);
90 putc('\n', outf);
91 }
92 fprintf(outf, "\tSID %u\n", frame[33] & 3);
93 fputs("}\n\n", outf);
94 break;
95 default:
96 goto inv_input;
97 }
98 }
99 exit(0);
100 }