comparison miscutil/fc-vm2hex.c @ 170:a72bbc3ace09

fc-vm2hex utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 22 Mar 2017 08:55:53 +0000
parents
children
comparison
equal deleted inserted replaced
169:0b4167c0ed52 170:a72bbc3ace09
1 /*
2 * This utility converts the old-fashioned (non-AMR) voice memo files
3 * read out of FFS into hex strings that can be analyzed by a human
4 * or further fed to fc-tch2fr.
5 */
6
7 #include <sys/types.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 char *infname;
12 FILE *inf, *outf;
13
14 static unsigned
15 get_word()
16 {
17 u_char b[2];
18 int i, c;
19
20 for (i = 0; i < 2; i++) {
21 c = getc(inf);
22 if (c < 0) {
23 fprintf(stderr, "error: premature EOF in %s\n",
24 infname);
25 exit(1);
26 }
27 b[i] = c;
28 }
29 return((b[1] << 8) | b[0]);
30 }
31
32 convert_speech_sample()
33 {
34 u_char bytes[34];
35 int i, dp;
36 unsigned word;
37
38 dp = 0;
39 for (i = 0; i < 17; i++) {
40 word = get_word();
41 bytes[dp++] = word >> 8;
42 bytes[dp++] = word;
43 }
44 for (i = 0; i < 33; i++)
45 fprintf(outf, "%02X", bytes[i]);
46 }
47
48 main(argc, argv)
49 char **argv;
50 {
51 unsigned first_word;
52
53 if (argc < 2 || argc > 3) {
54 fprintf(stderr, "usage: %s infile [outfile]\n", argv[0]);
55 exit(1);
56 }
57 infname = argv[1];
58 inf = fopen(infname, "r");
59 if (!inf) {
60 perror(infname);
61 exit(1);
62 }
63 if (argc > 2) {
64 outf = fopen(argv[2], "w");
65 if (!outf) {
66 perror(argv[2]);
67 exit(1);
68 }
69 } else
70 outf = stdout;
71
72 for (;;) {
73 first_word = get_word();
74 if (first_word == 0xFBFF) /* SC_VM_END_MASK */
75 break;
76 fprintf(outf, "%04X", first_word);
77 if (first_word & 0x8000) { /* B_VM_SPEECH */
78 fprintf(outf, " %04X", get_word());
79 fprintf(outf, " %04X", get_word());
80 putc(' ', outf);
81 convert_speech_sample();
82 }
83 putc('\n', outf);
84 }
85 exit(0);
86 }