2004-03-19 22:15:53 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2004 J<EFBFBD>rg Hohensohn
|
|
|
|
|
*
|
|
|
|
|
* This module collects the Talkbox and voice UI functions.
|
|
|
|
|
* (Talkbox reads directory names from mp3 clips called thumbnails,
|
2004-05-09 09:41:23 +00:00
|
|
|
|
* the voice UI lets menus and screens "talk" from a voicefile in memory.
|
2004-03-19 22:15:53 +00:00
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stddef.h>
|
2006-02-23 21:29:29 +00:00
|
|
|
|
#include <string.h>
|
2004-03-19 22:15:53 +00:00
|
|
|
|
#include "file.h"
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "system.h"
|
2004-04-06 07:06:59 +00:00
|
|
|
|
#include "settings.h"
|
2004-03-19 22:15:53 +00:00
|
|
|
|
#include "mp3_playback.h"
|
2005-04-04 12:06:29 +00:00
|
|
|
|
#include "audio.h"
|
2004-03-19 22:15:53 +00:00
|
|
|
|
#include "lang.h"
|
|
|
|
|
#include "talk.h"
|
2004-03-27 00:11:01 +00:00
|
|
|
|
#include "id3.h"
|
2005-08-20 11:13:19 +00:00
|
|
|
|
#include "logf.h"
|
2004-09-26 09:25:59 +00:00
|
|
|
|
#include "bitswap.h"
|
2005-08-29 21:15:27 +00:00
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2005-08-20 11:13:19 +00:00
|
|
|
|
#include "playback.h"
|
|
|
|
|
#endif
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
|
|
|
|
/***************** Constants *****************/
|
|
|
|
|
|
2004-05-09 09:41:23 +00:00
|
|
|
|
#define QUEUE_SIZE 64 /* must be a power of two */
|
|
|
|
|
#define QUEUE_MASK (QUEUE_SIZE-1)
|
2004-08-01 23:34:44 +00:00
|
|
|
|
const char* const dir_thumbnail_name = "_dirname.talk";
|
2004-10-21 18:34:48 +00:00
|
|
|
|
const char* const file_thumbnail_ext = ".talk";
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
2004-05-09 09:41:23 +00:00
|
|
|
|
/***************** Functional Macros *****************/
|
|
|
|
|
|
|
|
|
|
#define QUEUE_LEVEL ((queue_write - queue_read) & QUEUE_MASK)
|
|
|
|
|
|
2004-10-12 16:43:22 +00:00
|
|
|
|
#define LOADED_MASK 0x80000000 /* MSB */
|
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
|
|
|
|
/***************** Data types *****************/
|
|
|
|
|
|
|
|
|
|
struct clip_entry /* one entry of the index table */
|
|
|
|
|
{
|
2004-05-09 09:41:23 +00:00
|
|
|
|
int offset; /* offset from start of voicefile file */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
int size; /* size of the clip */
|
|
|
|
|
};
|
|
|
|
|
|
2004-05-09 09:41:23 +00:00
|
|
|
|
struct voicefile /* file format of our voice file */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
{
|
2004-05-09 09:41:23 +00:00
|
|
|
|
int version; /* version of the voicefile */
|
2004-04-03 20:52:24 +00:00
|
|
|
|
int table; /* offset to index table, (=header size) */
|
|
|
|
|
int id1_max; /* number of "normal" clips contained in above index */
|
|
|
|
|
int id2_max; /* number of "voice only" clips contained in above index */
|
|
|
|
|
struct clip_entry index[]; /* followed by the index tables */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
/* and finally the bitswapped mp3 clips, not visible here */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct queue_entry /* one entry of the internal queue */
|
|
|
|
|
{
|
|
|
|
|
unsigned char* buf;
|
2005-02-12 11:26:36 +00:00
|
|
|
|
long len;
|
2004-03-19 22:15:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************** Globals *****************/
|
|
|
|
|
|
|
|
|
|
static unsigned char* p_thumbnail; /* buffer for thumbnail */
|
|
|
|
|
static long size_for_thumbnail; /* leftover buffer size for it */
|
2004-05-09 09:41:23 +00:00
|
|
|
|
static struct voicefile* p_voicefile; /* loaded voicefile */
|
|
|
|
|
static bool has_voicefile; /* a voicefile file is present */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
static struct queue_entry queue[QUEUE_SIZE]; /* queue of scheduled clips */
|
|
|
|
|
static int queue_write; /* write index of queue, by application */
|
|
|
|
|
static int queue_read; /* read index of queue, by ISR context */
|
2004-05-09 09:41:23 +00:00
|
|
|
|
static int sent; /* how many bytes handed over to playback, owned by ISR */
|
2004-04-20 21:47:07 +00:00
|
|
|
|
static unsigned char curr_hd[3]; /* current frame header, for re-sync */
|
2004-10-12 16:43:22 +00:00
|
|
|
|
static int filehandle; /* global, so the MMC variant can keep the file open */
|
2004-11-17 22:30:38 +00:00
|
|
|
|
static unsigned char* p_silence; /* VOICE_PAUSE clip, used for termination */
|
2005-02-12 11:26:36 +00:00
|
|
|
|
static long silence_len; /* length of the VOICE_PAUSE clip */
|
2004-11-17 22:30:38 +00:00
|
|
|
|
static unsigned char* p_lastclip; /* address of latest clip, for silence add */
|
2005-08-20 11:13:19 +00:00
|
|
|
|
static unsigned long voicefile_size = 0; /* size of the loaded voice file */
|
2006-02-23 21:29:29 +00:00
|
|
|
|
static unsigned char last_lang[MAX_FILENAME+1]; /* name of last used lang file (in talk_init) */
|
2006-02-26 16:07:34 +00:00
|
|
|
|
static bool talk_initialized; /* true if talk_init has been called */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
2004-03-21 17:45:45 +00:00
|
|
|
|
/***************** Private prototypes *****************/
|
|
|
|
|
|
2004-10-12 16:43:22 +00:00
|
|
|
|
static void load_voicefile(void);
|
2004-03-21 17:45:45 +00:00
|
|
|
|
static void mp3_callback(unsigned char** start, int* size);
|
|
|
|
|
static int shutup(void);
|
2005-02-12 11:26:36 +00:00
|
|
|
|
static int queue_clip(unsigned char* buf, long size, bool enqueue);
|
2004-04-06 07:06:59 +00:00
|
|
|
|
static int open_voicefile(void);
|
2005-02-12 11:26:36 +00:00
|
|
|
|
static unsigned char* get_clip(long id, long* p_size);
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************** Private implementation *****************/
|
|
|
|
|
|
2004-04-06 07:06:59 +00:00
|
|
|
|
static int open_voicefile(void)
|
|
|
|
|
{
|
|
|
|
|
char buf[64];
|
|
|
|
|
char* p_lang = "english"; /* default */
|
|
|
|
|
|
|
|
|
|
if ( global_settings.lang_file[0] &&
|
|
|
|
|
global_settings.lang_file[0] != 0xff )
|
|
|
|
|
{ /* try to open the voice file of the selected language */
|
2005-12-05 22:44:42 +00:00
|
|
|
|
p_lang = (char *)global_settings.lang_file;
|
2004-04-06 07:06:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), ROCKBOX_DIR LANG_DIR "/%s.voice", p_lang);
|
2005-08-20 11:13:19 +00:00
|
|
|
|
|
2004-04-06 07:06:59 +00:00
|
|
|
|
return open(buf, O_RDONLY);
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-20 11:13:19 +00:00
|
|
|
|
int talk_get_bufsize(void)
|
|
|
|
|
{
|
|
|
|
|
return voicefile_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef SIMULATOR
|
|
|
|
|
static unsigned short BSWAP16(unsigned short value)
|
|
|
|
|
{
|
|
|
|
|
return (value >> 8) | (value << 8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned long BSWAP32(unsigned long value)
|
|
|
|
|
{
|
|
|
|
|
unsigned long hi = BSWAP16(value >> 16);
|
|
|
|
|
unsigned long lo = BSWAP16(value & 0xffff);
|
|
|
|
|
return (lo << 16) | hi;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2004-04-06 07:06:59 +00:00
|
|
|
|
|
2004-05-09 09:41:23 +00:00
|
|
|
|
/* load the voice file into the mp3 buffer */
|
2004-10-12 16:43:22 +00:00
|
|
|
|
static void load_voicefile(void)
|
2004-03-19 22:15:53 +00:00
|
|
|
|
{
|
2004-10-12 16:43:22 +00:00
|
|
|
|
int load_size;
|
|
|
|
|
int got_size;
|
|
|
|
|
int file_size;
|
2005-08-29 21:15:27 +00:00
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2005-08-20 11:13:19 +00:00
|
|
|
|
int length, i;
|
|
|
|
|
unsigned char *buf, temp;
|
|
|
|
|
#endif
|
2004-10-12 16:43:22 +00:00
|
|
|
|
|
|
|
|
|
filehandle = open_voicefile();
|
|
|
|
|
if (filehandle < 0) /* failed to open */
|
|
|
|
|
goto load_err;
|
|
|
|
|
|
|
|
|
|
file_size = filesize(filehandle);
|
2005-04-05 11:33:58 +00:00
|
|
|
|
if (file_size > audiobufend - audiobuf) /* won't fit? */
|
2004-10-12 16:43:22 +00:00
|
|
|
|
goto load_err;
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_MMC /* load only the header for now */
|
|
|
|
|
load_size = offsetof(struct voicefile, index);
|
|
|
|
|
#else /* load the full file */
|
|
|
|
|
load_size = file_size;
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-04-05 11:33:58 +00:00
|
|
|
|
got_size = read(filehandle, audiobuf, load_size);
|
2005-08-20 11:13:19 +00:00
|
|
|
|
if (got_size != load_size /* failure */)
|
|
|
|
|
goto load_err;
|
|
|
|
|
|
|
|
|
|
#ifdef SIMULATOR
|
|
|
|
|
logf("Byte swapping voice file");
|
|
|
|
|
p_voicefile = (struct voicefile*)audiobuf;
|
|
|
|
|
p_voicefile->version = BSWAP32(p_voicefile->version);
|
|
|
|
|
p_voicefile->table = BSWAP32(p_voicefile->table);
|
|
|
|
|
p_voicefile->id1_max = BSWAP32(p_voicefile->id1_max);
|
|
|
|
|
p_voicefile->id2_max = BSWAP32(p_voicefile->id2_max);
|
|
|
|
|
p_voicefile = NULL;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (((struct voicefile*)audiobuf)->table /* format check */
|
2004-05-09 09:41:23 +00:00
|
|
|
|
== offsetof(struct voicefile, index))
|
2004-03-19 22:15:53 +00:00
|
|
|
|
{
|
2005-04-05 11:33:58 +00:00
|
|
|
|
p_voicefile = (struct voicefile*)audiobuf;
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
|
|
|
|
/* thumbnail buffer is the remaining space behind */
|
2005-04-05 11:33:58 +00:00
|
|
|
|
p_thumbnail = audiobuf + file_size;
|
2005-02-12 11:26:36 +00:00
|
|
|
|
p_thumbnail += (long)p_thumbnail % 2; /* 16-bit align */
|
2005-04-05 11:33:58 +00:00
|
|
|
|
size_for_thumbnail = audiobufend - p_thumbnail;
|
2004-03-19 22:15:53 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2004-10-12 16:43:22 +00:00
|
|
|
|
goto load_err;
|
|
|
|
|
|
2005-08-20 11:13:19 +00:00
|
|
|
|
#ifdef SIMULATOR
|
|
|
|
|
for (i = 0; i < p_voicefile->id1_max + p_voicefile->id2_max; i++)
|
|
|
|
|
{
|
|
|
|
|
struct clip_entry *ce;
|
|
|
|
|
ce = &p_voicefile->index[i];
|
|
|
|
|
ce->offset = BSWAP32(ce->offset);
|
|
|
|
|
ce->size = BSWAP32(ce->size);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Do a bitswap as necessary. */
|
2005-08-29 21:15:27 +00:00
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2005-08-20 11:13:19 +00:00
|
|
|
|
logf("Bitswapping voice file.");
|
|
|
|
|
cpu_boost(true);
|
|
|
|
|
buf = (unsigned char *)(&p_voicefile->index) +
|
|
|
|
|
(p_voicefile->id1_max + p_voicefile->id2_max) * sizeof(struct clip_entry);
|
2005-08-20 18:49:14 +00:00
|
|
|
|
length = file_size - (buf - audiobuf);
|
2005-08-20 11:13:19 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
|
{
|
2005-08-21 23:17:25 +00:00
|
|
|
|
temp = buf[i];
|
|
|
|
|
temp = ((temp >> 4) & 0x0f) | ((temp & 0x0f) << 4);
|
|
|
|
|
temp = ((temp >> 2) & 0x33) | ((temp & 0x33) << 2);
|
|
|
|
|
buf[i] = ((temp >> 1) & 0x55) | ((temp & 0x55) << 1);
|
2005-08-20 11:13:19 +00:00
|
|
|
|
}
|
|
|
|
|
cpu_boost(false);
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_MMC
|
2004-10-12 16:43:22 +00:00
|
|
|
|
/* load the index table, now that we know its size from the header */
|
|
|
|
|
load_size = (p_voicefile->id1_max + p_voicefile->id2_max)
|
|
|
|
|
* sizeof(struct clip_entry);
|
|
|
|
|
got_size = read(filehandle,
|
2005-04-05 11:33:58 +00:00
|
|
|
|
audiobuf + offsetof(struct voicefile, index), load_size);
|
2004-10-12 16:43:22 +00:00
|
|
|
|
if (got_size != load_size) /* read error */
|
|
|
|
|
goto load_err;
|
|
|
|
|
#else
|
|
|
|
|
close(filehandle); /* only the MMC variant leaves it open */
|
|
|
|
|
filehandle = -1;
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-11-17 22:30:38 +00:00
|
|
|
|
/* make sure to have the silence clip, if available */
|
|
|
|
|
p_silence = get_clip(VOICE_PAUSE, &silence_len);
|
|
|
|
|
|
2004-10-12 16:43:22 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
load_err:
|
|
|
|
|
p_voicefile = NULL;
|
|
|
|
|
has_voicefile = false; /* don't try again */
|
|
|
|
|
if (filehandle >= 0)
|
2004-03-19 22:15:53 +00:00
|
|
|
|
{
|
2004-10-12 16:43:22 +00:00
|
|
|
|
close(filehandle);
|
|
|
|
|
filehandle = -1;
|
2004-03-19 22:15:53 +00:00
|
|
|
|
}
|
2004-10-12 16:43:22 +00:00
|
|
|
|
return;
|
2004-03-19 22:15:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* called in ISR context if mp3 data got consumed */
|
|
|
|
|
static void mp3_callback(unsigned char** start, int* size)
|
|
|
|
|
{
|
2004-05-09 09:41:23 +00:00
|
|
|
|
queue[queue_read].len -= sent; /* we completed this */
|
|
|
|
|
queue[queue_read].buf += sent;
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
|
|
|
|
if (queue[queue_read].len > 0) /* current clip not finished? */
|
|
|
|
|
{ /* feed the next 64K-1 chunk */
|
2005-08-29 21:15:27 +00:00
|
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2004-05-09 09:41:23 +00:00
|
|
|
|
sent = MIN(queue[queue_read].len, 0xFFFF);
|
2005-08-20 11:13:19 +00:00
|
|
|
|
#else
|
|
|
|
|
sent = queue[queue_read].len;
|
|
|
|
|
#endif
|
2004-03-19 22:15:53 +00:00
|
|
|
|
*start = queue[queue_read].buf;
|
2004-05-09 09:41:23 +00:00
|
|
|
|
*size = sent;
|
2004-03-19 22:15:53 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2004-11-17 22:30:38 +00:00
|
|
|
|
else if (sent > 0) /* go to next entry */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
{
|
2004-11-18 22:59:20 +00:00
|
|
|
|
queue_read = (queue_read + 1) & QUEUE_MASK;
|
2004-03-19 22:15:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-11-18 22:59:20 +00:00
|
|
|
|
re_check:
|
|
|
|
|
|
2004-05-09 09:41:23 +00:00
|
|
|
|
if (QUEUE_LEVEL) /* queue is not empty? */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
{ /* start next clip */
|
2005-08-29 21:15:27 +00:00
|
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2004-05-09 09:41:23 +00:00
|
|
|
|
sent = MIN(queue[queue_read].len, 0xFFFF);
|
2005-08-20 11:13:19 +00:00
|
|
|
|
#else
|
|
|
|
|
sent = queue[queue_read].len;
|
|
|
|
|
#endif
|
2004-11-17 22:30:38 +00:00
|
|
|
|
*start = p_lastclip = queue[queue_read].buf;
|
2004-05-09 09:41:23 +00:00
|
|
|
|
*size = sent;
|
2004-11-18 22:59:20 +00:00
|
|
|
|
curr_hd[0] = p_lastclip[1];
|
|
|
|
|
curr_hd[1] = p_lastclip[2];
|
|
|
|
|
curr_hd[2] = p_lastclip[3];
|
2004-03-19 22:15:53 +00:00
|
|
|
|
}
|
2004-11-18 22:59:20 +00:00
|
|
|
|
else if (p_silence != NULL /* silence clip available */
|
|
|
|
|
&& p_lastclip != p_silence /* previous clip wasn't silence */
|
|
|
|
|
&& p_lastclip < p_thumbnail) /* ..and not a thumbnail */
|
2004-11-17 22:30:38 +00:00
|
|
|
|
{ /* add silence clip when queue runs empty playing a voice clip */
|
2004-11-18 22:59:20 +00:00
|
|
|
|
queue[queue_write].buf = p_silence;
|
|
|
|
|
queue[queue_write].len = silence_len;
|
|
|
|
|
queue_write = (queue_write + 1) & QUEUE_MASK;
|
|
|
|
|
|
|
|
|
|
goto re_check;
|
2004-11-17 22:30:38 +00:00
|
|
|
|
}
|
2004-03-19 22:15:53 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*size = 0; /* end of data */
|
|
|
|
|
mp3_play_stop(); /* fixme: should be done by caller */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* stop the playback and the pending clips, but at frame boundary */
|
|
|
|
|
static int shutup(void)
|
|
|
|
|
{
|
2004-03-21 17:45:45 +00:00
|
|
|
|
unsigned char* pos;
|
|
|
|
|
unsigned char* search;
|
|
|
|
|
unsigned char* end;
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
2004-05-09 09:41:23 +00:00
|
|
|
|
if (QUEUE_LEVEL == 0) /* has ended anyway */
|
|
|
|
|
{
|
2004-03-21 17:45:45 +00:00
|
|
|
|
return 0;
|
2004-05-09 09:41:23 +00:00
|
|
|
|
}
|
2005-02-02 21:50:24 +00:00
|
|
|
|
#if CONFIG_CPU == SH7034
|
2004-05-09 09:41:23 +00:00
|
|
|
|
CHCR3 &= ~0x0001; /* disable the DMA (and therefore the interrupt also) */
|
2005-02-02 21:50:24 +00:00
|
|
|
|
#endif
|
2004-03-21 17:45:45 +00:00
|
|
|
|
/* search next frame boundary and continue up to there */
|
|
|
|
|
pos = search = mp3_get_pos();
|
|
|
|
|
end = queue[queue_read].buf + queue[queue_read].len;
|
|
|
|
|
|
2004-05-09 09:41:23 +00:00
|
|
|
|
if (pos >= queue[queue_read].buf
|
|
|
|
|
&& pos <= end) /* really our clip? */
|
|
|
|
|
{ /* (for strange reasons this isn't nesessarily the case) */
|
|
|
|
|
/* find the next frame boundary */
|
|
|
|
|
while (search < end) /* search the remaining data */
|
2004-03-21 17:45:45 +00:00
|
|
|
|
{
|
2004-05-09 09:41:23 +00:00
|
|
|
|
if (*search++ != 0xFF) /* quick search for frame sync byte */
|
|
|
|
|
continue; /* (this does the majority of the job) */
|
|
|
|
|
|
|
|
|
|
/* look at the (bitswapped) rest of header candidate */
|
|
|
|
|
if (search[0] == curr_hd[0] /* do the quicker checks first */
|
|
|
|
|
&& search[2] == curr_hd[2]
|
|
|
|
|
&& (search[1] & 0x30) == (curr_hd[1] & 0x30)) /* sample rate */
|
|
|
|
|
{
|
|
|
|
|
search--; /* back to the sync byte */
|
|
|
|
|
break; /* From looking at it, this is our header. */
|
|
|
|
|
}
|
2004-03-21 17:45:45 +00:00
|
|
|
|
}
|
2004-04-20 22:11:20 +00:00
|
|
|
|
|
2004-05-09 09:41:23 +00:00
|
|
|
|
if (search-pos)
|
|
|
|
|
{ /* play old data until the frame end, to keep the MAS in sync */
|
|
|
|
|
sent = search-pos;
|
|
|
|
|
|
2004-11-18 22:59:20 +00:00
|
|
|
|
queue_write = (queue_read + 1) & QUEUE_MASK; /* will be empty after next callback */
|
2004-05-09 09:41:23 +00:00
|
|
|
|
queue[queue_read].len = sent; /* current one ends after this */
|
|
|
|
|
|
2005-02-02 21:50:24 +00:00
|
|
|
|
#if CONFIG_CPU == SH7034
|
2004-05-09 09:41:23 +00:00
|
|
|
|
DTCR3 = sent; /* let the DMA finish this frame */
|
|
|
|
|
CHCR3 |= 0x0001; /* re-enable DMA */
|
2005-02-02 21:50:24 +00:00
|
|
|
|
#endif
|
2004-05-09 09:41:23 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2004-04-20 22:11:20 +00:00
|
|
|
|
}
|
2004-03-21 17:45:45 +00:00
|
|
|
|
|
2004-05-09 09:41:23 +00:00
|
|
|
|
/* nothing to do, was frame boundary or not our clip */
|
|
|
|
|
mp3_play_stop();
|
|
|
|
|
queue_write = queue_read = 0; /* reset the queue */
|
2005-08-20 11:13:19 +00:00
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* schedule a clip, at the end or discard the existing queue */
|
2005-02-12 11:26:36 +00:00
|
|
|
|
static int queue_clip(unsigned char* buf, long size, bool enqueue)
|
2004-03-19 22:15:53 +00:00
|
|
|
|
{
|
2004-05-09 09:41:23 +00:00
|
|
|
|
int queue_level;
|
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
|
if (!enqueue)
|
|
|
|
|
shutup(); /* cut off all the pending stuff */
|
|
|
|
|
|
2004-05-09 09:41:23 +00:00
|
|
|
|
if (!size)
|
|
|
|
|
return 0; /* safety check */
|
2005-02-02 21:50:24 +00:00
|
|
|
|
#if CONFIG_CPU == SH7034
|
2004-05-09 09:41:23 +00:00
|
|
|
|
/* disable the DMA temporarily, to be safe of race condition */
|
|
|
|
|
CHCR3 &= ~0x0001;
|
2005-02-02 21:50:24 +00:00
|
|
|
|
#endif
|
2004-05-09 09:41:23 +00:00
|
|
|
|
queue_level = QUEUE_LEVEL; /* check old level */
|
|
|
|
|
|
|
|
|
|
if (queue_level < QUEUE_SIZE - 1) /* space left? */
|
|
|
|
|
{
|
|
|
|
|
queue[queue_write].buf = buf; /* populate an entry */
|
|
|
|
|
queue[queue_write].len = size;
|
2004-11-18 22:59:20 +00:00
|
|
|
|
queue_write = (queue_write + 1) & QUEUE_MASK;
|
2004-05-09 09:41:23 +00:00
|
|
|
|
}
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
2004-05-09 09:41:23 +00:00
|
|
|
|
if (queue_level == 0)
|
|
|
|
|
{ /* queue was empty, we have to do the initial start */
|
2004-11-17 22:30:38 +00:00
|
|
|
|
p_lastclip = buf;
|
2005-08-29 21:15:27 +00:00
|
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2004-05-09 09:41:23 +00:00
|
|
|
|
sent = MIN(size, 0xFFFF); /* DMA can do no more */
|
2005-08-20 11:13:19 +00:00
|
|
|
|
#else
|
|
|
|
|
sent = size;
|
|
|
|
|
#endif
|
2004-05-09 09:41:23 +00:00
|
|
|
|
mp3_play_data(buf, sent, mp3_callback);
|
2004-04-20 21:47:07 +00:00
|
|
|
|
curr_hd[0] = buf[1];
|
|
|
|
|
curr_hd[1] = buf[2];
|
|
|
|
|
curr_hd[2] = buf[3];
|
2004-03-19 22:15:53 +00:00
|
|
|
|
mp3_play_pause(true); /* kickoff audio */
|
|
|
|
|
}
|
2004-05-09 09:41:23 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2005-02-02 21:50:24 +00:00
|
|
|
|
#if CONFIG_CPU == SH7034
|
2004-05-09 09:41:23 +00:00
|
|
|
|
CHCR3 |= 0x0001; /* re-enable DMA */
|
2005-02-02 21:50:24 +00:00
|
|
|
|
#endif
|
2004-05-09 09:41:23 +00:00
|
|
|
|
}
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-17 22:30:38 +00:00
|
|
|
|
/* fetch a clip from the voice file */
|
2005-02-12 11:26:36 +00:00
|
|
|
|
static unsigned char* get_clip(long id, long* p_size)
|
2004-11-17 22:30:38 +00:00
|
|
|
|
{
|
2005-02-12 11:26:36 +00:00
|
|
|
|
long clipsize;
|
2004-11-17 22:30:38 +00:00
|
|
|
|
unsigned char* clipbuf;
|
|
|
|
|
|
|
|
|
|
if (id > VOICEONLY_DELIMITER)
|
|
|
|
|
{ /* voice-only entries use the second part of the table */
|
|
|
|
|
id -= VOICEONLY_DELIMITER + 1;
|
|
|
|
|
if (id >= p_voicefile->id2_max)
|
|
|
|
|
return NULL; /* must be newer than we have */
|
|
|
|
|
id += p_voicefile->id1_max; /* table 2 is behind table 1 */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ /* normal use of the first table */
|
|
|
|
|
if (id >= p_voicefile->id1_max)
|
|
|
|
|
return NULL; /* must be newer than we have */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clipsize = p_voicefile->index[id].size;
|
|
|
|
|
if (clipsize == 0) /* clip not included in voicefile */
|
|
|
|
|
return NULL;
|
2005-04-05 11:33:58 +00:00
|
|
|
|
clipbuf = audiobuf + p_voicefile->index[id].offset;
|
2004-11-17 22:30:38 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_MMC /* dynamic loading, on demand */
|
|
|
|
|
if (!(clipsize & LOADED_MASK))
|
|
|
|
|
{ /* clip used for the first time, needs loading */
|
|
|
|
|
lseek(filehandle, p_voicefile->index[id].offset, SEEK_SET);
|
|
|
|
|
if (read(filehandle, clipbuf, clipsize) != clipsize)
|
|
|
|
|
return NULL; /* read error */
|
|
|
|
|
|
|
|
|
|
p_voicefile->index[id].size |= LOADED_MASK; /* mark as loaded */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ /* clip is in memory already */
|
|
|
|
|
clipsize &= ~LOADED_MASK; /* without the extra bit gives true size */
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
*p_size = clipsize;
|
|
|
|
|
return clipbuf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-10-12 16:43:22 +00:00
|
|
|
|
/* common code for talk_init() and talk_buffer_steal() */
|
2004-08-31 22:13:20 +00:00
|
|
|
|
static void reset_state(void)
|
|
|
|
|
{
|
|
|
|
|
queue_write = queue_read = 0; /* reset the queue */
|
|
|
|
|
p_voicefile = NULL; /* indicate no voicefile (trashed) */
|
2005-04-05 11:33:58 +00:00
|
|
|
|
p_thumbnail = audiobuf; /* whole space for thumbnail */
|
|
|
|
|
size_for_thumbnail = audiobufend - audiobuf;
|
2004-11-17 22:30:38 +00:00
|
|
|
|
p_silence = NULL; /* pause clip not accessible */
|
2004-08-31 22:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
|
/***************** Public implementation *****************/
|
|
|
|
|
|
|
|
|
|
void talk_init(void)
|
|
|
|
|
{
|
2006-02-26 16:07:34 +00:00
|
|
|
|
if (talk_initialized && !strcasecmp(last_lang, global_settings.lang_file))
|
2006-02-23 21:29:29 +00:00
|
|
|
|
{
|
|
|
|
|
/* not a new file, nothing to do */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2006-02-26 16:07:34 +00:00
|
|
|
|
talk_initialized = true;
|
2006-02-23 21:29:29 +00:00
|
|
|
|
strncpy((char *) last_lang, (char *)global_settings.lang_file,
|
|
|
|
|
MAX_FILENAME);
|
|
|
|
|
|
2005-09-14 16:07:07 +00:00
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
|
audio_stop();
|
|
|
|
|
#endif
|
2004-10-12 16:43:22 +00:00
|
|
|
|
reset_state(); /* use this for most of our inits */
|
2004-03-20 16:49:58 +00:00
|
|
|
|
|
2004-10-12 16:43:22 +00:00
|
|
|
|
#ifdef HAVE_MMC
|
|
|
|
|
load_voicefile(); /* load the tables right away */
|
|
|
|
|
has_voicefile = (p_voicefile != NULL);
|
|
|
|
|
#else
|
|
|
|
|
filehandle = open_voicefile();
|
|
|
|
|
has_voicefile = (filehandle >= 0); /* test if we can open it */
|
2005-08-20 11:13:19 +00:00
|
|
|
|
voicefile_size = 0;
|
|
|
|
|
|
2004-10-12 16:43:22 +00:00
|
|
|
|
if (has_voicefile)
|
2004-03-20 16:49:58 +00:00
|
|
|
|
{
|
2005-08-20 11:13:19 +00:00
|
|
|
|
voicefile_size = filesize(filehandle);
|
2005-08-29 21:15:27 +00:00
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2005-08-20 11:13:19 +00:00
|
|
|
|
voice_init();
|
|
|
|
|
#endif
|
2004-10-12 16:43:22 +00:00
|
|
|
|
close(filehandle); /* close again, this was just to detect presence */
|
|
|
|
|
filehandle = -1;
|
2004-03-20 16:49:58 +00:00
|
|
|
|
}
|
2004-10-12 16:43:22 +00:00
|
|
|
|
#endif
|
2005-08-20 11:13:19 +00:00
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* somebody else claims the mp3 buffer, e.g. for regular play/record */
|
|
|
|
|
int talk_buffer_steal(void)
|
|
|
|
|
{
|
2004-05-09 09:41:23 +00:00
|
|
|
|
mp3_play_stop();
|
2004-10-12 16:43:22 +00:00
|
|
|
|
#ifdef HAVE_MMC
|
|
|
|
|
if (filehandle >= 0) /* only relevant for MMC */
|
|
|
|
|
{
|
|
|
|
|
close(filehandle);
|
|
|
|
|
filehandle = -1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2004-08-31 22:13:20 +00:00
|
|
|
|
reset_state();
|
2004-03-19 22:15:53 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-05-09 09:41:23 +00:00
|
|
|
|
/* play a voice ID from voicefile */
|
2005-02-12 11:26:36 +00:00
|
|
|
|
int talk_id(long id, bool enqueue)
|
2004-03-19 22:15:53 +00:00
|
|
|
|
{
|
2005-02-12 11:26:36 +00:00
|
|
|
|
long clipsize;
|
2004-03-19 22:15:53 +00:00
|
|
|
|
unsigned char* clipbuf;
|
|
|
|
|
int unit;
|
|
|
|
|
|
2005-08-29 21:15:27 +00:00
|
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2005-04-04 12:06:29 +00:00
|
|
|
|
if (audio_status()) /* busy, buffer in use */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
return -1;
|
2005-08-20 11:13:19 +00:00
|
|
|
|
#endif
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
2004-05-09 09:41:23 +00:00
|
|
|
|
if (p_voicefile == NULL && has_voicefile)
|
|
|
|
|
load_voicefile(); /* reload needed */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
2004-05-09 09:41:23 +00:00
|
|
|
|
if (p_voicefile == NULL) /* still no voices? */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
2004-04-03 20:52:24 +00:00
|
|
|
|
if (id == -1) /* -1 is an indication for silence */
|
|
|
|
|
return -1;
|
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
|
/* check if this is a special ID, with a value */
|
2005-02-12 11:26:36 +00:00
|
|
|
|
unit = ((unsigned long)id) >> UNIT_SHIFT;
|
2004-04-03 20:52:24 +00:00
|
|
|
|
if (unit)
|
2004-03-19 22:15:53 +00:00
|
|
|
|
{ /* sign-extend the value */
|
2005-02-12 11:26:36 +00:00
|
|
|
|
id = (unsigned long)id << (32-UNIT_SHIFT);
|
2004-03-19 22:15:53 +00:00
|
|
|
|
id >>= (32-UNIT_SHIFT);
|
|
|
|
|
talk_value(id, unit, enqueue); /* speak it */
|
|
|
|
|
return 0; /* and stop, end of special case */
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-17 22:30:38 +00:00
|
|
|
|
clipbuf = get_clip(id, &clipsize);
|
|
|
|
|
if (clipbuf == NULL)
|
|
|
|
|
return -1; /* not present */
|
2004-10-12 16:43:22 +00:00
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
|
queue_clip(clipbuf, clipsize, enqueue);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* play a thumbnail from file */
|
2004-08-18 01:09:31 +00:00
|
|
|
|
int talk_file(const char* filename, bool enqueue)
|
2004-03-19 22:15:53 +00:00
|
|
|
|
{
|
|
|
|
|
int fd;
|
|
|
|
|
int size;
|
2004-03-27 00:11:01 +00:00
|
|
|
|
struct mp3entry info;
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
2005-04-04 12:06:29 +00:00
|
|
|
|
if (audio_status()) /* busy, buffer in use */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if (p_thumbnail == NULL || size_for_thumbnail <= 0)
|
|
|
|
|
return -1;
|
|
|
|
|
|
2004-07-27 14:10:48 +00:00
|
|
|
|
if(mp3info(&info, filename, false)) /* use this to find real start */
|
2004-03-27 00:11:01 +00:00
|
|
|
|
{
|
|
|
|
|
return 0; /* failed to open, or invalid */
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
|
fd = open(filename, O_RDONLY);
|
|
|
|
|
if (fd < 0) /* failed to open */
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-27 00:11:01 +00:00
|
|
|
|
lseek(fd, info.first_frame_offset, SEEK_SET); /* behind ID data */
|
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
|
size = read(fd, p_thumbnail, size_for_thumbnail);
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
|
|
/* ToDo: find audio, skip ID headers and trailers */
|
|
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
|
{
|
2005-08-29 21:15:27 +00:00
|
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2004-03-19 22:15:53 +00:00
|
|
|
|
bitswap(p_thumbnail, size);
|
2005-06-06 00:34:07 +00:00
|
|
|
|
#endif
|
2004-03-19 22:15:53 +00:00
|
|
|
|
queue_clip(p_thumbnail, size, enqueue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-03-20 16:49:58 +00:00
|
|
|
|
/* say a numeric value, this word ordering works for english,
|
|
|
|
|
but not necessarily for other languages (e.g. german) */
|
2005-02-12 11:26:36 +00:00
|
|
|
|
int talk_number(long n, bool enqueue)
|
2004-03-19 22:15:53 +00:00
|
|
|
|
{
|
2004-03-20 16:49:58 +00:00
|
|
|
|
int level = 0; /* mille count */
|
2005-02-12 11:26:36 +00:00
|
|
|
|
long mil = 1000000000; /* highest possible "-illion" */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
2005-08-29 21:15:27 +00:00
|
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2005-04-04 12:06:29 +00:00
|
|
|
|
if (audio_status()) /* busy, buffer in use */
|
2004-03-22 12:34:06 +00:00
|
|
|
|
return -1;
|
2005-08-20 11:13:19 +00:00
|
|
|
|
#endif
|
2004-03-22 12:34:06 +00:00
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
|
if (!enqueue)
|
|
|
|
|
shutup(); /* cut off all the pending stuff */
|
|
|
|
|
|
|
|
|
|
if (n==0)
|
2004-03-20 16:49:58 +00:00
|
|
|
|
{ /* special case */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
talk_id(VOICE_ZERO, true);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (n<0)
|
|
|
|
|
{
|
|
|
|
|
talk_id(VOICE_MINUS, true);
|
|
|
|
|
n = -n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (n)
|
|
|
|
|
{
|
2004-03-20 16:49:58 +00:00
|
|
|
|
int segment = n / mil; /* extract in groups of 3 digits */
|
|
|
|
|
n -= segment * mil; /* remove the used digits from number */
|
|
|
|
|
mil /= 1000; /* digit place for next round */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
|
|
|
|
if (segment)
|
|
|
|
|
{
|
|
|
|
|
int hundreds = segment / 100;
|
|
|
|
|
int ones = segment % 100;
|
|
|
|
|
|
|
|
|
|
if (hundreds)
|
|
|
|
|
{
|
|
|
|
|
talk_id(VOICE_ZERO + hundreds, true);
|
|
|
|
|
talk_id(VOICE_HUNDRED, true);
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-20 16:49:58 +00:00
|
|
|
|
/* combination indexing */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
if (ones > 20)
|
|
|
|
|
{
|
|
|
|
|
int tens = ones/10 + 18;
|
|
|
|
|
talk_id(VOICE_ZERO + tens, true);
|
|
|
|
|
ones %= 10;
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-20 16:49:58 +00:00
|
|
|
|
/* direct indexing */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
if (ones)
|
|
|
|
|
talk_id(VOICE_ZERO + ones, true);
|
|
|
|
|
|
2004-03-20 16:49:58 +00:00
|
|
|
|
/* add billion, million, thousand */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
if (mil)
|
|
|
|
|
talk_id(VOICE_BILLION + level, true);
|
|
|
|
|
}
|
|
|
|
|
level++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-20 21:47:07 +00:00
|
|
|
|
/* singular/plural aware saying of a value */
|
2005-02-12 11:26:36 +00:00
|
|
|
|
int talk_value(long n, int unit, bool enqueue)
|
2004-03-19 22:15:53 +00:00
|
|
|
|
{
|
|
|
|
|
int unit_id;
|
2004-08-26 20:30:22 +00:00
|
|
|
|
static const int unit_voiced[] =
|
2004-03-19 22:15:53 +00:00
|
|
|
|
{ /* lookup table for the voice ID of the units */
|
|
|
|
|
-1, -1, -1, /* regular ID, int, signed */
|
|
|
|
|
VOICE_MILLISECONDS, /* here come the "real" units */
|
|
|
|
|
VOICE_SECONDS,
|
|
|
|
|
VOICE_MINUTES,
|
|
|
|
|
VOICE_HOURS,
|
|
|
|
|
VOICE_KHZ,
|
|
|
|
|
VOICE_DB,
|
|
|
|
|
VOICE_PERCENT,
|
|
|
|
|
VOICE_MEGABYTE,
|
2004-03-20 16:49:58 +00:00
|
|
|
|
VOICE_GIGABYTE,
|
|
|
|
|
VOICE_MILLIAMPHOURS,
|
|
|
|
|
VOICE_PIXEL,
|
|
|
|
|
VOICE_PER_SEC,
|
|
|
|
|
VOICE_HERTZ,
|
2004-03-19 22:15:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
2005-08-29 21:15:27 +00:00
|
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2005-04-04 12:06:29 +00:00
|
|
|
|
if (audio_status()) /* busy, buffer in use */
|
2004-03-22 12:34:06 +00:00
|
|
|
|
return -1;
|
2005-08-20 11:13:19 +00:00
|
|
|
|
#endif
|
2004-03-22 12:34:06 +00:00
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
|
if (unit < 0 || unit >= UNIT_LAST)
|
|
|
|
|
unit_id = -1;
|
|
|
|
|
else
|
|
|
|
|
unit_id = unit_voiced[unit];
|
|
|
|
|
|
2004-03-20 16:49:58 +00:00
|
|
|
|
if ((n==1 || n==-1) /* singular? */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
&& unit_id >= VOICE_SECONDS && unit_id <= VOICE_HOURS)
|
|
|
|
|
{
|
|
|
|
|
unit_id--; /* use the singular for those units which have */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* special case with a "plus" before */
|
|
|
|
|
if (n > 0 && (unit == UNIT_SIGNED || unit == UNIT_DB))
|
|
|
|
|
{
|
|
|
|
|
talk_id(VOICE_PLUS, enqueue);
|
|
|
|
|
enqueue = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
talk_number(n, enqueue); /* say the number */
|
|
|
|
|
talk_id(unit_id, true); /* say the unit, if any */
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-04 19:08:44 +00:00
|
|
|
|
/* spell a string */
|
2004-08-26 20:30:22 +00:00
|
|
|
|
int talk_spell(const char* spell, bool enqueue)
|
2004-04-04 19:08:44 +00:00
|
|
|
|
{
|
|
|
|
|
char c; /* currently processed char */
|
|
|
|
|
|
2005-08-29 21:15:27 +00:00
|
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2005-04-04 12:06:29 +00:00
|
|
|
|
if (audio_status()) /* busy, buffer in use */
|
2004-04-04 19:08:44 +00:00
|
|
|
|
return -1;
|
2005-08-20 11:13:19 +00:00
|
|
|
|
#endif
|
2004-04-04 19:08:44 +00:00
|
|
|
|
|
|
|
|
|
if (!enqueue)
|
|
|
|
|
shutup(); /* cut off all the pending stuff */
|
|
|
|
|
|
|
|
|
|
while ((c = *spell++) != '\0')
|
|
|
|
|
{
|
|
|
|
|
/* if this grows into too many cases, I should use a table */
|
|
|
|
|
if (c >= 'A' && c <= 'Z')
|
|
|
|
|
talk_id(VOICE_CHAR_A + c - 'A', true);
|
|
|
|
|
else if (c >= 'a' && c <= 'z')
|
|
|
|
|
talk_id(VOICE_CHAR_A + c - 'a', true);
|
|
|
|
|
else if (c >= '0' && c <= '9')
|
|
|
|
|
talk_id(VOICE_ZERO + c - '0', true);
|
|
|
|
|
else if (c == '-')
|
|
|
|
|
talk_id(VOICE_MINUS, true);
|
|
|
|
|
else if (c == '+')
|
|
|
|
|
talk_id(VOICE_PLUS, true);
|
|
|
|
|
else if (c == '.')
|
2004-10-25 20:44:37 +00:00
|
|
|
|
talk_id(VOICE_DOT, true);
|
2004-10-23 17:58:38 +00:00
|
|
|
|
else if (c == ' ')
|
|
|
|
|
talk_id(VOICE_PAUSE, true);
|
2004-04-04 19:08:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|