FreeCalypso > hg > freecalypso-tools
annotate tchtools/fc-vm2hex.c @ 929:ab771ce34fac
rvinterf/lowlevel/format.c: get rid of static fmtbuf
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 23 May 2023 05:56:08 +0000 |
parents | 5041bcb8140f |
children |
rev | line source |
---|---|
170
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
904
5041bcb8140f
tchtools/fc-vm2hex.c: update header comment for new situation
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
2 * This utility converts old-fashioned (non-AMR) TCS211 voice memo files |
5041bcb8140f
tchtools/fc-vm2hex.c: update header comment for new situation
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
3 * read out of FFS into hex strings that can be analyzed by a human, |
5041bcb8140f
tchtools/fc-vm2hex.c: update header comment for new situation
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
4 * either directly or with the aid of gsmfr-dlcap-parse utility from |
5041bcb8140f
tchtools/fc-vm2hex.c: update header comment for new situation
Mychaela Falconia <falcon@freecalypso.org>
parents:
902
diff
changeset
|
5 * Themyscira Wireless GSM codec libraries & utilities package. |
170
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 |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/types.h> |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 char *infname; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 FILE *inf, *outf; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 static unsigned |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 get_word() |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 { |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 u_char b[2]; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int i, c; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 for (i = 0; i < 2; i++) { |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 c = getc(inf); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (c < 0) { |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 fprintf(stderr, "error: premature EOF in %s\n", |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 infname); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 exit(1); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 } |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 b[i] = c; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return((b[1] << 8) | b[0]); |
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 |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 convert_speech_sample() |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 { |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 u_char bytes[34]; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 int i, dp; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 unsigned word; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 dp = 0; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 for (i = 0; i < 17; i++) { |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 word = get_word(); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 bytes[dp++] = word >> 8; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 bytes[dp++] = word; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 } |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 for (i = 0; i < 33; i++) |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 fprintf(outf, "%02X", bytes[i]); |
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 |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 main(argc, argv) |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 char **argv; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 { |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 unsigned first_word; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 if (argc < 2 || argc > 3) { |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 fprintf(stderr, "usage: %s infile [outfile]\n", argv[0]); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 exit(1); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 infname = argv[1]; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 inf = fopen(infname, "r"); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (!inf) { |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 perror(infname); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 exit(1); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (argc > 2) { |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 outf = fopen(argv[2], "w"); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (!outf) { |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 perror(argv[2]); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 exit(1); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } else |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 outf = stdout; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 for (;;) { |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 first_word = get_word(); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 if (first_word == 0xFBFF) /* SC_VM_END_MASK */ |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 break; |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 fprintf(outf, "%04X", first_word); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 if (first_word & 0x8000) { /* B_VM_SPEECH */ |
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 fprintf(outf, " %04X", get_word()); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 putc(' ', outf); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 convert_speech_sample(); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 putc('\n', outf); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 } |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 exit(0); |
a72bbc3ace09
fc-vm2hex utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |