FreeCalypso > hg > gsm-codec-lib
comparison hrutil/rpf2hex.c @ 567:2fcb6b27ee9b
hrutil: new program gsmhr-rpf2hex
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 12 Feb 2025 02:32:21 +0000 |
parents | miscutil/gsmx-to-tw5a.c@5595293e4f29 |
children |
comparison
equal
deleted
inserted
replaced
566:62fe499ffc15 | 567:2fcb6b27ee9b |
---|---|
1 /* | |
2 * This program converts HRv1 speech recordings from ETSI TS 101 318 raw | |
3 * packed format (14 bytes per frame, good frames only) into our preferred | |
4 * TW-TS-005 Annex B format. | |
5 */ | |
6 | |
7 #include <stdio.h> | |
8 #include <stdint.h> | |
9 #include <stdlib.h> | |
10 #include <string.h> | |
11 #include <strings.h> | |
12 #include <unistd.h> | |
13 #include "../libgsmhr1/tw_gsmhr.h" | |
14 | |
15 static void | |
16 emit_hr1_hex_frame(outf, frame, emit_5993) | |
17 FILE *outf; | |
18 uint8_t *frame; | |
19 { | |
20 unsigned n; | |
21 | |
22 if (emit_5993) { | |
23 fprintf(outf, "%02X", | |
24 gsmhr_ts101318_is_perfect_sid(frame) << 4); | |
25 } | |
26 for (n = 0; n < GSMHR_FRAME_LEN_RPF; n++) | |
27 fprintf(outf, "%02X", frame[n]); | |
28 putc('\n', outf); | |
29 } | |
30 | |
31 main(argc, argv) | |
32 char **argv; | |
33 { | |
34 char *infname, *outfname; | |
35 FILE *inf, *outf; | |
36 int opt, cc, emit_5993 = 0; | |
37 uint8_t frame[GSMHR_FRAME_LEN_RPF]; | |
38 extern int optind; | |
39 | |
40 while ((opt = getopt(argc, argv, "x")) != EOF) { | |
41 switch (opt) { | |
42 case 'x': | |
43 emit_5993 = 1; | |
44 continue; | |
45 default: | |
46 usage: | |
47 fprintf(stderr, | |
48 "usage: %s [-x] input.hrpf output.hex\n", | |
49 argv[0]); | |
50 exit(1); | |
51 } | |
52 } | |
53 if (argc != optind + 2) | |
54 goto usage; | |
55 infname = argv[optind]; | |
56 outfname = argv[optind+1]; | |
57 | |
58 inf = fopen(infname, "r"); | |
59 if (!inf) { | |
60 perror(infname); | |
61 exit(1); | |
62 } | |
63 outf = fopen(outfname, "w"); | |
64 if (!outf) { | |
65 perror(outfname); | |
66 exit(1); | |
67 } | |
68 | |
69 for (;;) { | |
70 cc = fread(frame, 1, GSMHR_FRAME_LEN_RPF, inf); | |
71 if (cc == 0) | |
72 break; | |
73 if (cc != GSMHR_FRAME_LEN_RPF) { | |
74 fprintf(stderr, "error: short read from %s\n", infname); | |
75 exit(1); | |
76 } | |
77 emit_hr1_hex_frame(outf, frame, emit_5993); | |
78 } | |
79 exit(0); | |
80 } |