annotate hrutil/rpf2hex.c @ 569:0d05892150cf

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