/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id$ * * Copyright (C) 2004 by Jörg Hohensohn * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * 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/wiki/VoiceBuilding * ****************************************************************************/ #include "voicefont.h" #include #include #define HEADER_SIZE (20) #define MAX_NAME_LEN (80) #define MAX_VOICE_ENTRIES (2048) /* endian conversion macros */ #if defined(__BIG_ENDIAN__) #define UINT_TO_BE(x) (x) #else #define UINT_TO_BE(x) ((((unsigned)(x)>>24) & 0x000000ff) |\ (((unsigned)(x)>>8) & 0x0000ff00) |\ (((unsigned)(x)<<8) & 0x00ff0000) |\ (((unsigned)(x)<<24) & 0xff000000)) #endif int voicefont(FILE* voicefontids,int targetnum,char* filedir, FILE* output, unsigned int version) { int i,j; /* two tables, one for normal strings, one for voice-only (>0x8000) */ static char names[MAX_VOICE_ENTRIES][MAX_NAME_LEN]; /* worst-case space */ char name[MAX_NAME_LEN]; /* one string ID */ static int pos[MAX_VOICE_ENTRIES]; /* position of sample */ static int size[MAX_VOICE_ENTRIES]; /* length of clip */ int voiceonly[MAX_VOICE_ENTRIES]; /* flag if this is voice only */ int count = 0; int count_voiceonly = 0; unsigned int value; /* value to be written to file */ static unsigned char buffer[65535]; /* clip buffer, allow only 64K */ int fields; char line[255]; /* one line from the .lang file */ char mp3filename1[1024]; char mp3filename2[1024]; char* mp3filename; FILE* pMp3File; memset(voiceonly, 0, sizeof(voiceonly)); while (!feof(voicefontids)) { if (!fgets(line, sizeof(line), voicefontids)) break; if (line[0] == '#') /* comment */ continue; fields = sscanf(line, " id: %s", name); if (fields == 1) { strcpy(names[count], name); if (strncmp("VOICE_", name, 6) == 0) /* voice-only id? */ { count_voiceonly++; voiceonly[count] = 1; } count++; /* next entry started */ continue; } } fclose(voicefontids); if (count > MAX_VOICE_ENTRIES) { return -1; } 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; } ids = fopen(argv[1], "r"); if (ids == NULL) { printf("Error opening language file %s\n", argv[1]); return -2; } output = fopen(argv[4], "wb"); if (output == NULL) { printf("Error opening output file %s\n", argv[4]); return -2; } if (voicefont(ids, atoi(argv[2]),argv[3],output, 400) < 0) { printf("Error too many voicefont entries!\n"); return -3; } return 0; } #endif