annotate miscutil/fc-vm2hex.c @ 873:2b5f4736079c

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