annotate miscutil/gsmx-to-tw5a.c @ 555:62943a1ad64e

doc/FR1-Rx-DTX-detail: grammar fix
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 11 Oct 2024 00:22:47 +0000
parents 5595293e4f29
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 /*
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"
540
5595293e4f29 gsmx-to-tw5a utility: use emit_hex_frame() in libtest
Mychaela Falconia <falcon@freecalypso.org>
parents: 521
diff changeset
17 #include "../libtest/tw5writer.h"
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
18
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 main(argc, argv)
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 char **argv;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 {
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
22 FILE *binf, *outf;
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 unsigned frame_index;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 uint8_t frame[BINFILE_MAX_FRAME];
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
25 int rc;
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
27 if (argc != 3) {
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
28 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
29 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 binf = fopen(argv[1], "r");
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (!binf) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 perror(argv[1]);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 }
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
36 if (strcmp(argv[2], "-")) {
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
37 outf = fopen(argv[2], "w");
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
38 if (!outf) {
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
39 perror(argv[2]);
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
40 exit(1);
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
41 }
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
42 } else
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
43 outf = stdout;
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 for (frame_index = 0; ; frame_index++) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 rc = binfile_read_frame(binf, frame);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (rc < 0) {
520
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
47 fprintf(stderr,
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
48 "error: garbage in %s after %u frames\n",
785b302992f0 miscutil: new program gsmx-to-tw5a
Mychaela Falconia <falcon@freecalypso.org>
parents: 471
diff changeset
49 argv[1], frame_index);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 exit(1);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (!rc)
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 switch (frame[0] & 0xF0) {
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 case 0xB0:
521
68fe269b4316 gsmx-to-tw5a: actually write to the output file
Mychaela Falconia <falcon@freecalypso.org>
parents: 520
diff changeset
56 fprintf(outf, "%02X\n", 0xE6 | frame[1] & 1);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 case 0xC0:
521
68fe269b4316 gsmx-to-tw5a: actually write to the output file
Mychaela Falconia <falcon@freecalypso.org>
parents: 520
diff changeset
59 emit_hex_frame(outf, frame, EFR_RTP_FRAME_LEN);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 case 0xD0:
521
68fe269b4316 gsmx-to-tw5a: actually write to the output file
Mychaela Falconia <falcon@freecalypso.org>
parents: 520
diff changeset
62 emit_hex_frame(outf, frame, GSMFR_RTP_FRAME_LEN);
23
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 break;
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 exit(0);
baadb1cb744d new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }