annotate tchtools/fc-efr2tch.c @ 1004:d15d337ac0a9

loadtools/scripts: remove long-deprecated -h gta02 config
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 09 Dec 2023 18:35:30 +0000
parents 94890123a74f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
906
94890123a74f tchtools: new program fc-efr2tch
Mychaela Falconia <falcon@freecalypso.org>
parents: 902
diff changeset
2 * This utility converts a GSM EFR speech recording from Themyscira Wireless
94890123a74f tchtools: new program fc-efr2tch
Mychaela Falconia <falcon@freecalypso.org>
parents: 902
diff changeset
3 * gsmx format into hex strings of TCH UL bits, to be fed to the TCH UL play
94890123a74f tchtools: new program fc-efr2tch
Mychaela Falconia <falcon@freecalypso.org>
parents: 902
diff changeset
4 * buffer in the Calypso DSP by way of a suitable FreeCalypso firmware version
94890123a74f tchtools: new program fc-efr2tch
Mychaela Falconia <falcon@freecalypso.org>
parents: 902
diff changeset
5 * and the special tch play command in fc-shell.
5
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 */
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/types.h>
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 main(argc, argv)
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 char **argv;
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 {
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 FILE *inf, *outf;
906
94890123a74f tchtools: new program fc-efr2tch
Mychaela Falconia <falcon@freecalypso.org>
parents: 902
diff changeset
16 u_char efr_bytes[31], tidsp_bytes[33];
5
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 int cc, i, gotsome = 0;
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (argc != 3) {
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 fprintf(stderr, "usage: %s infile outfile\n", argv[0]);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 exit(1);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 }
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 inf = fopen(argv[1], "r");
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 if (!inf) {
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 perror(argv[1]);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 exit(1);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 outf = fopen(argv[2], "w");
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (!outf) {
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 perror(argv[2]);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 exit(1);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 for (;;) {
906
94890123a74f tchtools: new program fc-efr2tch
Mychaela Falconia <falcon@freecalypso.org>
parents: 902
diff changeset
34 cc = fread(efr_bytes, 1, 31, inf);
94890123a74f tchtools: new program fc-efr2tch
Mychaela Falconia <falcon@freecalypso.org>
parents: 902
diff changeset
35 if (cc < 31)
5
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 break;
906
94890123a74f tchtools: new program fc-efr2tch
Mychaela Falconia <falcon@freecalypso.org>
parents: 902
diff changeset
37 if ((efr_bytes[0] & 0xF0) != 0xC0) {
94890123a74f tchtools: new program fc-efr2tch
Mychaela Falconia <falcon@freecalypso.org>
parents: 902
diff changeset
38 invalid: fprintf(stderr,
94890123a74f tchtools: new program fc-efr2tch
Mychaela Falconia <falcon@freecalypso.org>
parents: 902
diff changeset
39 "error: %s is not in EFR codec format\n",
5
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 argv[1]);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 exit(1);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
906
94890123a74f tchtools: new program fc-efr2tch
Mychaela Falconia <falcon@freecalypso.org>
parents: 902
diff changeset
43 efr_std_to_tidsp(efr_bytes, tidsp_bytes);
5
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 for (i = 0; i < 33; i++)
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 fprintf(outf, "%02X", tidsp_bytes[i]);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 putc('\n', outf);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 gotsome = 1;
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fclose(outf);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (cc) {
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (gotsome)
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 fprintf(stderr,
906
94890123a74f tchtools: new program fc-efr2tch
Mychaela Falconia <falcon@freecalypso.org>
parents: 902
diff changeset
53 "warning: extra non-31 bytes at the end of %s\n",
5
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 argv[1]);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 else
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 goto invalid;
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 exit(0);
7eaa3307e5df fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }