FreeCalypso > hg > freecalypso-tools
comparison tchtools/fc-fr2tch.c @ 902:8ddb16a37273
tree org: move TCH and VM utils from miscutil to tchtools
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 28 Dec 2022 07:52:30 +0000 |
parents | miscutil/fc-fr2tch.c@7eaa3307e5df |
children |
comparison
equal
deleted
inserted
replaced
901:2e6764022292 | 902:8ddb16a37273 |
---|---|
1 /* | |
2 * This utility converts a GSM 06.10 speech recording from the format that is | |
3 * commonly accepted as standard in the Unix/Linux world (libgsm format) into | |
4 * hex strings of TCH bits to be fed to the GSM 05.03 channel encoder by way | |
5 * of a TI Calypso GSM device, a FreeCalypso GSM firmware version with the | |
6 * TCH rerouting feature, and fc-shell's tch play command. | |
7 */ | |
8 | |
9 #include <sys/types.h> | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 | |
13 main(argc, argv) | |
14 char **argv; | |
15 { | |
16 FILE *inf, *outf; | |
17 u_char libgsm_bytes[33], tidsp_bytes[33]; | |
18 int cc, i, gotsome = 0; | |
19 | |
20 if (argc != 3) { | |
21 fprintf(stderr, "usage: %s infile outfile\n", argv[0]); | |
22 exit(1); | |
23 } | |
24 inf = fopen(argv[1], "r"); | |
25 if (!inf) { | |
26 perror(argv[1]); | |
27 exit(1); | |
28 } | |
29 outf = fopen(argv[2], "w"); | |
30 if (!outf) { | |
31 perror(argv[2]); | |
32 exit(1); | |
33 } | |
34 for (;;) { | |
35 cc = fread(libgsm_bytes, 1, 33, inf); | |
36 if (cc < 33) | |
37 break; | |
38 if ((libgsm_bytes[0] & 0xF0) != 0xD0) { | |
39 invalid: fprintf(stderr, "error: %s is not in libgsm format\n", | |
40 argv[1]); | |
41 exit(1); | |
42 } | |
43 gsm0610_libgsm_to_tidsp(libgsm_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-33 bytes at the end of %s\n", | |
54 argv[1]); | |
55 else | |
56 goto invalid; | |
57 } | |
58 exit(0); | |
59 } |