FreeCalypso > hg > gsm-net-reveng
annotate trau-decode/extr-main.c @ 69:cf60172895fe
pathloss: add sysmo-example-10w
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 25 Oct 2024 16:26:26 +0000 |
parents | 0565aaa84b17 |
children |
rev | line source |
---|---|
9
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program reads a 64 kbit/s timeslot recording file with a focus |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * on a single sub-timeslot just like trau-parse, but it needs to be |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * invoked with a starting and ending offset for the frame-aligned |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * portion of interest (found with trau-parse), and it saves (converts) |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * the selected stream of TRAU-UL frames to a Themyscira gsmx file. |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 */ |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <sys/types.h> |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdio.h> |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdint.h> |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdlib.h> |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <string.h> |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <strings.h> |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 static void |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 reduce_to_subslot(buf, right_shift) |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 uint8_t *buf; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 unsigned n; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 for (n = 0; n < 160; n++) { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 buf[n] >>= right_shift; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 buf[n] &= 3; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 static void |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 unpack_dibits(dibits, frame_bits) |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 uint8_t *dibits, *frame_bits; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 int i, inb; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 uint8_t *op; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 op = frame_bits; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 for (i = 0; i < 160; i++) { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 inb = dibits[i]; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (inb & 2) |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 *op++ = 1; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 else |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 *op++ = 0; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (inb & 1) |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 *op++ = 1; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 else |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 *op++ = 0; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 static unsigned |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 bits_to_num(bits, nbits) |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 uint8_t *bits; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 unsigned nbits; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 unsigned accum; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 unsigned n; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 accum = 0; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 for (n = 0; n < nbits; n++) { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 accum <<= 1; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (*bits) |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 accum |= 1; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 bits++; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 return accum; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 static void |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 collect_d_bits(frame_bits, d_bits) |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 uint8_t *frame_bits, *d_bits; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 bcopy(frame_bits + 33, d_bits, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 bcopy(frame_bits + 49, d_bits + 15, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 bcopy(frame_bits + 65, d_bits + 30, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 bcopy(frame_bits + 81, d_bits + 45, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 bcopy(frame_bits + 97, d_bits + 60, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 bcopy(frame_bits + 113, d_bits + 75, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 bcopy(frame_bits + 129, d_bits + 90, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 bcopy(frame_bits + 145, d_bits + 105, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 bcopy(frame_bits + 161, d_bits + 120, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 bcopy(frame_bits + 177, d_bits + 135, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 bcopy(frame_bits + 193, d_bits + 150, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 bcopy(frame_bits + 209, d_bits + 165, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 bcopy(frame_bits + 225, d_bits + 180, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 bcopy(frame_bits + 241, d_bits + 195, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 bcopy(frame_bits + 257, d_bits + 210, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 bcopy(frame_bits + 273, d_bits + 225, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 bcopy(frame_bits + 289, d_bits + 240, 15); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 bcopy(frame_bits + 305, d_bits + 255, 5); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 static void |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 process_frame(cur_offset, dibits, outf) |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 u_long cur_offset; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 uint8_t *dibits; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 FILE *outf; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 uint8_t frame_bits[320], d_bits[260]; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 unsigned c1_5; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 unpack_dibits(dibits, frame_bits); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 if (frame_bits[28]) { /* C12 aka BFI */ |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 putc(0xBF, outf); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 putc(frame_bits[31], outf); /* C15 aka TAF */ |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 return; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 collect_d_bits(frame_bits, d_bits); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 c1_5 = bits_to_num(frame_bits + 17, 5); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 switch (c1_5) { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 case 0x02: |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 convert_fr_frame(d_bits, outf); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 break; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 case 0x1A: |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 convert_efr_frame(d_bits, outf); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 break; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 default: |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 fprintf(stderr, |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 "error: unknown frame type 0x%x at file offset 0x%lx\n", |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 c1_5, cur_offset); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 exit(1); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 main(argc, argv) |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 char **argv; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 FILE *inf, *outf; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 int subslot, right_shift; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 u_long start_offset, end_offset, cur_offset; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 uint8_t readbuf[160]; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 int cc; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 if (argc != 6) { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 fprintf(stderr, "usage: %s binfile subslot start end outfile\n", |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 argv[0]); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 exit(1); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 inf = fopen(argv[1], "r"); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 if (!inf) { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 perror(argv[1]); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 exit(1); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 subslot = atoi(argv[2]); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 if (subslot < 0 || subslot > 3) { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 fprintf(stderr, "error: invalid subslot argument\n"); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 exit(1); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 right_shift = (3 - subslot) * 2; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 start_offset = strtoul(argv[3], 0, 0); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 fseek(inf, start_offset, SEEK_SET); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 end_offset = strtoul(argv[4], 0, 0); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 outf = fopen(argv[5], "w"); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 if (!outf) { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 perror(argv[5]); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 exit(1); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 for (cur_offset = start_offset; ; cur_offset += 160) { |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 if (end_offset && cur_offset >= end_offset) |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 break; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 cc = fread(readbuf, 1, 160, inf); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 if (cc < 160) |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 break; |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 reduce_to_subslot(readbuf, right_shift); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 process_frame(cur_offset, readbuf, outf); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 } |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 exit(0); |
0565aaa84b17
trau-decode: implement trau-extr program
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 } |