annotate ffstools/tiaud/decomp.c @ 289:329c31f7c797

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