comparison tchtools/fc-efr2tch.c @ 906:94890123a74f

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