summaryrefslogtreecommitdiff
path: root/tools/voicefont.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/voicefont.c')
-rw-r--r--tools/voicefont.c107
1 files changed, 59 insertions, 48 deletions
diff --git a/tools/voicefont.c b/tools/voicefont.c
index 10f08f385c..3dd5169cc7 100644
--- a/tools/voicefont.c
+++ b/tools/voicefont.c
@@ -22,6 +22,8 @@
22 * 22 *
23 ****************************************************************************/ 23 ****************************************************************************/
24 24
25#include "voicefont.h"
26
25#include <stdio.h> 27#include <stdio.h>
26#include <string.h> 28#include <string.h>
27 29
@@ -64,11 +66,9 @@ int BitswapAudio (unsigned char* pDest, unsigned char* pSrc, size_t len)
64 return 0; 66 return 0;
65} 67}
66 68
67 69int voicefont(FILE* voicefontids,int targetnum,char* filedir, FILE* output)
68int main (int argc, char** argv)
69{ 70{
70 FILE* pFile; 71
71
72 int i,j; 72 int i,j;
73 73
74 /* two tables, one for normal strings, one for voice-only (>0x8000) */ 74 /* two tables, one for normal strings, one for voice-only (>0x8000) */
@@ -90,35 +90,18 @@ int main (int argc, char** argv)
90 int target_id; 90 int target_id;
91 int do_bitswap_audio = 0; 91 int do_bitswap_audio = 0;
92 92
93
94 if (argc < 2)
95 {
96 printf("Makes a Rockbox voicefont from a collection of mp3 clips.\n");
97 printf("Usage: voicefont <string id list file> <target id> <mp3 path> <output file>\n");
98 printf("\n");
99 printf("Example: \n");
100 printf("voicefont voicefontids.txt 2 voice\\ voicefont.bin\n");
101 return -1;
102 }
103 93
104 pFile = fopen(argv[1], "r");
105 if (pFile == NULL)
106 {
107 printf("Error opening language file %s\n", argv[1]);
108 return -2;
109 }
110
111 /* We bitswap the voice file only SH based archos players, target IDs 94 /* We bitswap the voice file only SH based archos players, target IDs
112 equal to or lower than 8. See the target_id line for each target in 95 equal to or lower than 8. See the target_id line for each target in
113 configure */ 96 configure */
114 target_id = atoi(argv[2]); 97 target_id = targetnum;
115 if (target_id <= 8) 98 if (target_id <= 8)
116 do_bitswap_audio = 1; 99 do_bitswap_audio = 1;
117 100
118 memset(voiceonly, 0, sizeof(voiceonly)); 101 memset(voiceonly, 0, sizeof(voiceonly));
119 while (!feof(pFile)) 102 while (!feof(voicefontids))
120 { 103 {
121 fgets(line, sizeof(line), pFile); 104 fgets(line, sizeof(line), voicefontids);
122 if (line[0] == '#') /* comment */ 105 if (line[0] == '#') /* comment */
123 continue; 106 continue;
124 107
@@ -132,24 +115,18 @@ int main (int argc, char** argv)
132 continue; 115 continue;
133 } 116 }
134 } 117 }
135 fclose(pFile); 118 fclose(voicefontids);
136 119
137 pFile = fopen(argv[4], "wb"); 120 fseek(output, HEADER_SIZE + count*8, SEEK_SET); /* space for header */
138 if (pFile == NULL)
139 {
140 printf("Error opening output file %s\n", argv[4]);
141 return -2;
142 }
143 fseek(pFile, HEADER_SIZE + count*8, SEEK_SET); /* space for header */
144 121
145 for (i=0; i<count; i++) 122 for (i=0; i<count; i++)
146 { 123 {
147 if (voiceonly[i] == 1) 124 if (voiceonly[i] == 1)
148 count_voiceonly++; 125 count_voiceonly++;
149 126
150 pos[i] = ftell(pFile); 127 pos[i] = ftell(output);
151 sprintf(mp3filename1, "%s%s.mp3", argv[3], names[i]); 128 sprintf(mp3filename1, "%s%s.mp3", filedir, names[i]);
152 sprintf(mp3filename2, "%s%s.wav.mp3", argv[3], names[i]); 129 sprintf(mp3filename2, "%s%s.wav.mp3", filedir, names[i]);
153 mp3filename = mp3filename1; 130 mp3filename = mp3filename1;
154 pMp3File = fopen(mp3filename, "rb"); 131 pMp3File = fopen(mp3filename, "rb");
155 if (pMp3File == NULL) 132 if (pMp3File == NULL)
@@ -169,36 +146,36 @@ int main (int argc, char** argv)
169 fclose(pMp3File); 146 fclose(pMp3File);
170 if (do_bitswap_audio) 147 if (do_bitswap_audio)
171 BitswapAudio(buffer, buffer, size[i]); 148 BitswapAudio(buffer, buffer, size[i]);
172 fwrite(buffer, 1, size[i], pFile); 149 fwrite(buffer, 1, size[i], output);
173 150
174 printf("%d %s %d\n", i, names[i], size[i]); /* debug */ 151 printf("%d %s %d\n", i, names[i], size[i]); /* debug */
175 } /* for i */ 152 } /* for i */
176 153
177 154
178 fseek(pFile, 0, SEEK_SET); 155 fseek(output, 0, SEEK_SET);
179 156
180 /* Create the file format: */ 157 /* Create the file format: */
181 158
182 /* 1st 32 bit value in the file is the version number */ 159 /* 1st 32 bit value in the file is the version number */
183 value = SWAP4(400); /* 4.00 */ 160 value = SWAP4(400); /* 4.00 */
184 fwrite(&value, sizeof(value), 1, pFile); 161 fwrite(&value, sizeof(value), 1, output);
185 162
186 /* 2nd 32 bit value in the file is the id number for the target 163 /* 2nd 32 bit value in the file is the id number for the target
187 we made the voce file for */ 164 we made the voce file for */
188 value = SWAP4(atoi(argv[2])); 165 value = SWAP4(targetnum);
189 fwrite(&value, sizeof(value), 1, pFile); 166 fwrite(&value, sizeof(value), 1, output);
190 167
191 /* 3rd 32 bit value in the file is the header size (= 1st table position) */ 168 /* 3rd 32 bit value in the file is the header size (= 1st table position) */
192 value = SWAP4(HEADER_SIZE); /* version, target id, header size, number1, number2 */ 169 value = SWAP4(HEADER_SIZE); /* version, target id, header size, number1, number2 */
193 fwrite(&value, sizeof(value), 1, pFile); 170 fwrite(&value, sizeof(value), 1, output);
194 171
195 /* 4th 32 bit value in the file is the number of clips in 1st table */ 172 /* 4th 32 bit value in the file is the number of clips in 1st table */
196 value = SWAP4(count-count_voiceonly); 173 value = SWAP4(count-count_voiceonly);
197 fwrite(&value, sizeof(value), 1, pFile); 174 fwrite(&value, sizeof(value), 1, output);
198 175
199 /* 5th bit value in the file is the number of clips in 2nd table */ 176 /* 5th bit value in the file is the number of clips in 2nd table */
200 value = SWAP4(count_voiceonly); 177 value = SWAP4(count_voiceonly);
201 fwrite(&value, sizeof(value), 1, pFile); 178 fwrite(&value, sizeof(value), 1, output);
202 179
203 /* then followed by offset/size pairs for each clip */ 180 /* then followed by offset/size pairs for each clip */
204 for (j=0; j<2; j++) /* now 2 tables */ 181 for (j=0; j<2; j++) /* now 2 tables */
@@ -217,9 +194,9 @@ int main (int argc, char** argv)
217 } 194 }
218 195
219 value = SWAP4(pos[i]); /* position */ 196 value = SWAP4(pos[i]); /* position */
220 fwrite(&value, sizeof(value), 1, pFile); 197 fwrite(&value, sizeof(value), 1,output);
221 value = SWAP4(size[i]); /* size */ 198 value = SWAP4(size[i]); /* size */
222 fwrite(&value, sizeof(value), 1, pFile); 199 fwrite(&value, sizeof(value), 1, output);
223 } /* for i */ 200 } /* for i */
224 } /* for j */ 201 } /* for j */
225 202
@@ -229,7 +206,41 @@ int main (int argc, char** argv)
229 * which we already have written, see above. 206 * which we already have written, see above.
230 */ 207 */
231 208
232 fclose(pFile); 209 fclose(output);
210
211 return 0;
212
213
214}
215#ifndef RBUTIL
216int main (int argc, char** argv)
217{
233 218
219 if (argc < 2)
220 {
221 printf("Makes a Rockbox voicefont from a collection of mp3 clips.\n");
222 printf("Usage: voicefont <string id list file> <target id> <mp3 path> <output file>\n");
223 printf("\n");
224 printf("Example: \n");
225 printf("voicefont voicefontids.txt 2 voice\\ voicefont.bin\n");
226 return -1;
227 }
228
229 FILE* ids = fopen(argv[1], "r");
230 if (ids == NULL)
231 {
232 printf("Error opening language file %s\n", argv[1]);
233 return -2;
234 }
235
236 FILE* output = fopen(argv[4], "wb");
237 if (output == NULL)
238 {
239 printf("Error opening output file %s\n", argv[4]);
240 return -2;
241 }
242
243 voicefont(ids, atoi(argv[2]),argv[3],output);
234 return 0; 244 return 0;
235} 245}
246#endif