2006-11-03 21:47:52 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-05-05 10:32:46 +00:00
|
|
|
* Copyright (C) 2004 by Jörg Hohensohn
|
2006-11-03 21:47:52 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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.
|
2006-11-03 21:47:52 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2020-06-07 01:37:17 +00:00
|
|
|
* Details at http://www.rockbox.org/wiki/VoiceBuilding
|
2006-11-03 21:47:52 +00:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-01-11 23:46:10 +00:00
|
|
|
#include "voicefont.h"
|
|
|
|
|
2006-11-03 21:47:52 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2007-11-18 22:01:31 +00:00
|
|
|
#define HEADER_SIZE 20
|
|
|
|
|
2006-11-03 21:47:52 +00:00
|
|
|
/* endian conversion macros */
|
2010-03-13 23:34:19 +00:00
|
|
|
#if defined(__BIG_ENDIAN__)
|
2012-06-03 14:40:30 +00:00
|
|
|
#define UINT_TO_BE(x) (x)
|
2010-03-13 23:34:19 +00:00
|
|
|
#else
|
2012-06-03 14:40:30 +00:00
|
|
|
#define UINT_TO_BE(x) ((((unsigned)(x)>>24) & 0x000000ff) |\
|
2006-11-03 21:47:52 +00:00
|
|
|
(((unsigned)(x)>>8) & 0x0000ff00) |\
|
|
|
|
(((unsigned)(x)<<8) & 0x00ff0000) |\
|
|
|
|
(((unsigned)(x)<<24) & 0xff000000))
|
2010-03-13 23:34:19 +00:00
|
|
|
#endif
|
2006-11-03 21:47:52 +00:00
|
|
|
|
2012-06-03 14:13:04 +00:00
|
|
|
int voicefont(FILE* voicefontids,int targetnum,char* filedir, FILE* output, unsigned int version)
|
2006-11-03 21:47:52 +00:00
|
|
|
{
|
2012-04-03 21:27:13 +00:00
|
|
|
|
2006-11-03 21:47:52 +00:00
|
|
|
int i,j;
|
2012-04-03 21:27:13 +00:00
|
|
|
|
2006-11-03 21:47:52 +00:00
|
|
|
/* two tables, one for normal strings, one for voice-only (>0x8000) */
|
|
|
|
static char names[1000][80]; /* worst-case space */
|
|
|
|
char name[80]; /* one string ID */
|
|
|
|
static int pos[1000]; /* position of sample */
|
|
|
|
static int size[1000]; /* length of clip */
|
|
|
|
int voiceonly[1000]; /* 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;
|
2007-08-06 18:39:04 +00:00
|
|
|
|
2006-11-03 21:47:52 +00:00
|
|
|
memset(voiceonly, 0, sizeof(voiceonly));
|
2008-01-11 23:46:10 +00:00
|
|
|
while (!feof(voicefontids))
|
2006-11-03 21:47:52 +00:00
|
|
|
{
|
2018-09-21 18:27:12 +00:00
|
|
|
if (!fgets(line, sizeof(line), voicefontids))
|
|
|
|
break;
|
2006-11-03 21:47:52 +00:00
|
|
|
if (line[0] == '#') /* comment */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fields = sscanf(line, " id: %s", name);
|
|
|
|
if (fields == 1)
|
|
|
|
{
|
2012-06-03 14:47:16 +00:00
|
|
|
strcpy(names[count], name);
|
2006-11-03 21:47:52 +00:00
|
|
|
if (strncmp("VOICE_", name, 6) == 0) /* voice-only id? */
|
2012-06-03 14:47:16 +00:00
|
|
|
{
|
|
|
|
count_voiceonly++;
|
|
|
|
voiceonly[count] = 1;
|
|
|
|
}
|
|
|
|
count++; /* next entry started */
|
2006-11-03 21:47:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2008-01-11 23:46:10 +00:00
|
|
|
fclose(voicefontids);
|
2006-11-03 21:47:52 +00:00
|
|
|
|
2008-01-11 23:46:10 +00:00
|
|
|
fseek(output, HEADER_SIZE + count*8, SEEK_SET); /* space for header */
|
2006-11-03 21:47:52 +00:00
|
|
|
|
|
|
|
for (i=0; i<count; i++)
|
|
|
|
{
|
2008-01-11 23:46:10 +00:00
|
|
|
pos[i] = ftell(output);
|
|
|
|
sprintf(mp3filename1, "%s%s.mp3", filedir, names[i]);
|
|
|
|
sprintf(mp3filename2, "%s%s.wav.mp3", filedir, names[i]);
|
2006-11-03 21:47:52 +00:00
|
|
|
mp3filename = mp3filename1;
|
|
|
|
pMp3File = fopen(mp3filename, "rb");
|
|
|
|
if (pMp3File == NULL)
|
|
|
|
{ /* alternatively, try the lame default filename */
|
|
|
|
mp3filename = mp3filename2;
|
|
|
|
pMp3File = fopen(mp3filename, "rb");
|
|
|
|
if (pMp3File == NULL)
|
|
|
|
{
|
|
|
|
printf("mp3 file %s not found!\n", mp3filename1);
|
|
|
|
size[i] = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2012-04-03 21:27:13 +00:00
|
|
|
printf("processing %s", mp3filename);
|
2006-11-03 21:47:52 +00:00
|
|
|
|
|
|
|
size[i] = fread(buffer, 1, sizeof(buffer), pMp3File);
|
|
|
|
fclose(pMp3File);
|
2008-01-11 23:46:10 +00:00
|
|
|
fwrite(buffer, 1, size[i], output);
|
2006-11-03 21:47:52 +00:00
|
|
|
|
2012-04-03 21:27:13 +00:00
|
|
|
printf(": %d %s %d\n", i, names[i], size[i]); /* debug */
|
2006-11-03 21:47:52 +00:00
|
|
|
} /* for i */
|
|
|
|
|
|
|
|
|
2008-01-11 23:46:10 +00:00
|
|
|
fseek(output, 0, SEEK_SET);
|
2006-11-03 21:47:52 +00:00
|
|
|
|
|
|
|
/* Create the file format: */
|
|
|
|
|
|
|
|
/* 1st 32 bit value in the file is the version number */
|
2012-06-03 14:13:04 +00:00
|
|
|
value = UINT_TO_BE(version);
|
2008-01-11 23:46:10 +00:00
|
|
|
fwrite(&value, sizeof(value), 1, output);
|
2006-11-03 21:47:52 +00:00
|
|
|
|
2007-08-05 19:19:39 +00:00
|
|
|
/* 2nd 32 bit value in the file is the id number for the target
|
|
|
|
we made the voce file for */
|
2012-06-03 14:40:30 +00:00
|
|
|
value = UINT_TO_BE(targetnum);
|
2008-01-11 23:46:10 +00:00
|
|
|
fwrite(&value, sizeof(value), 1, output);
|
2006-11-03 21:47:52 +00:00
|
|
|
|
2007-08-05 19:19:39 +00:00
|
|
|
/* 3rd 32 bit value in the file is the header size (= 1st table position) */
|
2012-06-03 14:40:30 +00:00
|
|
|
value = UINT_TO_BE(HEADER_SIZE); /* version, target id, header size, number1, number2 */
|
2008-01-11 23:46:10 +00:00
|
|
|
fwrite(&value, sizeof(value), 1, output);
|
2007-08-05 19:19:39 +00:00
|
|
|
|
|
|
|
/* 4th 32 bit value in the file is the number of clips in 1st table */
|
2012-06-03 14:40:30 +00:00
|
|
|
value = UINT_TO_BE(count-count_voiceonly);
|
2008-01-11 23:46:10 +00:00
|
|
|
fwrite(&value, sizeof(value), 1, output);
|
2006-11-03 21:47:52 +00:00
|
|
|
|
2007-08-05 19:19:39 +00:00
|
|
|
/* 5th bit value in the file is the number of clips in 2nd table */
|
2012-06-03 14:40:30 +00:00
|
|
|
value = UINT_TO_BE(count_voiceonly);
|
2008-01-11 23:46:10 +00:00
|
|
|
fwrite(&value, sizeof(value), 1, output);
|
2006-11-03 21:47:52 +00:00
|
|
|
|
|
|
|
/* then followed by offset/size pairs for each clip */
|
|
|
|
for (j=0; j<2; j++) /* now 2 tables */
|
|
|
|
{
|
|
|
|
for (i=0; i<count; i++)
|
|
|
|
{
|
|
|
|
if (j == 0) /* first run, skip the voice only ones */
|
|
|
|
{
|
|
|
|
if (voiceonly[i] == 1)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else /* second run, skip the non voice only ones */
|
|
|
|
{
|
2020-07-15 16:00:09 +00:00
|
|
|
if (!(voiceonly[i] == 1))
|
2006-11-03 21:47:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-06-03 14:40:30 +00:00
|
|
|
value = UINT_TO_BE(pos[i]); /* position */
|
2008-01-11 23:46:10 +00:00
|
|
|
fwrite(&value, sizeof(value), 1,output);
|
2012-06-03 14:40:30 +00:00
|
|
|
value = UINT_TO_BE(size[i]); /* size */
|
2008-01-11 23:46:10 +00:00
|
|
|
fwrite(&value, sizeof(value), 1, output);
|
2006-11-03 21:47:52 +00:00
|
|
|
} /* for i */
|
|
|
|
} /* for j */
|
|
|
|
|
2008-01-11 23:46:10 +00:00
|
|
|
fclose(output);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
#ifndef RBUTIL
|
|
|
|
int main (int argc, char** argv)
|
|
|
|
{
|
2008-10-06 06:45:41 +00:00
|
|
|
FILE *ids, *output;
|
2006-11-03 21:47:52 +00:00
|
|
|
|
2008-01-11 23:46:10 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-10-06 06:45:41 +00:00
|
|
|
ids = fopen(argv[1], "r");
|
2008-01-11 23:46:10 +00:00
|
|
|
if (ids == NULL)
|
|
|
|
{
|
|
|
|
printf("Error opening language file %s\n", argv[1]);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2008-10-06 06:45:41 +00:00
|
|
|
output = fopen(argv[4], "wb");
|
2008-01-11 23:46:10 +00:00
|
|
|
if (output == NULL)
|
|
|
|
{
|
|
|
|
printf("Error opening output file %s\n", argv[4]);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2012-06-03 14:13:04 +00:00
|
|
|
voicefont(ids, atoi(argv[2]),argv[3],output, 400);
|
2006-11-03 21:47:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-01-11 23:46:10 +00:00
|
|
|
#endif
|
2010-03-13 23:34:19 +00:00
|
|
|
|