From 5b76936a44de3c7ecd568300f26b5e6421901285 Mon Sep 17 00:00:00 2001 From: Nils Wallménius Date: Mon, 6 Aug 2007 13:08:36 +0000 Subject: Accept FS#6159 'Add voice to roughly 100 splash screens and yes-no menus' by Stephane Doyon with some minor tweaks by me. Rerun 'configure' and do a 'make clean' before rebuilding your voice files. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14213 a1c6a512-1295-4272-9138-f99709370657 --- apps/talk.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'apps/talk.c') diff --git a/apps/talk.c b/apps/talk.c index 89ab3901c4..3b7ab2a03f 100644 --- a/apps/talk.c +++ b/apps/talk.c @@ -117,6 +117,8 @@ static long size_for_thumbnail; /* leftover buffer size for it */ static struct voicefile* p_voicefile; /* loaded voicefile */ static bool has_voicefile; /* a voicefile file is present */ static struct queue_entry queue[QUEUE_SIZE]; /* queue of scheduled clips */ +/* enqueue next utterance even if enqueue is false. */ +static bool force_enqueue_next; static int queue_write; /* write index of queue, by application */ static int queue_read; /* read index of queue, by ISR context */ static int sent; /* how many bytes handed over to playback, owned by ISR */ @@ -134,7 +136,6 @@ static int talk_menu_disable; /* if non-zero, temporarily disable voice UI (not static void load_voicefile(void); static void mp3_callback(unsigned char** start, size_t* size); -static int shutup(void); static int queue_clip(unsigned char* buf, long size, bool enqueue); static int open_voicefile(void); static unsigned char* get_clip(long id, long* p_size); @@ -267,6 +268,13 @@ load_err: } +/* Are more voice clips queued and waiting? */ +bool is_voice_queued() +{ + return !!QUEUE_LEVEL; +} + + /* called in ISR context if mp3 data got consumed */ static void mp3_callback(unsigned char** start, size_t* size) { @@ -321,7 +329,7 @@ re_check: } /* stop the playback and the pending clips */ -static int shutup(void) +static int do_shutup(void) { #if CONFIG_CODEC != SWCODEC unsigned char* pos; @@ -387,6 +395,13 @@ static int shutup(void) return 0; } +/* Shutup the voice, except if force_enqueue_next is set. */ +static int shutup(void) +{ + if (!force_enqueue_next) + return do_shutup(); + return 0; +} /* schedule a clip, at the end or discard the existing queue */ static int queue_clip(unsigned char* buf, long size, bool enqueue) @@ -395,6 +410,9 @@ static int queue_clip(unsigned char* buf, long size, bool enqueue) if (!enqueue) shutup(); /* cut off all the pending stuff */ + /* Something is being enqueued, force_enqueue_next override is no + longer in effect. */ + force_enqueue_next = false; if (!size) return 0; /* safety check */ @@ -617,6 +635,26 @@ int talk_id(long id, bool enqueue) return 0; } +/* Speaks zero or more IDs (from an array). */ +int talk_idarray(long *ids, bool enqueue) +{ + int r; + if(!ids) + return 0; + while(*ids != TALK_FINAL_ID) + { + if((r = talk_id(*ids++, enqueue)) <0) + return r; + enqueue = true; + } + return 0; +} + +/* Make sure the current utterance is not interrupted by the next one. */ +void talk_force_enqueue_next(void) +{ + force_enqueue_next = true; +} /* play a thumbnail from file */ int talk_file(const char* filename, bool enqueue) -- cgit v1.2.3