FreeCalypso > hg > freecalypso-tools
annotate miscutil/fc-gsm2vm.c @ 791:a31ae776de6e
fc-simint: tell the user when we are requesting spenh
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 19 Mar 2021 04:42:41 +0000 |
parents | f736f3ce8310 |
children |
rev | line source |
---|---|
171
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This utility converts a GSM 06.10 speech recording from the format that is |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * commonly accepted as standard in the Unix/Linux world (libgsm format) into |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * a voice memo file that can be uploaded into the FFS of a FreeCalypso device |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * and played with the audio_vm_play_start() API or the AT@VMP command that |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * invokes the latter. |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 */ |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <sys/types.h> |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdio.h> |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 main(argc, argv) |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 char **argv; |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 { |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 FILE *inf, *outf; |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 u_char libgsm_bytes[33], tidsp_bytes[34], arm_bytes[34]; |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 static u_char header_bytes[6] = {0x00, 0xC4, 0x00, 0x00, 0x00, 0x00}; |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 static u_char endmarker[2] = {0xFF, 0xFB}; |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 int cc, i, gotsome = 0; |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (argc != 3) { |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 fprintf(stderr, "usage: %s infile outfile\n", argv[0]); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 exit(1); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 inf = fopen(argv[1], "r"); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (!inf) { |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 perror(argv[1]); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 exit(1); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 outf = fopen(argv[2], "w"); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (!outf) { |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 perror(argv[2]); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 exit(1); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 tidsp_bytes[33] = 0; |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 for (;;) { |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 cc = fread(libgsm_bytes, 1, 33, inf); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 if (cc < 33) |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 break; |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if ((libgsm_bytes[0] & 0xF0) != 0xD0) { |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 invalid: fprintf(stderr, "error: %s is not in libgsm format\n", |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 argv[1]); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 exit(1); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 gsm0610_libgsm_to_tidsp(libgsm_bytes, tidsp_bytes); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 for (i = 0; i < 34; i += 2) { |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 arm_bytes[i] = tidsp_bytes[i+1]; |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 arm_bytes[i+1] = tidsp_bytes[i]; |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 fwrite(header_bytes, 1, 6, outf); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 fwrite(arm_bytes, 1, 34, outf); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 gotsome = 1; |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 } |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 fwrite(endmarker, 1, 2, outf); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 fclose(outf); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (cc) { |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 if (gotsome) |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 fprintf(stderr, |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 "warning: extra non-33 bytes at the end of %s\n", |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 argv[1]); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 else |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 goto invalid; |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 exit(0); |
f736f3ce8310
fc-gsm2vm utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |