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,
|
|
|
|
|
* the voice UI lets menus and screens "talk" from a voicefont in memory.
|
|
|
|
|
*
|
|
|
|
|
* 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>
|
|
|
|
|
#include "file.h"
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "system.h"
|
|
|
|
|
#include "mp3_playback.h"
|
|
|
|
|
#include "mpeg.h"
|
|
|
|
|
#include "lang.h"
|
|
|
|
|
#include "talk.h"
|
2004-03-27 00:11:01 +00:00
|
|
|
|
#include "id3.h"
|
2004-03-19 22:15:53 +00:00
|
|
|
|
extern void bitswap(unsigned char *data, int length); /* no header for this */
|
|
|
|
|
|
|
|
|
|
/***************** Constants *****************/
|
|
|
|
|
|
2004-03-20 16:49:58 +00:00
|
|
|
|
#define QUEUE_SIZE 20
|
|
|
|
|
const char* voicefont_file = "/.rockbox/langs/english.voice";
|
2004-03-27 00:11:01 +00:00
|
|
|
|
const char* dir_thumbnail_name = ".dirname.mp3";
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************** Data types *****************/
|
|
|
|
|
|
|
|
|
|
struct clip_entry /* one entry of the index table */
|
|
|
|
|
{
|
|
|
|
|
int offset; /* offset from start of voicefont file */
|
|
|
|
|
int size; /* size of the clip */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct voicefont /* file format of our "voicefont" */
|
|
|
|
|
{
|
|
|
|
|
int version; /* version of the voicefont */
|
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;
|
|
|
|
|
int len;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************** Globals *****************/
|
|
|
|
|
|
|
|
|
|
static unsigned char* p_thumbnail; /* buffer for thumbnail */
|
|
|
|
|
static long size_for_thumbnail; /* leftover buffer size for it */
|
|
|
|
|
static struct voicefont* p_voicefont; /* loaded voicefont */
|
|
|
|
|
static bool has_voicefont; /* a voicefont file is present */
|
|
|
|
|
static bool is_playing; /* we're currently playing */
|
|
|
|
|
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-03-21 17:45:45 +00:00
|
|
|
|
/***************** Private prototypes *****************/
|
|
|
|
|
|
|
|
|
|
static int load_voicefont(void);
|
|
|
|
|
static void mp3_callback(unsigned char** start, int* size);
|
|
|
|
|
static int shutup(void);
|
|
|
|
|
static int queue_clip(unsigned char* buf, int size, bool enqueue);
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************** Private implementation *****************/
|
|
|
|
|
|
|
|
|
|
static int load_voicefont(void)
|
|
|
|
|
{
|
|
|
|
|
int fd;
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
|
|
p_voicefont = NULL; /* indicate no voicefont if we fail below */
|
|
|
|
|
|
2004-03-20 16:49:58 +00:00
|
|
|
|
fd = open(voicefont_file, O_RDONLY);
|
2004-03-19 22:15:53 +00:00
|
|
|
|
if (fd < 0) /* failed to open */
|
|
|
|
|
{
|
|
|
|
|
p_voicefont = NULL; /* indicate no voicefont */
|
|
|
|
|
has_voicefont = false; /* don't try again */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size = read(fd, mp3buf, mp3end - mp3buf);
|
|
|
|
|
if (size > 1000
|
2004-04-03 20:52:24 +00:00
|
|
|
|
&& ((struct voicefont*)mp3buf)->table
|
2004-03-19 22:15:53 +00:00
|
|
|
|
== offsetof(struct voicefont, index))
|
|
|
|
|
{
|
|
|
|
|
p_voicefont = (struct voicefont*)mp3buf;
|
|
|
|
|
|
|
|
|
|
/* thumbnail buffer is the remaining space behind */
|
|
|
|
|
p_thumbnail = mp3buf + size;
|
|
|
|
|
p_thumbnail += (int)p_thumbnail % 2; /* 16-bit align */
|
|
|
|
|
size_for_thumbnail = mp3end - p_thumbnail;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
has_voicefont = false; /* don't try again */
|
|
|
|
|
}
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* called in ISR context if mp3 data got consumed */
|
|
|
|
|
static void mp3_callback(unsigned char** start, int* size)
|
|
|
|
|
{
|
|
|
|
|
int play_now;
|
|
|
|
|
|
|
|
|
|
if (queue[queue_read].len > 0) /* current clip not finished? */
|
|
|
|
|
{ /* feed the next 64K-1 chunk */
|
|
|
|
|
play_now = MIN(queue[queue_read].len, 0xFFFF);
|
|
|
|
|
*start = queue[queue_read].buf;
|
|
|
|
|
*size = play_now;
|
|
|
|
|
queue[queue_read].buf += play_now;
|
|
|
|
|
queue[queue_read].len -= play_now;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else /* go to next entry */
|
|
|
|
|
{
|
|
|
|
|
queue_read++;
|
|
|
|
|
if (queue_read >= QUEUE_SIZE)
|
|
|
|
|
queue_read = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (queue_read != queue_write) /* queue is not empty? */
|
|
|
|
|
{ /* start next clip */
|
|
|
|
|
play_now = MIN(queue[queue_read].len, 0xFFFF);
|
|
|
|
|
*start = queue[queue_read].buf;
|
|
|
|
|
*size = play_now;
|
|
|
|
|
queue[queue_read].buf += play_now;
|
|
|
|
|
queue[queue_read].len -= play_now;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*size = 0; /* end of data */
|
|
|
|
|
is_playing = false;
|
|
|
|
|
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-29 08:19:47 +00:00
|
|
|
|
/* one silent bitswapped mp3 frame (22kHz), without bit reservoir */
|
|
|
|
|
static const unsigned char silent_frame[] = {
|
|
|
|
|
0xFF,0xCF,0x08,0x23,0x00,0x00,0x00,0xC0,0x12,0x80,0x01,0x00,0x00,
|
|
|
|
|
0x32,0x82,0xB2,0xA2,0xCC,0x74,0x9C,0xCC,0xAA,0xAA,0xAA,0xAA,0xAA,
|
|
|
|
|
};
|
2004-03-21 17:45:45 +00:00
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
|
mp3_play_pause(false); /* pause */
|
|
|
|
|
|
2004-03-21 17:45:45 +00:00
|
|
|
|
if (!is_playing) /* has ended anyway */
|
|
|
|
|
return 0;
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
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-03-23 11:49:09 +00:00
|
|
|
|
/* Find the next frame boundary */
|
2004-03-21 17:45:45 +00:00
|
|
|
|
while (search < end) /* search the remaining data */
|
|
|
|
|
{
|
2004-03-29 08:19:47 +00:00
|
|
|
|
if (*search++ != 0xFF) /* search for frame sync byte */
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* look at the (bitswapped) 2nd byte of header candidate */
|
|
|
|
|
if ((*search & 0x07) == 0x07 /* rest of frame sync */
|
|
|
|
|
&& (*search & 0x18) != 0x10 /* version != reserved */
|
|
|
|
|
&& (*search & 0x60) != 0x00) /* layer != reserved */
|
2004-03-21 17:45:45 +00:00
|
|
|
|
{
|
2004-03-29 08:19:47 +00:00
|
|
|
|
search--; /* back to the sync byte */
|
|
|
|
|
break; /* From looking at the first 2 bytes, this is a header. */
|
|
|
|
|
/* this is not a sufficient condition to find header,
|
|
|
|
|
may give "false alert" (end too early), but a start */
|
2004-03-21 17:45:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queue_write = queue_read; /* reset the queue */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
is_playing = false;
|
|
|
|
|
|
2004-03-21 17:45:45 +00:00
|
|
|
|
/* play old data until the frame end, to keep the MAS in sync */
|
|
|
|
|
if (search-pos)
|
|
|
|
|
queue_clip(pos, search-pos, true);
|
|
|
|
|
|
|
|
|
|
/* If the voice clips contain dependent frames (currently they don't),
|
|
|
|
|
it may be a good idea to insert an independent dummy frame here. */
|
2004-03-29 08:19:47 +00:00
|
|
|
|
queue_clip((unsigned char*)silent_frame, sizeof(silent_frame), true);
|
2004-03-21 17:45:45 +00:00
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* schedule a clip, at the end or discard the existing queue */
|
|
|
|
|
static int queue_clip(unsigned char* buf, int size, bool enqueue)
|
|
|
|
|
{
|
|
|
|
|
if (!enqueue)
|
|
|
|
|
shutup(); /* cut off all the pending stuff */
|
|
|
|
|
|
|
|
|
|
queue[queue_write].buf = buf;
|
|
|
|
|
queue[queue_write].len = size;
|
|
|
|
|
|
|
|
|
|
/* FixMe: make this IRQ-safe */
|
|
|
|
|
|
|
|
|
|
if (!is_playing)
|
|
|
|
|
{ /* queue empty, we have to do the initial start */
|
|
|
|
|
int size_now = MIN(size, 0xFFFF); /* DMA can do no more */
|
|
|
|
|
is_playing = true;
|
|
|
|
|
mp3_play_data(buf, size_now, mp3_callback);
|
|
|
|
|
mp3_play_pause(true); /* kickoff audio */
|
|
|
|
|
queue[queue_write].buf += size_now;
|
|
|
|
|
queue[queue_write].len -= size_now;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queue_write++;
|
|
|
|
|
if (queue_write >= QUEUE_SIZE)
|
|
|
|
|
queue_write = 0;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************** Public implementation *****************/
|
|
|
|
|
|
|
|
|
|
void talk_init(void)
|
|
|
|
|
{
|
2004-03-20 16:49:58 +00:00
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
|
|
fd = open(voicefont_file, O_RDONLY);
|
|
|
|
|
if (fd >= 0) /* success */
|
|
|
|
|
{
|
|
|
|
|
close(fd);
|
|
|
|
|
has_voicefont = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
has_voicefont = false; /* no voice file available */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
talk_buffer_steal(); /* abuse this for most of our inits */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
queue_write = queue_read = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* somebody else claims the mp3 buffer, e.g. for regular play/record */
|
|
|
|
|
int talk_buffer_steal(void)
|
|
|
|
|
{
|
|
|
|
|
p_voicefont = NULL; /* indicate no voicefont (trashed) */
|
|
|
|
|
p_thumbnail = mp3buf; /* whole space for thumbnail */
|
|
|
|
|
size_for_thumbnail = mp3end - mp3buf;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* play a voice ID from voicefont */
|
|
|
|
|
int talk_id(int id, bool enqueue)
|
|
|
|
|
{
|
|
|
|
|
int clipsize;
|
|
|
|
|
unsigned char* clipbuf;
|
|
|
|
|
int unit;
|
|
|
|
|
|
|
|
|
|
if (mpeg_status()) /* busy, buffer in use */
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if (p_voicefont == NULL && has_voicefont)
|
|
|
|
|
load_voicefont(); /* reload needed */
|
|
|
|
|
|
|
|
|
|
if (p_voicefont == NULL) /* still no voices? */
|
|
|
|
|
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 */
|
|
|
|
|
unit = ((unsigned)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 */
|
|
|
|
|
//splash(200, true,"unit=%d", unit);
|
|
|
|
|
id = (unsigned)id << (32-UNIT_SHIFT);
|
|
|
|
|
id >>= (32-UNIT_SHIFT);
|
|
|
|
|
talk_value(id, unit, enqueue); /* speak it */
|
|
|
|
|
return 0; /* and stop, end of special case */
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-03 20:52:24 +00:00
|
|
|
|
if (id > VOICEONLY_DELIMITER)
|
|
|
|
|
{ /* voice-only entries use the second part of the table */
|
|
|
|
|
id -= VOICEONLY_DELIMITER + 1;
|
|
|
|
|
if (id >= p_voicefont->id2_max)
|
|
|
|
|
return -1; /* must be newer than we have */
|
|
|
|
|
id += p_voicefont->id1_max; /* table 2 is behind table 1 */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ /* normal use of the first table */
|
|
|
|
|
if (id >= p_voicefont->id1_max)
|
|
|
|
|
return -1; /* must be newer than we have */
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
|
clipsize = p_voicefont->index[id].size;
|
|
|
|
|
if (clipsize == 0) /* clip not included in voicefont */
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
clipbuf = mp3buf + p_voicefont->index[id].offset;
|
|
|
|
|
|
|
|
|
|
queue_clip(clipbuf, clipsize, enqueue);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* play a thumbnail from file */
|
|
|
|
|
int talk_file(char* filename, bool enqueue)
|
|
|
|
|
{
|
|
|
|
|
int fd;
|
|
|
|
|
int size;
|
2004-03-27 00:11:01 +00:00
|
|
|
|
struct mp3entry info;
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
|
|
|
|
if (mpeg_status()) /* busy, buffer in use */
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if (p_thumbnail == NULL || size_for_thumbnail <= 0)
|
|
|
|
|
return -1;
|
|
|
|
|
|
2004-03-27 00:11:01 +00:00
|
|
|
|
if(mp3info(&info, filename)) /* use this to find real start */
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
bitswap(p_thumbnail, size);
|
|
|
|
|
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) */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
int talk_number(int n, bool enqueue)
|
|
|
|
|
{
|
2004-03-20 16:49:58 +00:00
|
|
|
|
int level = 0; /* mille count */
|
|
|
|
|
int mil = 1000000000; /* highest possible "-illion" */
|
2004-03-19 22:15:53 +00:00
|
|
|
|
|
2004-03-22 12:34:06 +00:00
|
|
|
|
if (mpeg_status()) /* busy, buffer in use */
|
|
|
|
|
return -1;
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int talk_value(int n, int unit, bool enqueue)
|
|
|
|
|
{
|
|
|
|
|
int unit_id;
|
|
|
|
|
const int unit_voiced[] =
|
|
|
|
|
{ /* 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
|
|
|
|
};
|
|
|
|
|
|
2004-03-22 12:34:06 +00:00
|
|
|
|
if (mpeg_status()) /* busy, buffer in use */
|
|
|
|
|
return -1;
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|