comparison miscutil/fc-gsm2vm.c @ 171:f736f3ce8310

fc-gsm2vm utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 22 Mar 2017 18:21:03 +0000
parents
children
comparison
equal deleted inserted replaced
170:a72bbc3ace09 171:f736f3ce8310
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 * a voice memo file that can be uploaded into the FFS of a FreeCalypso device
5 * and played with the audio_vm_play_start() API or the AT@VMP command that
6 * invokes the latter.
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[34], arm_bytes[34];
18 static u_char header_bytes[6] = {0x00, 0xC4, 0x00, 0x00, 0x00, 0x00};
19 static u_char endmarker[2] = {0xFF, 0xFB};
20 int cc, i, gotsome = 0;
21
22 if (argc != 3) {
23 fprintf(stderr, "usage: %s infile outfile\n", argv[0]);
24 exit(1);
25 }
26 inf = fopen(argv[1], "r");
27 if (!inf) {
28 perror(argv[1]);
29 exit(1);
30 }
31 outf = fopen(argv[2], "w");
32 if (!outf) {
33 perror(argv[2]);
34 exit(1);
35 }
36 tidsp_bytes[33] = 0;
37 for (;;) {
38 cc = fread(libgsm_bytes, 1, 33, inf);
39 if (cc < 33)
40 break;
41 if ((libgsm_bytes[0] & 0xF0) != 0xD0) {
42 invalid: fprintf(stderr, "error: %s is not in libgsm format\n",
43 argv[1]);
44 exit(1);
45 }
46 gsm0610_libgsm_to_tidsp(libgsm_bytes, tidsp_bytes);
47 for (i = 0; i < 34; i += 2) {
48 arm_bytes[i] = tidsp_bytes[i+1];
49 arm_bytes[i+1] = tidsp_bytes[i];
50 }
51 fwrite(header_bytes, 1, 6, outf);
52 fwrite(arm_bytes, 1, 34, outf);
53 gotsome = 1;
54 }
55 fwrite(endmarker, 1, 2, outf);
56 fclose(outf);
57 if (cc) {
58 if (gotsome)
59 fprintf(stderr,
60 "warning: extra non-33 bytes at the end of %s\n",
61 argv[1]);
62 else
63 goto invalid;
64 }
65 exit(0);
66 }