From 25ecd0939f2d9532da6a58e72cf597bffadfb09f Mon Sep 17 00:00:00 2001 From: domonoky Date: Fri, 11 Jan 2008 23:46:10 +0000 Subject: [PATCH] refactored voicefont and wavtrim for inclusion into rbutil. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16058 a1c6a512-1295-4272-9138-f99709370657 --- tools/voicefont.c | 107 ++++++++++++++++++++++++++++++------------------------ tools/voicefont.h | 33 +++++++++++++++++ tools/wavtrim.c | 69 ++++++++++++++++++++++------------- tools/wavtrim.h | 27 ++++++++++++++ 4 files changed, 163 insertions(+), 73 deletions(-) create mode 100644 tools/voicefont.h create mode 100644 tools/wavtrim.h diff --git a/tools/voicefont.c b/tools/voicefont.c index 10f08f385..3dd5169cc 100644 --- a/tools/voicefont.c +++ b/tools/voicefont.c @@ -22,6 +22,8 @@ * ****************************************************************************/ +#include "voicefont.h" + #include #include @@ -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 \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 \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 diff --git a/tools/voicefont.h b/tools/voicefont.h new file mode 100644 index 000000000..63374e36d --- /dev/null +++ b/tools/voicefont.h @@ -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 +#include + +int voicefont(FILE* voicefontids,int targetnum,char* filedir, FILE* output); + +#endif diff --git a/tools/wavtrim.c b/tools/wavtrim.c index 3d77b4e97..fe212ef93 100644 --- a/tools/wavtrim.c +++ b/tools/wavtrim.c @@ -23,6 +23,8 @@ #include /* for file I/O */ #include /* 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 []\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 []\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) diff --git a/tools/wavtrim.h b/tools/wavtrim.h new file mode 100644 index 000000000..86dc28fda --- /dev/null +++ b/tools/wavtrim.h @@ -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 -- 2.11.4.GIT