annotate miscutil/gsmx-to-tw5a.c @ 520:785b302992f0

miscutil: new program gsmx-to-tw5a
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 19 Sep 2024 01:06:58 +0000
parents miscutil/gsmrec-dump.c@b5f8ea41362b
children 68fe269b4316
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 /*
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
2 * This program converts FR/EFR speech recordings from gsmx binary format
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
3 * into more formally standardized TW-TS-005 Annex A format.
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
4 *
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
5 * FR and EFR frames are written in basic format (no TEH);
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
6 * BFI marker records are converted into TW-TS-001 No_Data frames.
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 */
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
471
b5f8ea41362b gsmrec-dump: report DHF matches
Mychaela Falconia <falcon@freecalypso.org>
parents: 293
diff changeset
12 #include <string.h>
b5f8ea41362b gsmrec-dump: report DHF matches
Mychaela Falconia <falcon@freecalypso.org>
parents: 293
diff changeset
13 #include <strings.h>
281
3816ba89a5a0 gsmrec-dump: use libgsmfr2 instead of old libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents: 128
diff changeset
14 #include "../libgsmfr2/tw_gsmfr.h"
46
edd2e20e7090 gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents: 23
diff changeset
15 #include "../libgsmefr/gsm_efr.h"
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../libtest/binreader.h"
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
18 static void
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
19 emit_hex_frame(frame, nbytes)
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
20 uint8_t *frame;
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
21 unsigned nbytes;
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
22 {
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
23 unsigned n;
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
24
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
25 for (n = 0; n < nbytes; n++)
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
26 printf("%02X", frame[n]);
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
27 putchar('\n');
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
28 }
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
29
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 main(argc, argv)
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 char **argv;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 {
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
33 FILE *binf, *outf;
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 unsigned frame_index;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 uint8_t frame[BINFILE_MAX_FRAME];
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
36 int rc;
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
38 if (argc != 3) {
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
39 fprintf(stderr, "usage: %s input.gsmx output.hex\n", argv[0]);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 binf = fopen(argv[1], "r");
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (!binf) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 perror(argv[1]);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
47 if (strcmp(argv[2], "-")) {
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
48 outf = fopen(argv[2], "w");
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
49 if (!outf) {
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
50 perror(argv[2]);
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
51 exit(1);
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
52 }
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
53 } else
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
54 outf = stdout;
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 for (frame_index = 0; ; frame_index++) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 rc = binfile_read_frame(binf, frame);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (rc < 0) {
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
58 fprintf(stderr,
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
59 "error: garbage in %s after %u frames\n",
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
60 argv[1], frame_index);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (!rc)
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 switch (frame[0] & 0xF0) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 case 0xB0:
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
67 printf("%02X\n", 0xE6 | frame[1] & 1);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 case 0xC0:
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
70 emit_hex_frame(frame, EFR_RTP_FRAME_LEN);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 case 0xD0:
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
73 emit_hex_frame(frame, GSMFR_RTP_FRAME_LEN);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 exit(0);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 }