FreeCalypso > hg > gsm-codec-lib
comparison miscutil/tw5a-to-gsmx.c @ 524:ddb2b00d582b
miscutil: new program tw5a-to-gsmx
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 19 Sep 2024 05:02:45 +0000 |
parents | miscutil/tw5a-dump.c@86d4ec69b36c |
children |
comparison
equal
deleted
inserted
replaced
523:86d4ec69b36c | 524:ddb2b00d582b |
---|---|
1 /* | |
2 * This program converts FR/EFR speech recordings from TW-TS-005 Annex A | |
3 * hexadecimal format into our older gsmx binary format. | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdint.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <strings.h> | |
11 #include "../libgsmfr2/tw_gsmfr.h" | |
12 #include "../libgsmefr/gsm_efr.h" | |
13 #include "../libtest/tw5reader.h" | |
14 | |
15 main(argc, argv) | |
16 char **argv; | |
17 { | |
18 FILE *hexf, *outf; | |
19 unsigned lineno; | |
20 uint8_t frame[TWTS005_MAX_FRAME]; | |
21 unsigned frame_len; | |
22 int rc; | |
23 | |
24 if (argc != 3) { | |
25 fprintf(stderr, "usage: %s input.hex output.gsmx\n", argv[0]); | |
26 exit(1); | |
27 } | |
28 hexf = fopen(argv[1], "r"); | |
29 if (!hexf) { | |
30 perror(argv[1]); | |
31 exit(1); | |
32 } | |
33 lineno = 0; | |
34 outf = fopen(argv[2], "w"); | |
35 if (!outf) { | |
36 perror(argv[2]); | |
37 exit(1); | |
38 } | |
39 for (;;) { | |
40 rc = twts005_read_frame(hexf, &lineno, frame, &frame_len); | |
41 if (rc < 0) { | |
42 fprintf(stderr, "%s line %u: not valid TW-TS-005\n", | |
43 argv[1], lineno); | |
44 exit(1); | |
45 } | |
46 if (!rc) | |
47 break; | |
48 switch (frame_len) { | |
49 case 0: | |
50 putc(0xBF, outf); | |
51 putc(0, outf); | |
52 break; | |
53 case 1: | |
54 if ((frame[0] & 0xF6) != 0xE6) | |
55 goto invalid; | |
56 putc(0xBF, outf); | |
57 putc(frame[0] & 1, outf); | |
58 break; | |
59 case GSMFR_RTP_FRAME_LEN: | |
60 if ((frame[0] & 0xF0) != 0xD0) | |
61 goto invalid; | |
62 fwrite(frame, 1, GSMFR_RTP_FRAME_LEN, outf); | |
63 break; | |
64 case GSMFR_RTP_FRAME_LEN+1: | |
65 if ((frame[0] & 0xF4) != 0xE0) | |
66 goto invalid; | |
67 if ((frame[1] & 0xF0) != 0xD0) | |
68 goto invalid; | |
69 if (frame[0] & 0x02) { | |
70 putc(0xBF, outf); | |
71 putc(frame[0] & 1, outf); | |
72 } else | |
73 fwrite(frame + 1, 1, GSMFR_RTP_FRAME_LEN, outf); | |
74 break; | |
75 case EFR_RTP_FRAME_LEN: | |
76 if ((frame[0] & 0xF0) != 0xC0) | |
77 goto invalid; | |
78 fwrite(frame, 1, EFR_RTP_FRAME_LEN, outf); | |
79 break; | |
80 case EFR_RTP_FRAME_LEN+1: | |
81 if ((frame[0] & 0xF4) != 0xE0) | |
82 goto invalid; | |
83 if ((frame[1] & 0xF0) != 0xC0) | |
84 goto invalid; | |
85 if (frame[0] & 0x02) { | |
86 putc(0xBF, outf); | |
87 putc(frame[0] & 1, outf); | |
88 } else | |
89 fwrite(frame + 1, 1, EFR_RTP_FRAME_LEN, outf); | |
90 break; | |
91 default: | |
92 invalid: | |
93 fprintf(stderr, | |
94 "%s line %u: not a valid FR or EFR frame\n", | |
95 argv[1], lineno); | |
96 exit(1); | |
97 } | |
98 } | |
99 exit(0); | |
100 } |