annotate miscutil/gsmx-to-tw5a.c @ 521:68fe269b4316

gsmx-to-tw5a: actually write to the output file
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 19 Sep 2024 02:21:08 +0000
parents 785b302992f0
children 5595293e4f29
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
521
68fe269b4316 gsmx-to-tw5a: actually write to the output file
Mychaela Falconia <falcon@freecalypso.org>
parents: 520
diff changeset
19 emit_hex_frame(outf, frame, nbytes)
68fe269b4316 gsmx-to-tw5a: actually write to the output file
Mychaela Falconia <falcon@freecalypso.org>
parents: 520
diff changeset
20 FILE *outf;
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
21 uint8_t *frame;
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
22 unsigned nbytes;
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
23 {
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
24 unsigned n;
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
25
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
26 for (n = 0; n < nbytes; n++)
521
68fe269b4316 gsmx-to-tw5a: actually write to the output file
Mychaela Falconia <falcon@freecalypso.org>
parents: 520
diff changeset
27 fprintf(outf, "%02X", frame[n]);
68fe269b4316 gsmx-to-tw5a: actually write to the output file
Mychaela Falconia <falcon@freecalypso.org>
parents: 520
diff changeset
28 putc('\n', outf);
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
29 }
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 {
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
34 FILE *binf, *outf;
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 unsigned frame_index;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 uint8_t frame[BINFILE_MAX_FRAME];
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
37 int rc;
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
39 if (argc != 3) {
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
40 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
41 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 binf = fopen(argv[1], "r");
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (!binf) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 perror(argv[1]);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
48 if (strcmp(argv[2], "-")) {
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
49 outf = fopen(argv[2], "w");
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
50 if (!outf) {
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
51 perror(argv[2]);
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
52 exit(1);
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
53 }
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
54 } else
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
55 outf = stdout;
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 for (frame_index = 0; ; frame_index++) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 rc = binfile_read_frame(binf, frame);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (rc < 0) {
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
59 fprintf(stderr,
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
60 "error: garbage in %s after %u frames\n",
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
61 argv[1], frame_index);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (!rc)
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 switch (frame[0] & 0xF0) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 case 0xB0:
521
68fe269b4316 gsmx-to-tw5a: actually write to the output file
Mychaela Falconia <falcon@freecalypso.org>
parents: 520
diff changeset
68 fprintf(outf, "%02X\n", 0xE6 | frame[1] & 1);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 case 0xC0:
521
68fe269b4316 gsmx-to-tw5a: actually write to the output file
Mychaela Falconia <falcon@freecalypso.org>
parents: 520
diff changeset
71 emit_hex_frame(outf, frame, EFR_RTP_FRAME_LEN);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 case 0xD0:
521
68fe269b4316 gsmx-to-tw5a: actually write to the output file
Mychaela Falconia <falcon@freecalypso.org>
parents: 520
diff changeset
74 emit_hex_frame(outf, frame, GSMFR_RTP_FRAME_LEN);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 break;
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 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 exit(0);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }