comparison trau-ul-prep/gsmx2tsrc.c @ 19:4ab8762be333

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