summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Wenger <domonoky@googlemail.com>2008-01-11 23:46:10 +0000
committerDominik Wenger <domonoky@googlemail.com>2008-01-11 23:46:10 +0000
commit5be332938d51b75dee8856ad87e2edbe9b8ce3b2 (patch)
treeff253f1f7e17bc5faf8fc31b0662962fba7ab649
parentfc13290a823b2fe9b5c466a16af7a7db91f58eee (diff)
downloadrockbox-5be332938d51b75dee8856ad87e2edbe9b8ce3b2.tar.gz
rockbox-5be332938d51b75dee8856ad87e2edbe9b8ce3b2.zip
refactored voicefont and wavtrim for inclusion into rbutil.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16058 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--tools/voicefont.c107
-rw-r--r--tools/voicefont.h33
-rw-r--r--tools/wavtrim.c69
-rw-r--r--tools/wavtrim.h27
4 files changed, 163 insertions, 73 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
diff --git a/tools/voicefont.h b/tools/voicefont.h
new file mode 100644
index 0000000000..63374e36d3
--- /dev/null
+++ b/tools/voicefont.h
@@ -0,0 +1,33 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: voicefont.h 15675 2007-11-18 22:01:31Z amiconn $
9 *
10 * Copyright (C) 2004 by Jörg Hohensohn
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 * A tool to generate the Rockbox "voicefont", a collection of all the UI
19 * strings.
20 *
21 * Details at http://www.rockbox.org/twiki/bin/view/Main/VoiceBuilding
22 *
23 ****************************************************************************/
24
25#ifndef VOICEFONT_H
26#define VOICEFONT_H
27
28#include <stdio.h>
29#include <stdlib.h>
30
31int voicefont(FILE* voicefontids,int targetnum,char* filedir, FILE* output);
32
33#endif
diff --git a/tools/wavtrim.c b/tools/wavtrim.c
index 3d77b4e972..fe212ef93c 100644
--- a/tools/wavtrim.c
+++ b/tools/wavtrim.c
@@ -23,6 +23,8 @@
23#include <stdio.h> /* for file I/O */ 23#include <stdio.h> /* for file I/O */
24#include <stdlib.h> /* for malloc */ 24#include <stdlib.h> /* for malloc */
25 25
26#include "wavtrim.h"
27
26/* place a 32 bit value into memory, little endian */ 28/* place a 32 bit value into memory, little endian */
27void Write32(unsigned char* pByte, unsigned long value) 29void Write32(unsigned char* pByte, unsigned long value)
28{ 30{
@@ -66,9 +68,8 @@ unsigned long Read16(unsigned char* pByte)
66 return value; 68 return value;
67} 69}
68 70
69 71int wavtrim(char * filename, int maxsilence ,char* errstring,int errsize)
70int main (int argc, char** argv) 72{
71{
72 FILE* pFile; 73 FILE* pFile;
73 long lFileSize, lGot; 74 long lFileSize, lGot;
74 unsigned char* pBuf; 75 unsigned char* pBuf;
@@ -79,29 +80,17 @@ int main (int argc, char** argv)
79 unsigned char *databuf; /* Pointer to the data chunk payload */ 80 unsigned char *databuf; /* Pointer to the data chunk payload */
80 int skip_head, skip_tail, pad_head, pad_tail; 81 int skip_head, skip_tail, pad_head, pad_tail;
81 int i; 82 int i;
82 int max_silence = 0; 83 int max_silence = maxsilence;
83 signed char sample8; 84 signed char sample8;
84 short sample16; 85 short sample16;
85 86
86 if (argc < 2) 87 pFile = fopen(filename, "rb");
87 {
88 printf("wavtrim removes silence at the begin and end of a WAV file.\n");
89 printf("usage: wavtrim <filename.wav> [<max_silence>]\n");
90 return 0;
91 }
92
93 if (argc == 3)
94 {
95 max_silence = atoi(argv[2]);
96 }
97
98 pFile = fopen(argv[1], "rb");
99 if (pFile == NULL) 88 if (pFile == NULL)
100 { 89 {
101 printf("Error opening file %s for reading\n", argv[1]); 90 snprintf(errstring,errsize,"Error opening file %s for reading\n", filename);
102 return -1; 91 return -1;
103 } 92 }
104 93
105 fseek(pFile, 0, SEEK_END); 94 fseek(pFile, 0, SEEK_END);
106 lFileSize = ftell(pFile); 95 lFileSize = ftell(pFile);
107 fseek(pFile, 0, SEEK_SET); 96 fseek(pFile, 0, SEEK_SET);
@@ -109,7 +98,7 @@ int main (int argc, char** argv)
109 pBuf = malloc(lFileSize); 98 pBuf = malloc(lFileSize);
110 if (pBuf == NULL) 99 if (pBuf == NULL)
111 { 100 {
112 printf("Out of memory to allocate %ld bytes for file.\n", lFileSize); 101 snprintf(errstring,errsize,"Out of memory to allocate %ld bytes for file.\n", lFileSize);
113 fclose(pFile); 102 fclose(pFile);
114 return -1; 103 return -1;
115 } 104 }
@@ -118,11 +107,12 @@ int main (int argc, char** argv)
118 fclose(pFile); 107 fclose(pFile);
119 if (lGot != lFileSize) 108 if (lGot != lFileSize)
120 { 109 {
121 printf("File read error, got only %ld bytes out of %ld.\n", lGot, lFileSize); 110 snprintf(errstring,errsize,"File read error, got only %ld bytes out of %ld.\n", lGot, lFileSize);
122 free(pBuf); 111 free(pBuf);
123 return -1; 112 return -1;
124 } 113 }
125 114
115
126 bps = Read16(pBuf + 32); 116 bps = Read16(pBuf + 32);
127 datapos = 28 + Read16(pBuf + 16); 117 datapos = 28 + Read16(pBuf + 16);
128 databuf = &pBuf[datapos]; 118 databuf = &pBuf[datapos];
@@ -132,7 +122,7 @@ int main (int argc, char** argv)
132 || Read32(pBuf+12) != 0x20746d66 /* "fmt " */ 122 || Read32(pBuf+12) != 0x20746d66 /* "fmt " */
133 || Read32(pBuf+datapos-8) != 0x61746164) /* "data" */ 123 || Read32(pBuf+datapos-8) != 0x61746164) /* "data" */
134 { 124 {
135 printf("No valid input WAV file?\n", lGot, lFileSize); 125 snprintf(errstring,errsize,"No valid input WAV file?\n");
136 free(pBuf); 126 free(pBuf);
137 return -1; 127 return -1;
138 } 128 }
@@ -198,10 +188,10 @@ int main (int argc, char** argv)
198 Write32(pBuf+4, Read32(pBuf+4) - skip_head - skip_tail); 188 Write32(pBuf+4, Read32(pBuf+4) - skip_head - skip_tail);
199 Write32(pBuf+datapos-4, datalen - skip_head - skip_tail); 189 Write32(pBuf+datapos-4, datalen - skip_head - skip_tail);
200 190
201 pFile = fopen(argv[1], "wb"); 191 pFile = fopen(filename, "wb");
202 if (pFile == NULL) 192 if (pFile == NULL)
203 { 193 {
204 printf("Error opening file %s for writing\n", argv[1]); 194 snprintf(errstring,errsize,"Error opening file %s for writing\n",filename);
205 return -1; 195 return -1;
206 } 196 }
207 197
@@ -212,8 +202,37 @@ int main (int argc, char** argv)
212 202
213 free(pBuf); 203 free(pBuf);
214 return 0; 204 return 0;
205
215} 206}
216 207
208#ifndef RBUTIL
209int main (int argc, char** argv)
210{
211 int max_silence = 0;
212 char errbuffer[255];
213 int ret=0;
214
215 if (argc < 2)
216 {
217 printf("wavtrim removes silence at the begin and end of a WAV file.\n");
218 printf("usage: wavtrim <filename.wav> [<max_silence>]\n");
219 return 0;
220 }
221
222 if (argc == 3)
223 {
224 max_silence = atoi(argv[2]);
225 }
226
227
228 ret = wavtrim(argv[1],max_silence,errbuffer,255 );
229 if( ret< 0)
230 {
231 printf(errbuffer);
232 }
233 return ret;
234}
235#endif
217/* 236/*
218RIFF Chunk (12 bytes in length total) 237RIFF Chunk (12 bytes in length total)
2190 - 3 "RIFF" (ASCII Characters) 2380 - 3 "RIFF" (ASCII Characters)
diff --git a/tools/wavtrim.h b/tools/wavtrim.h
new file mode 100644
index 0000000000..86dc28fdaa
--- /dev/null
+++ b/tools/wavtrim.h
@@ -0,0 +1,27 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: wavtrim.h 14229 2007-08-07 10:21:03Z linus $
9 *
10 * Copyright (C) 2004 by Jörg Hohensohn
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 * Details at http://www.rockbox.org/twiki/bin/view/Main/VoiceBuilding
19 *
20 ****************************************************************************/
21
22#ifndef WAVTRIM_H
23#define WAVTRIM_H
24
25int wavtrim(char * filename, int maxsilence ,char* errstring,int errsize);
26
27#endif