FreeCalypso > hg > freecalypso-tools
annotate miscutil/fc-fr2tch.c @ 383:f8c693d16978
fcup-smsendmult: UCS-2 send mode implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 09 Mar 2018 02:56:09 +0000 |
parents | 7eaa3307e5df |
children |
rev | line source |
---|---|
5
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This utility converts a GSM 06.10 speech recording from the format that is |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * commonly accepted as standard in the Unix/Linux world (libgsm format) into |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * hex strings of TCH bits to be fed to the GSM 05.03 channel encoder by way |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * of a TI Calypso GSM device, a FreeCalypso GSM firmware version with the |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * TCH rerouting feature, and fc-shell's tch play command. |
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 |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <sys/types.h> |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdio.h> |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 main(argc, argv) |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 char **argv; |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 { |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 FILE *inf, *outf; |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 u_char libgsm_bytes[33], tidsp_bytes[33]; |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 int cc, i, gotsome = 0; |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 if (argc != 3) { |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 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
|
22 exit(1); |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 } |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 inf = fopen(argv[1], "r"); |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (!inf) { |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 perror(argv[1]); |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 exit(1); |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 } |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 outf = fopen(argv[2], "w"); |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (!outf) { |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 perror(argv[2]); |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 exit(1); |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 for (;;) { |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 cc = fread(libgsm_bytes, 1, 33, inf); |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (cc < 33) |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 break; |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if ((libgsm_bytes[0] & 0xF0) != 0xD0) { |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 invalid: fprintf(stderr, "error: %s is not in libgsm format\n", |
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 } |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 gsm0610_libgsm_to_tidsp(libgsm_bytes, tidsp_bytes); |
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, |
7eaa3307e5df
fc-fr2tch utility written, added under miscutil
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 "warning: extra non-33 bytes at the end of %s\n", |
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 } |