FreeCalypso > hg > freecalypso-tools
comparison ffstools/tiaud/decomp.c @ 163:568e2a2b49c8
tiaud-decomp utility written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 18 Mar 2017 05:47:32 +0000 |
parents | |
children | c458e33060bf |
comparison
equal
deleted
inserted
replaced
162:ce7479d28b02 | 163:568e2a2b49c8 |
---|---|
1 /* | |
2 * This utility decompiles a binary /aud/*.cfg file read out of FFS | |
3 * into our ASCII text representation. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <sys/file.h> | |
8 #include <sys/stat.h> | |
9 #include <stdio.h> | |
10 #include <stdint.h> | |
11 #include <endian.h> | |
12 #include <stdlib.h> | |
13 #include <unistd.h> | |
14 #include "binstruct.h" | |
15 | |
16 struct audio_cfg_bin bin; | |
17 FILE *outf; | |
18 | |
19 read_bin_file(filename) | |
20 char *filename; | |
21 { | |
22 int fd; | |
23 struct stat st; | |
24 | |
25 fd = open(filename, O_RDONLY); | |
26 if (fd < 0) { | |
27 perror(filename); | |
28 exit(1); | |
29 } | |
30 fstat(fd, &st); | |
31 if (!S_ISREG(st.st_mode)) { | |
32 fprintf(stderr, "%s is not a regular file\n", filename); | |
33 exit(1); | |
34 } | |
35 if (st.st_size != sizeof(struct audio_cfg_bin)) { | |
36 fprintf(stderr, "%s has the wrong length\n", filename); | |
37 exit(1); | |
38 } | |
39 read(fd, &bin, sizeof bin); | |
40 close(fd); | |
41 } | |
42 | |
43 emit_fir(table) | |
44 uint16_t *table; | |
45 { | |
46 int i; | |
47 | |
48 for (i = 0; i < 31; i++) { | |
49 if ((i % 8) == 0) | |
50 fprintf(outf, "\tfir %2d", i); | |
51 fprintf(outf, " 0x%04X", le16toh(table[i])); | |
52 if (i == 7 || i == 15 || i == 23 || i == 30) | |
53 putc('\n', outf); | |
54 } | |
55 } | |
56 | |
57 emit_ascii() | |
58 { | |
59 int i; | |
60 | |
61 fprintf(outf, "voice-path %u\n", bin.voice_path); | |
62 | |
63 switch (bin.mic_mode) { | |
64 case AUDIO_MICROPHONE_HANDHELD: | |
65 fprintf(outf, "mic default {\n"); | |
66 break; | |
67 case AUDIO_MICROPHONE_HANDFREE: | |
68 fprintf(outf, "mic aux {\n"); | |
69 break; | |
70 case AUDIO_MICROPHONE_HEADSET: | |
71 fprintf(outf, "mic headset {\n"); | |
72 break; | |
73 default: | |
74 fprintf(stderr, "error: unknown microphone mode 0x%02X\n", | |
75 bin.mic_mode); | |
76 exit(1); | |
77 } | |
78 fprintf(outf, "\tgain %d\n", bin.mic_bytes[0]); | |
79 if (bin.mic_mode == AUDIO_MICROPHONE_HANDFREE) { | |
80 fprintf(outf, "\textra-gain %d\n", bin.mic_bytes[1]); | |
81 fprintf(outf, "\toutput-bias %d\n", bin.mic_bytes[2]); | |
82 } else | |
83 fprintf(outf, "\toutput-bias %d\n", bin.mic_bytes[1]); | |
84 emit_fir(bin.mic_fir); | |
85 fputs("}\n", outf); | |
86 | |
87 switch (bin.speaker_mode) { | |
88 case AUDIO_SPEAKER_HANDHELD: | |
89 fprintf(outf, "speaker ear {\n"); | |
90 break; | |
91 case AUDIO_SPEAKER_HANDFREE: | |
92 fprintf(outf, "speaker aux {\n"); | |
93 break; | |
94 case AUDIO_SPEAKER_HEADSET: | |
95 fprintf(outf, "speaker headset {\n"); | |
96 break; | |
97 case AUDIO_SPEAKER_BUZZER: | |
98 fprintf(outf, "speaker buzzer {\n"); | |
99 break; | |
100 case AUDIO_SPEAKER_HANDHELD_HANDFREE: | |
101 fprintf(outf, "speaker ear+aux {\n"); | |
102 break; | |
103 default: | |
104 fprintf(stderr, "error: unknown speaker mode 0x%02X\n", | |
105 bin.speaker_mode); | |
106 exit(1); | |
107 } | |
108 if (bin.speaker_mode != AUDIO_SPEAKER_BUZZER) { | |
109 fprintf(outf, "\tgain %d\n", bin.speaker_bytes[0]); | |
110 fprintf(outf, "\taudio-filter %d\n", bin.speaker_bytes[1]); | |
111 emit_fir(bin.speaker_fir); | |
112 } else | |
113 fprintf(outf, "\tactivate %d\n", bin.speaker_bytes[0]); | |
114 fputs("}\n", outf); | |
115 | |
116 fprintf(outf, "sidetone %d\n", bin.sidetone_gain); | |
117 fputs("aec", outf); | |
118 for (i = 0; i < 5; i++) { | |
119 putc(' ', outf); | |
120 if (bin.aec_words[i]) | |
121 fprintf(outf, "0x%X", le16toh(bin.aec_words[i])); | |
122 else | |
123 putc('0', outf); | |
124 } | |
125 putc('\n', outf); | |
126 } | |
127 | |
128 main(argc, argv) | |
129 char **argv; | |
130 { | |
131 if (argc < 2 || argc > 3) { | |
132 fprintf(stderr, "usage: %s infile [outfile]\n", argv[0]); | |
133 exit(1); | |
134 } | |
135 read_bin_file(argv[1]); | |
136 if (argc > 2) { | |
137 outf = fopen(argv[2], "w"); | |
138 if (!outf) { | |
139 perror(argv[2]); | |
140 exit(1); | |
141 } | |
142 } else | |
143 outf = stdout; | |
144 emit_ascii(); | |
145 exit(0); | |
146 } |