refactored voicefont and wavtrim for inclusion into rbutil.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16058 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
fc13290a82
commit
5be332938d
4 changed files with 163 additions and 73 deletions
|
@ -22,6 +22,8 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "voicefont.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -64,11 +66,9 @@ int BitswapAudio (unsigned char* pDest, unsigned char* pSrc, size_t len)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char** argv)
|
||||
int voicefont(FILE* voicefontids,int targetnum,char* filedir, FILE* output)
|
||||
{
|
||||
FILE* pFile;
|
||||
|
||||
|
||||
int i,j;
|
||||
|
||||
/* two tables, one for normal strings, one for voice-only (>0x8000) */
|
||||
|
@ -90,35 +90,18 @@ int main (int argc, char** argv)
|
|||
int target_id;
|
||||
int do_bitswap_audio = 0;
|
||||
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("Makes a Rockbox voicefont from a collection of mp3 clips.\n");
|
||||
printf("Usage: voicefont <string id list file> <target id> <mp3 path> <output file>\n");
|
||||
printf("\n");
|
||||
printf("Example: \n");
|
||||
printf("voicefont voicefontids.txt 2 voice\\ voicefont.bin\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pFile = fopen(argv[1], "r");
|
||||
if (pFile == NULL)
|
||||
{
|
||||
printf("Error opening language file %s\n", argv[1]);
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* We bitswap the voice file only SH based archos players, target IDs
|
||||
equal to or lower than 8. See the target_id line for each target in
|
||||
configure */
|
||||
target_id = atoi(argv[2]);
|
||||
equal to or lower than 8. See the target_id line for each target in
|
||||
configure */
|
||||
target_id = targetnum;
|
||||
if (target_id <= 8)
|
||||
do_bitswap_audio = 1;
|
||||
|
||||
memset(voiceonly, 0, sizeof(voiceonly));
|
||||
while (!feof(pFile))
|
||||
while (!feof(voicefontids))
|
||||
{
|
||||
fgets(line, sizeof(line), pFile);
|
||||
fgets(line, sizeof(line), voicefontids);
|
||||
if (line[0] == '#') /* comment */
|
||||
continue;
|
||||
|
||||
|
@ -132,24 +115,18 @@ int main (int argc, char** argv)
|
|||
continue;
|
||||
}
|
||||
}
|
||||
fclose(pFile);
|
||||
fclose(voicefontids);
|
||||
|
||||
pFile = fopen(argv[4], "wb");
|
||||
if (pFile == NULL)
|
||||
{
|
||||
printf("Error opening output file %s\n", argv[4]);
|
||||
return -2;
|
||||
}
|
||||
fseek(pFile, HEADER_SIZE + count*8, SEEK_SET); /* space for header */
|
||||
fseek(output, HEADER_SIZE + count*8, SEEK_SET); /* space for header */
|
||||
|
||||
for (i=0; i<count; i++)
|
||||
{
|
||||
if (voiceonly[i] == 1)
|
||||
count_voiceonly++;
|
||||
|
||||
pos[i] = ftell(pFile);
|
||||
sprintf(mp3filename1, "%s%s.mp3", argv[3], names[i]);
|
||||
sprintf(mp3filename2, "%s%s.wav.mp3", argv[3], names[i]);
|
||||
pos[i] = ftell(output);
|
||||
sprintf(mp3filename1, "%s%s.mp3", filedir, names[i]);
|
||||
sprintf(mp3filename2, "%s%s.wav.mp3", filedir, names[i]);
|
||||
mp3filename = mp3filename1;
|
||||
pMp3File = fopen(mp3filename, "rb");
|
||||
if (pMp3File == NULL)
|
||||
|
@ -169,36 +146,36 @@ int main (int argc, char** argv)
|
|||
fclose(pMp3File);
|
||||
if (do_bitswap_audio)
|
||||
BitswapAudio(buffer, buffer, size[i]);
|
||||
fwrite(buffer, 1, size[i], pFile);
|
||||
fwrite(buffer, 1, size[i], output);
|
||||
|
||||
printf("%d %s %d\n", i, names[i], size[i]); /* debug */
|
||||
} /* for i */
|
||||
|
||||
|
||||
fseek(pFile, 0, SEEK_SET);
|
||||
fseek(output, 0, SEEK_SET);
|
||||
|
||||
/* Create the file format: */
|
||||
|
||||
/* 1st 32 bit value in the file is the version number */
|
||||
value = SWAP4(400); /* 4.00 */
|
||||
fwrite(&value, sizeof(value), 1, pFile);
|
||||
fwrite(&value, sizeof(value), 1, output);
|
||||
|
||||
/* 2nd 32 bit value in the file is the id number for the target
|
||||
we made the voce file for */
|
||||
value = SWAP4(atoi(argv[2]));
|
||||
fwrite(&value, sizeof(value), 1, pFile);
|
||||
value = SWAP4(targetnum);
|
||||
fwrite(&value, sizeof(value), 1, output);
|
||||
|
||||
/* 3rd 32 bit value in the file is the header size (= 1st table position) */
|
||||
value = SWAP4(HEADER_SIZE); /* version, target id, header size, number1, number2 */
|
||||
fwrite(&value, sizeof(value), 1, pFile);
|
||||
fwrite(&value, sizeof(value), 1, output);
|
||||
|
||||
/* 4th 32 bit value in the file is the number of clips in 1st table */
|
||||
value = SWAP4(count-count_voiceonly);
|
||||
fwrite(&value, sizeof(value), 1, pFile);
|
||||
fwrite(&value, sizeof(value), 1, output);
|
||||
|
||||
/* 5th bit value in the file is the number of clips in 2nd table */
|
||||
value = SWAP4(count_voiceonly);
|
||||
fwrite(&value, sizeof(value), 1, pFile);
|
||||
fwrite(&value, sizeof(value), 1, output);
|
||||
|
||||
/* then followed by offset/size pairs for each clip */
|
||||
for (j=0; j<2; j++) /* now 2 tables */
|
||||
|
@ -217,9 +194,9 @@ int main (int argc, char** argv)
|
|||
}
|
||||
|
||||
value = SWAP4(pos[i]); /* position */
|
||||
fwrite(&value, sizeof(value), 1, pFile);
|
||||
fwrite(&value, sizeof(value), 1,output);
|
||||
value = SWAP4(size[i]); /* size */
|
||||
fwrite(&value, sizeof(value), 1, pFile);
|
||||
fwrite(&value, sizeof(value), 1, output);
|
||||
} /* for i */
|
||||
} /* for j */
|
||||
|
||||
|
@ -229,7 +206,41 @@ int main (int argc, char** argv)
|
|||
* which we already have written, see above.
|
||||
*/
|
||||
|
||||
fclose(pFile);
|
||||
fclose(output);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
#ifndef RBUTIL
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("Makes a Rockbox voicefont from a collection of mp3 clips.\n");
|
||||
printf("Usage: voicefont <string id list file> <target id> <mp3 path> <output file>\n");
|
||||
printf("\n");
|
||||
printf("Example: \n");
|
||||
printf("voicefont voicefontids.txt 2 voice\\ voicefont.bin\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILE* ids = fopen(argv[1], "r");
|
||||
if (ids == NULL)
|
||||
{
|
||||
printf("Error opening language file %s\n", argv[1]);
|
||||
return -2;
|
||||
}
|
||||
|
||||
FILE* output = fopen(argv[4], "wb");
|
||||
if (output == NULL)
|
||||
{
|
||||
printf("Error opening output file %s\n", argv[4]);
|
||||
return -2;
|
||||
}
|
||||
|
||||
voicefont(ids, atoi(argv[2]),argv[3],output);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
33
tools/voicefont.h
Normal file
33
tools/voicefont.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id: voicefont.h 15675 2007-11-18 22:01:31Z amiconn $
|
||||
*
|
||||
* Copyright (C) 2004 by Jörg Hohensohn
|
||||
*
|
||||
* All files in this archive are subject to the GNU General Public License.
|
||||
* See the file COPYING in the source tree root for full license agreement.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* A tool to generate the Rockbox "voicefont", a collection of all the UI
|
||||
* strings.
|
||||
*
|
||||
* Details at http://www.rockbox.org/twiki/bin/view/Main/VoiceBuilding
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef VOICEFONT_H
|
||||
#define VOICEFONT_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int voicefont(FILE* voicefontids,int targetnum,char* filedir, FILE* output);
|
||||
|
||||
#endif
|
|
@ -23,6 +23,8 @@
|
|||
#include <stdio.h> /* for file I/O */
|
||||
#include <stdlib.h> /* for malloc */
|
||||
|
||||
#include "wavtrim.h"
|
||||
|
||||
/* place a 32 bit value into memory, little endian */
|
||||
void Write32(unsigned char* pByte, unsigned long value)
|
||||
{
|
||||
|
@ -66,9 +68,8 @@ unsigned long Read16(unsigned char* pByte)
|
|||
return value;
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
int wavtrim(char * filename, int maxsilence ,char* errstring,int errsize)
|
||||
{
|
||||
FILE* pFile;
|
||||
long lFileSize, lGot;
|
||||
unsigned char* pBuf;
|
||||
|
@ -79,29 +80,17 @@ int main (int argc, char** argv)
|
|||
unsigned char *databuf; /* Pointer to the data chunk payload */
|
||||
int skip_head, skip_tail, pad_head, pad_tail;
|
||||
int i;
|
||||
int max_silence = 0;
|
||||
int max_silence = maxsilence;
|
||||
signed char sample8;
|
||||
short sample16;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("wavtrim removes silence at the begin and end of a WAV file.\n");
|
||||
printf("usage: wavtrim <filename.wav> [<max_silence>]\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc == 3)
|
||||
{
|
||||
max_silence = atoi(argv[2]);
|
||||
}
|
||||
|
||||
pFile = fopen(argv[1], "rb");
|
||||
pFile = fopen(filename, "rb");
|
||||
if (pFile == NULL)
|
||||
{
|
||||
printf("Error opening file %s for reading\n", argv[1]);
|
||||
snprintf(errstring,errsize,"Error opening file %s for reading\n", filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
fseek(pFile, 0, SEEK_END);
|
||||
lFileSize = ftell(pFile);
|
||||
fseek(pFile, 0, SEEK_SET);
|
||||
|
@ -109,7 +98,7 @@ int main (int argc, char** argv)
|
|||
pBuf = malloc(lFileSize);
|
||||
if (pBuf == NULL)
|
||||
{
|
||||
printf("Out of memory to allocate %ld bytes for file.\n", lFileSize);
|
||||
snprintf(errstring,errsize,"Out of memory to allocate %ld bytes for file.\n", lFileSize);
|
||||
fclose(pFile);
|
||||
return -1;
|
||||
}
|
||||
|
@ -118,11 +107,12 @@ int main (int argc, char** argv)
|
|||
fclose(pFile);
|
||||
if (lGot != lFileSize)
|
||||
{
|
||||
printf("File read error, got only %ld bytes out of %ld.\n", lGot, lFileSize);
|
||||
snprintf(errstring,errsize,"File read error, got only %ld bytes out of %ld.\n", lGot, lFileSize);
|
||||
free(pBuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bps = Read16(pBuf + 32);
|
||||
datapos = 28 + Read16(pBuf + 16);
|
||||
databuf = &pBuf[datapos];
|
||||
|
@ -132,7 +122,7 @@ int main (int argc, char** argv)
|
|||
|| Read32(pBuf+12) != 0x20746d66 /* "fmt " */
|
||||
|| Read32(pBuf+datapos-8) != 0x61746164) /* "data" */
|
||||
{
|
||||
printf("No valid input WAV file?\n", lGot, lFileSize);
|
||||
snprintf(errstring,errsize,"No valid input WAV file?\n");
|
||||
free(pBuf);
|
||||
return -1;
|
||||
}
|
||||
|
@ -198,10 +188,10 @@ int main (int argc, char** argv)
|
|||
Write32(pBuf+4, Read32(pBuf+4) - skip_head - skip_tail);
|
||||
Write32(pBuf+datapos-4, datalen - skip_head - skip_tail);
|
||||
|
||||
pFile = fopen(argv[1], "wb");
|
||||
pFile = fopen(filename, "wb");
|
||||
if (pFile == NULL)
|
||||
{
|
||||
printf("Error opening file %s for writing\n", argv[1]);
|
||||
snprintf(errstring,errsize,"Error opening file %s for writing\n",filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -212,8 +202,37 @@ int main (int argc, char** argv)
|
|||
|
||||
free(pBuf);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
#ifndef RBUTIL
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
int max_silence = 0;
|
||||
char errbuffer[255];
|
||||
int ret=0;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("wavtrim removes silence at the begin and end of a WAV file.\n");
|
||||
printf("usage: wavtrim <filename.wav> [<max_silence>]\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc == 3)
|
||||
{
|
||||
max_silence = atoi(argv[2]);
|
||||
}
|
||||
|
||||
|
||||
ret = wavtrim(argv[1],max_silence,errbuffer,255 );
|
||||
if( ret< 0)
|
||||
{
|
||||
printf(errbuffer);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
RIFF Chunk (12 bytes in length total)
|
||||
0 - 3 "RIFF" (ASCII Characters)
|
||||
|
|
27
tools/wavtrim.h
Normal file
27
tools/wavtrim.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id: wavtrim.h 14229 2007-08-07 10:21:03Z linus $
|
||||
*
|
||||
* Copyright (C) 2004 by Jörg Hohensohn
|
||||
*
|
||||
* All files in this archive are subject to the GNU General Public License.
|
||||
* See the file COPYING in the source tree root for full license agreement.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* Details at http://www.rockbox.org/twiki/bin/view/Main/VoiceBuilding
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef WAVTRIM_H
|
||||
#define WAVTRIM_H
|
||||
|
||||
int wavtrim(char * filename, int maxsilence ,char* errstring,int errsize);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue