FS#7994 - Rename talk.c API, make talk_disable() affect all talking (not just menus), hopefully save some space.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15206 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Steve Bavin 2007-10-19 15:31:42 +00:00
parent 877ea486ba
commit 32a9575130
22 changed files with 161 additions and 186 deletions

View file

@ -44,7 +44,7 @@
static void speak_time(int hours, int minutes, bool speak_hours) static void speak_time(int hours, int minutes, bool speak_hours)
{ {
if (talk_menus_enabled()){ if (global_settings.talk_menu){
if(speak_hours) { if(speak_hours) {
talk_value(hours, UNIT_HOUR, false); talk_value(hours, UNIT_HOUR, false);
talk_value(minutes, UNIT_MIN, true); talk_value(minutes, UNIT_MIN, true);
@ -86,7 +86,7 @@ bool alarm_screen(void)
screens[i].puts(0, 3, str(LANG_ALARM_MOD_KEYS)); screens[i].puts(0, 3, str(LANG_ALARM_MOD_KEYS));
} }
/* Talk when entering the wakeup screen */ /* Talk when entering the wakeup screen */
if (talk_menus_enabled()) if (global_settings.talk_menu)
{ {
talk_value(h, UNIT_HOUR, true); talk_value(h, UNIT_HOUR, true);
talk_value(m, UNIT_MIN, true); talk_value(m, UNIT_MIN, true);
@ -113,7 +113,7 @@ bool alarm_screen(void)
rtc_init(); rtc_init();
rtc_set_alarm(h,m); rtc_set_alarm(h,m);
rtc_enable_alarm(true); rtc_enable_alarm(true);
if (talk_menus_enabled()) if (global_settings.talk_menu)
{ {
talk_id(LANG_ALARM_MOD_TIME_TO_GO, true); talk_id(LANG_ALARM_MOD_TIME_TO_GO, true);
talk_value(togo / 60, UNIT_HOUR, true); talk_value(togo / 60, UNIT_HOUR, true);
@ -164,7 +164,7 @@ bool alarm_screen(void)
case ACTION_STD_NEXTREPEAT: case ACTION_STD_NEXTREPEAT:
h = (h+1) % 24; h = (h+1) % 24;
if (talk_menus_enabled()) if (global_settings.talk_menu)
talk_value(h, UNIT_HOUR, false); talk_value(h, UNIT_HOUR, false);
break; break;
@ -173,7 +173,7 @@ bool alarm_screen(void)
case ACTION_STD_PREVREPEAT: case ACTION_STD_PREVREPEAT:
h = (h+23) % 24; h = (h+23) % 24;
if (talk_menus_enabled()) if (global_settings.talk_menu)
talk_value(h, UNIT_HOUR, false); talk_value(h, UNIT_HOUR, false);
break; break;

View file

@ -667,7 +667,7 @@ static char* select_bookmark(const char* bookmark_file_name, bool show_dont_resu
item--; item--;
} }
if (item != last_item && talk_menus_enabled()) if (item != last_item && global_settings.talk_menu)
{ {
last_item = item; last_item = item;

View file

@ -133,7 +133,7 @@ static char *option_get_valuestring(struct settings_list *setting,
static void option_talk(struct settings_list *setting, int temp_var) static void option_talk(struct settings_list *setting, int temp_var)
{ {
if (!talk_menus_enabled()) if (!global_settings.talk_menu)
return; return;
if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING)
{ {

View file

@ -145,7 +145,7 @@ enum yesno_res gui_syncyesno_run(struct text_message * main_message,
while (result==-1) while (result==-1)
{ {
/* Repeat the question every 5secs (more or less) */ /* Repeat the question every 5secs (more or less) */
if (talk_menus_enabled() if (global_settings.talk_menu
&& (talked_tick==0 || TIME_AFTER(current_tick, talked_tick+HZ*5))) && (talked_tick==0 || TIME_AFTER(current_tick, talked_tick+HZ*5)))
{ {
talked_tick = current_tick; talked_tick = current_tick;
@ -175,7 +175,7 @@ enum yesno_res gui_syncyesno_run(struct text_message * main_message,
FOR_NB_SCREENS(i) FOR_NB_SCREENS(i)
result_displayed=gui_yesno_draw_result(&(yn[i]), result); result_displayed=gui_yesno_draw_result(&(yn[i]), result);
if (talk_menus_enabled()) if (global_settings.talk_menu)
{ {
talk_idarray(voice_ids, false); talk_idarray(voice_ids, false);
talk_force_enqueue_next(); talk_force_enqueue_next();

View file

@ -225,7 +225,7 @@ static void init_tagcache(void)
/* hwcodec can't use voice here, as the database commit /* hwcodec can't use voice here, as the database commit
* uses the audio buffer. */ * uses the audio buffer. */
static long talked_tick = 0; static long talked_tick = 0;
if(talk_menus_enabled() if(global_settings.talk_menu
&& (talked_tick == 0 && (talked_tick == 0
|| TIME_AFTER(current_tick, talked_tick+7*HZ))) || TIME_AFTER(current_tick, talked_tick+7*HZ)))
{ {

View file

@ -225,7 +225,7 @@ static void talk_menu_item(const struct menu_item_ex *menu,
unsigned char *str; unsigned char *str;
int sel; int sel;
if (talk_menus_enabled()) if (global_settings.talk_menu)
{ {
sel = get_menu_selection(gui_synclist_get_sel_pos(lists),menu); sel = get_menu_selection(gui_synclist_get_sel_pos(lists),menu);
if ((menu->flags&MENU_TYPE_MASK) == MT_MENU) if ((menu->flags&MENU_TYPE_MASK) == MT_MENU)

View file

@ -161,7 +161,7 @@ static bool show_info(void)
size2 = 0; size2 = 0;
#endif #endif
if (talk_menus_enabled()) if (global_settings.talk_menu)
{ {
/* say whatever is reasonable, no real connection to the screen */ /* say whatever is reasonable, no real connection to the screen */
bool enqueue = false; /* enqueue all but the first */ bool enqueue = false; /* enqueue all but the first */

View file

@ -685,7 +685,7 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
audio_close_recording(); audio_close_recording();
#endif #endif
if(talk_menus_enabled()) if(global_settings.talk_menu)
{ {
bool enqueue = false; bool enqueue = false;
if(msg_id != -1) if(msg_id != -1)

View file

@ -677,7 +677,7 @@ void audio_play(long offset)
#ifdef PLAYBACK_VOICE #ifdef PLAYBACK_VOICE
/* Truncate any existing voice output so we don't have spelling /* Truncate any existing voice output so we don't have spelling
* etc. over the first part of the played track */ * etc. over the first part of the played track */
do_shutup(); talk_force_shutup();
#endif #endif
/* Start playback */ /* Start playback */
@ -960,7 +960,7 @@ static void voice_stop(void)
if (!voice_codec_loaded) if (!voice_codec_loaded)
return; return;
do_shutup(); talk_force_shutup();
/* Loop until voice empties it's queue, stops and picks up on the new /* Loop until voice empties it's queue, stops and picks up on the new
track; the voice thread must be stopped and waiting for messages track; the voice thread must be stopped and waiting for messages

View file

@ -74,7 +74,7 @@ static unsigned short *kbd_setupkeys(int page, int* len)
/* helper function to spell a char if voice UI is enabled */ /* helper function to spell a char if voice UI is enabled */
static void kbd_spellchar(char c) static void kbd_spellchar(char c)
{ {
if (talk_menus_enabled()) /* voice UI? */ if (global_settings.talk_menu) /* voice UI? */
{ {
unsigned char tmp[5]; unsigned char tmp[5];
/* store char to pass to talk_spell */ /* store char to pass to talk_spell */
@ -90,7 +90,7 @@ static void kbd_spellchar(char c)
static void say_edit(void) static void say_edit(void)
{ {
if (talk_menus_enabled()) if (global_settings.talk_menu)
talk_id(VOICE_EDIT, false); talk_id(VOICE_EDIT, false);
} }
@ -112,7 +112,7 @@ int kbd_input(char* text, int buflen)
editpos = utf8length(text); editpos = utf8length(text);
if (talk_menus_enabled()) /* voice UI? */ if (global_settings.talk_menu) /* voice UI? */
talk_spell(text, true); /* spell initial text */ talk_spell(text, true); /* spell initial text */
while (!done) while (!done)
@ -284,7 +284,7 @@ int kbd_input(char* text, int buflen)
editpos++; editpos++;
} }
} }
if (talk_menus_enabled()) /* voice UI? */ if (global_settings.talk_menu) /* voice UI? */
talk_spell(text, false); /* speak revised text */ talk_spell(text, false); /* speak revised text */
break; break;

View file

@ -1664,7 +1664,7 @@ static void display_playlist_count(int count, const unsigned char *fmt,
{ {
static long talked_tick = 0; static long talked_tick = 0;
long id = P2ID(fmt); long id = P2ID(fmt);
if(talk_menus_enabled() && id>=0) if(global_settings.talk_menu && id>=0)
{ {
if(final || (count && (talked_tick == 0 if(final || (count && (talked_tick == 0
|| TIME_AFTER(current_tick, talked_tick+5*HZ)))) || TIME_AFTER(current_tick, talked_tick+5*HZ))))

View file

@ -468,8 +468,7 @@ static const struct plugin_api rockbox_api = {
#endif #endif
&global_settings, &global_settings,
&global_status, &global_status,
talk_disable_menus, talk_disable,
talk_enable_menus,
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
codec_load_file, codec_load_file,
get_codec_filename, get_codec_filename,

View file

@ -112,12 +112,12 @@
#define PLUGIN_MAGIC 0x526F634B /* RocK */ #define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */ /* increase this every time the api struct changes */
#define PLUGIN_API_VERSION 83 #define PLUGIN_API_VERSION 84
/* update this to latest version if a change to the api struct breaks /* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */ new function which are "waiting" at the end of the function table) */
#define PLUGIN_MIN_API_VERSION 83 #define PLUGIN_MIN_API_VERSION 84
/* plugin return codes */ /* plugin return codes */
enum plugin_status { enum plugin_status {
@ -579,8 +579,7 @@ struct plugin_api {
#endif #endif
struct user_settings* global_settings; struct user_settings* global_settings;
struct system_status *global_status; struct system_status *global_status;
void (*talk_disable_menus)(void); void (*talk_disable)(bool disable);
void (*talk_enable_menus)(void);
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
int (*codec_load_file)(const char* codec, struct codec_api *api); int (*codec_load_file)(const char* codec, struct codec_api *api);
const char *(*get_codec_filename)(int cod_spec); const char *(*get_codec_filename)(int cod_spec);

View file

@ -1170,7 +1170,7 @@ static int button_loop(void)
str_send_msg(&video_str, STREAM_QUIT, 0); str_send_msg(&video_str, STREAM_QUIT, 0);
audio_str.status = STREAM_STOPPED; audio_str.status = STREAM_STOPPED;
} }
} }
} }
quit: quit:
return audio_str.status; return audio_str.status;
@ -2227,6 +2227,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
api->splash(HZ*2, "No File"); api->splash(HZ*2, "No File");
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
api->talk_disable(true);
/* Initialize IRAM - stops audio and voice as well */ /* Initialize IRAM - stops audio and voice as well */
PLUGIN_IRAM_INIT(api) PLUGIN_IRAM_INIT(api)
@ -2253,6 +2254,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
audiosize -= graysize; audiosize -= graysize;
if (grayscales < 33 || audiosize <= 0) if (grayscales < 33 || audiosize <= 0)
{ {
rb->talk_disable(false);
rb->splash(HZ, "gray buf error"); rb->splash(HZ, "gray buf error");
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
@ -2261,7 +2263,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
/* Initialise our malloc buffer */ /* Initialise our malloc buffer */
audiosize = mpeg_alloc_init(audiobuf,audiosize, LIBMPEG2BUFFER_SIZE); audiosize = mpeg_alloc_init(audiobuf,audiosize, LIBMPEG2BUFFER_SIZE);
if (audiosize == 0) if (audiosize == 0)
{
rb->talk_disable(false);
return PLUGIN_ERROR; return PLUGIN_ERROR;
}
/* Set disk pointers to NULL */ /* Set disk pointers to NULL */
disk_buf_end = disk_buf_start = NULL; disk_buf_end = disk_buf_start = NULL;
@ -2275,13 +2280,21 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
disk_buf_start = mpeg_malloc(disk_buf_size,-1); disk_buf_start = mpeg_malloc(disk_buf_size,-1);
if (disk_buf_start == NULL) if (disk_buf_start == NULL)
{
rb->talk_disable(false);
return PLUGIN_ERROR; return PLUGIN_ERROR;
}
if (!init_mpabuf()) if (!init_mpabuf())
{
rb->talk_disable(false);
return PLUGIN_ERROR; return PLUGIN_ERROR;
}
if (!init_pcmbuf()) if (!init_pcmbuf())
{
rb->talk_disable(false);
return PLUGIN_ERROR; return PLUGIN_ERROR;
}
/* The remaining buffer is for use by libmpeg2 */ /* The remaining buffer is for use by libmpeg2 */
@ -2290,6 +2303,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
if (in_file < 0){ if (in_file < 0){
DEBUGF("Could not open %s\n",(char*)parameter); DEBUGF("Could not open %s\n",(char*)parameter);
rb->talk_disable(false);
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
filename = (char*)parameter; filename = (char*)parameter;
@ -2322,6 +2336,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
switch (result) switch (result)
{ {
case MPEG_START_QUIT: case MPEG_START_QUIT:
rb->talk_disable(false);
return 0; return 0;
default: default:
start_time = settings.resume_time; start_time = settings.resume_time;
@ -2336,7 +2351,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
/* Turn off backlight timeout */ /* Turn off backlight timeout */
backlight_force_on(rb); /* backlight control in lib/helper.c */ backlight_force_on(rb); /* backlight control in lib/helper.c */
rb->talk_disable_menus();
#ifdef HAVE_ADJUSTABLE_CPU_FREQ #ifdef HAVE_ADJUSTABLE_CPU_FREQ
rb->cpu_boost(true); rb->cpu_boost(true);
@ -2465,7 +2479,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
rb->splash(30,"buffer fill error"); rb->splash(30,"buffer fill error");
} }
bytes_to_read -= n; bytes_to_read -= n;
file_remaining -= n; file_remaining -= n;
@ -2531,7 +2544,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
/* Turn on backlight timeout (revert to settings) */ /* Turn on backlight timeout (revert to settings) */
backlight_use_settings(rb); /* backlight control in lib/helper.c */ backlight_use_settings(rb); /* backlight control in lib/helper.c */
rb->talk_enable_menus(); rb->talk_disable(false);
return status; return status;
} }

View file

@ -191,7 +191,7 @@ int load_kbd(unsigned char* filename)
/* helper function to spell a char if voice UI is enabled */ /* helper function to spell a char if voice UI is enabled */
static void kbd_spellchar(unsigned short c) static void kbd_spellchar(unsigned short c)
{ {
if (talk_menus_enabled()) /* voice UI? */ if (global_settings.talk_menu) /* voice UI? */
{ {
unsigned char tmp[5]; unsigned char tmp[5];
/* store char to pass to talk_spell */ /* store char to pass to talk_spell */
@ -208,7 +208,7 @@ static void kbd_spellchar(unsigned short c)
#ifdef KBD_MODES #ifdef KBD_MODES
static void say_edit(void) static void say_edit(void)
{ {
if(talk_menus_enabled()) if(global_settings.talk_menu)
talk_id(VOICE_EDIT, false); talk_id(VOICE_EDIT, false);
} }
#endif #endif
@ -527,7 +527,7 @@ int kbd_input(char* text, int buflen)
/* Initial edit position is after last character */ /* Initial edit position is after last character */
editpos = utf8length(text); editpos = utf8length(text);
if (talk_menus_enabled()) /* voice UI? */ if (global_settings.talk_menu) /* voice UI? */
talk_spell(text, true); /* spell initial text */ talk_spell(text, true); /* spell initial text */
@ -832,7 +832,7 @@ int kbd_input(char* text, int buflen)
kbd_spellchar(text[c]); kbd_spellchar(text[c]);
} }
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
else if (talk_menus_enabled()) else if (global_settings.talk_menu)
pcmbuf_beep(1000, 150, 1500); pcmbuf_beep(1000, 150, 1500);
#endif #endif
} }
@ -877,7 +877,7 @@ int kbd_input(char* text, int buflen)
kbd_spellchar(text[c]); kbd_spellchar(text[c]);
} }
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
else if (talk_menus_enabled()) else if (global_settings.talk_menu)
pcmbuf_beep(1000, 150, 1500); pcmbuf_beep(1000, 150, 1500);
#endif #endif
} }
@ -1124,7 +1124,7 @@ int kbd_input(char* text, int buflen)
kbd_inschar(text, buflen, &editpos, ch); kbd_inschar(text, buflen, &editpos, ch);
} }
if (talk_menus_enabled()) /* voice UI? */ if (global_settings.talk_menu) /* voice UI? */
talk_spell(text, false); talk_spell(text, false);
/* speak revised text */ /* speak revised text */
@ -1153,7 +1153,7 @@ int kbd_input(char* text, int buflen)
kbd_inschar(text, buflen, &editpos, ch); kbd_inschar(text, buflen, &editpos, ch);
} }
if (talk_menus_enabled()) /* voice UI? */ if (global_settings.talk_menu) /* voice UI? */
talk_spell(text, false); /* speak revised text */ talk_spell(text, false); /* speak revised text */
break; break;
@ -1166,7 +1166,7 @@ int kbd_input(char* text, int buflen)
kbd_spellchar(text[c]); kbd_spellchar(text[c]);
} }
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
else if (talk_menus_enabled()) else if (global_settings.talk_menu)
pcmbuf_beep(1000, 150, 1500); pcmbuf_beep(1000, 150, 1500);
#endif #endif
break; break;
@ -1180,7 +1180,7 @@ int kbd_input(char* text, int buflen)
kbd_spellchar(text[c]); kbd_spellchar(text[c]);
} }
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
else if (talk_menus_enabled()) else if (global_settings.talk_menu)
pcmbuf_beep(1000, 150, 1500); pcmbuf_beep(1000, 150, 1500);
#endif #endif
break; break;
@ -1212,7 +1212,7 @@ int kbd_input(char* text, int buflen)
param[l].hangul = false; param[l].hangul = false;
kbd_inschar(text, buflen, &editpos, morse_alphabets[j]); kbd_inschar(text, buflen, &editpos, morse_alphabets[j]);
if (talk_menus_enabled()) /* voice UI? */ if (global_settings.talk_menu) /* voice UI? */
talk_spell(text, false); /* speak revised text */ talk_spell(text, false); /* speak revised text */
} }
#endif /* KBD_MORSE_INPUT */ #endif /* KBD_MORSE_INPUT */

View file

@ -889,7 +889,7 @@ bool recording_screen(bool no_source)
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
/* recording_menu gets messed up: so prevent manus talking */ /* recording_menu gets messed up: so prevent manus talking */
talk_disable_menus(); talk_disable(true);
/* audio_init_recording stops anything playing when it takes the audio /* audio_init_recording stops anything playing when it takes the audio
buffer */ buffer */
#else #else
@ -1873,8 +1873,8 @@ bool recording_screen(bool no_source)
/* Go back to playback mode */ /* Go back to playback mode */
rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
/* restore talk_menu setting */ /* restore talking */
talk_enable_menus(); talk_disable(false);
#else /* !SWCODEC */ #else /* !SWCODEC */
audio_init_playback(); audio_init_playback();
#endif /* CONFIG_CODEC == SWCODEC */ #endif /* CONFIG_CODEC == SWCODEC */

View file

@ -160,7 +160,7 @@ static int browser(void* param)
/* Display building progress */ /* Display building progress */
static long talked_tick = 0; static long talked_tick = 0;
if(talk_menus_enabled() && if(global_settings.talk_menu &&
(talked_tick == 0 (talked_tick == 0
|| TIME_AFTER(current_tick, talked_tick+7*HZ))) || TIME_AFTER(current_tick, talked_tick+7*HZ)))
{ {
@ -238,7 +238,7 @@ static int wpsscrn(void* param)
(void)param; (void)param;
if (audio_status()) if (audio_status())
{ {
shutup(); talk_shutup();
ret_val = gui_wps_show(); ret_val = gui_wps_show();
} }
else if ( global_status.resume_index != -1 ) else if ( global_status.resume_index != -1 )

View file

@ -158,7 +158,7 @@ int mmc_remove_request(void)
FOR_NB_SCREENS(i) FOR_NB_SCREENS(i)
screens[i].clear_display(); screens[i].clear_display();
gui_syncsplash(1, str(LANG_REMOVE_MMC)); gui_syncsplash(1, str(LANG_REMOVE_MMC));
if (talk_menus_enabled()) if (global_settings.talk_menu)
talk_id(LANG_REMOVE_MMC, false); talk_id(LANG_REMOVE_MMC, false);
while (1) while (1)
@ -822,7 +822,7 @@ static void say_time(int cursorpos, const struct tm *tm)
static const int unit[] = { UNIT_HOUR, UNIT_MIN, UNIT_SEC, 0, 0, 0 }; static const int unit[] = { UNIT_HOUR, UNIT_MIN, UNIT_SEC, 0, 0, 0 };
int value = 0; int value = 0;
if (!talk_menus_enabled()) if (!global_settings.talk_menu)
return; return;
switch(cursorpos) switch(cursorpos)

View file

@ -949,7 +949,7 @@ const struct settings_list* find_setting(void* variable, int *id)
void talk_setting(void *global_settings_variable) void talk_setting(void *global_settings_variable)
{ {
const struct settings_list *setting; const struct settings_list *setting;
if (!talk_menus_enabled()) if (!global_settings.talk_menu)
return; return;
setting = find_setting(global_settings_variable, NULL); setting = find_setting(global_settings_variable, NULL);
if (setting == NULL) if (setting == NULL)

View file

@ -80,10 +80,6 @@ const char* const file_thumbnail_ext = ".talk";
#define MAX_THUMBNAIL_BUFSIZE 0x10000 #define MAX_THUMBNAIL_BUFSIZE 0x10000
#endif #endif
#ifndef SIMULATOR
extern bool audio_is_initialized;
#endif
/***************** Data types *****************/ /***************** Data types *****************/
struct clip_entry /* one entry of the index table */ struct clip_entry /* one entry of the index table */
@ -118,8 +114,7 @@ static long size_for_thumbnail; /* leftover buffer size for it */
static struct voicefile* p_voicefile; /* loaded voicefile */ static struct voicefile* p_voicefile; /* loaded voicefile */
static bool has_voicefile; /* a voicefile file is present */ static bool has_voicefile; /* a voicefile file is present */
static struct queue_entry queue[QUEUE_SIZE]; /* queue of scheduled clips */ static struct queue_entry queue[QUEUE_SIZE]; /* queue of scheduled clips */
/* enqueue next utterance even if enqueue is false. */ static bool force_enqueue_next; /* 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_write; /* write index of queue, by application */
static int queue_read; /* read index of queue, by ISR context */ static int queue_read; /* read index of queue, by ISR context */
static int sent; /* how many bytes handed over to playback, owned by ISR */ static int sent; /* how many bytes handed over to playback, owned by ISR */
@ -131,16 +126,8 @@ static unsigned char* p_lastclip; /* address of latest clip, for silence add */
static unsigned long voicefile_size = 0; /* size of the loaded voice file */ static unsigned long voicefile_size = 0; /* size of the loaded voice file */
static unsigned char last_lang[MAX_FILENAME+1]; /* name of last used lang file (in talk_init) */ static unsigned char last_lang[MAX_FILENAME+1]; /* name of last used lang file (in talk_init) */
static bool talk_initialized; /* true if talk_init has been called */ static bool talk_initialized; /* true if talk_init has been called */
static int talk_menu_disable; /* if non-zero, temporarily disable voice UI (not saved) */ static int talk_temp_disable_count; /* if positive, temporarily disable voice UI (not saved) */
/***************** Private prototypes *****************/
static void load_voicefile(void);
static void mp3_callback(unsigned char** start, size_t* size);
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);
int shutup(void); /* Interrupt voice, as when enqueue is false */
/***************** Private implementation *****************/ /***************** Private implementation *****************/
@ -161,6 +148,50 @@ static int open_voicefile(void)
} }
/* fetch a clip from the voice file */
static unsigned char* get_clip(long id, long* p_size)
{
long clipsize;
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;
clipbuf = (unsigned char *) p_voicefile + p_voicefile->index[id].offset;
#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;
}
/* load the voice file into the mp3 buffer */ /* load the voice file into the mp3 buffer */
static void load_voicefile(void) static void load_voicefile(void)
{ {
@ -252,7 +283,7 @@ load_err:
/* Are more voice clips queued and waiting? */ /* Are more voice clips queued and waiting? */
bool is_voice_queued() bool is_voice_queued()
{ {
return !!QUEUE_LEVEL; return (QUEUE_LEVEL != 0);
} }
@ -280,7 +311,7 @@ static void mp3_callback(unsigned char** start, size_t* size)
re_check: re_check:
if (QUEUE_LEVEL) /* queue is not empty? */ if (QUEUE_LEVEL != 0) /* queue is not empty? */
{ /* start next clip */ { /* start next clip */
#if CONFIG_CODEC != SWCODEC #if CONFIG_CODEC != SWCODEC
sent = MIN(queue[queue_read].len, 0xFFFF); sent = MIN(queue[queue_read].len, 0xFFFF);
@ -309,26 +340,22 @@ re_check:
} }
} }
/***************** Public routines *****************/
/* stop the playback and the pending clips */ /* stop the playback and the pending clips */
int do_shutup(void) void talk_force_shutup(void)
{ {
/* Most of this is MAS only */
#if CONFIG_CODEC != SWCODEC #if CONFIG_CODEC != SWCODEC
unsigned char* pos; unsigned char* pos;
unsigned char* search; unsigned char* search;
unsigned char* end; unsigned char* end;
#endif
if (QUEUE_LEVEL == 0) /* has ended anyway */ if (QUEUE_LEVEL == 0) /* has ended anyway */
{ return;
#if CONFIG_CODEC == SWCODEC
mp3_play_stop();
#endif
return 0;
}
#if CONFIG_CODEC != SWCODEC
#if CONFIG_CPU == SH7034 #if CONFIG_CPU == SH7034
CHCR3 &= ~0x0001; /* disable the DMA (and therefore the interrupt also) */ CHCR3 &= ~0x0001; /* disable the DMA (and therefore the interrupt also) */
#endif #endif /* CONFIG_CPU == SH7034 */
/* search next frame boundary and continue up to there */ /* search next frame boundary and continue up to there */
pos = search = mp3_get_pos(); pos = search = mp3_get_pos();
end = queue[queue_read].buf + queue[queue_read].len; end = queue[queue_read].buf + queue[queue_read].len;
@ -362,41 +389,38 @@ int do_shutup(void)
#if CONFIG_CPU == SH7034 #if CONFIG_CPU == SH7034
DTCR3 = sent; /* let the DMA finish this frame */ DTCR3 = sent; /* let the DMA finish this frame */
CHCR3 |= 0x0001; /* re-enable DMA */ CHCR3 |= 0x0001; /* re-enable DMA */
#endif #endif /* CONFIG_CPU == SH7034 */
return 0; return;
} }
} }
#endif #endif /* CONFIG_CODEC != SWCODEC */
/* nothing to do, was frame boundary or not our clip */ /* Either SWCODEC, or MAS had nothing to do (was frame boundary or not our clip) */
mp3_play_stop(); mp3_play_stop();
queue_write = queue_read = 0; /* reset the queue */ queue_write = queue_read = 0; /* reset the queue */
return;
return 0;
} }
/* Shutup the voice, except if force_enqueue_next is set. */ /* Shutup the voice, except if force_enqueue_next is set. */
int shutup(void) void talk_shutup(void)
{ {
if (!force_enqueue_next) if (!force_enqueue_next)
return do_shutup(); talk_force_shutup();
return 0;
} }
/* schedule a clip, at the end or discard the existing queue */ /* schedule a clip, at the end or discard the existing queue */
static int queue_clip(unsigned char* buf, long size, bool enqueue) static void queue_clip(unsigned char* buf, long size, bool enqueue)
{ {
int queue_level; int queue_level;
if (!enqueue) if (!enqueue)
shutup(); /* cut off all the pending stuff */ talk_shutup(); /* cut off all the pending stuff */
/* Something is being enqueued, force_enqueue_next override is no /* Something is being enqueued, force_enqueue_next override is no
longer in effect. */ longer in effect. */
force_enqueue_next = false; force_enqueue_next = false;
if (!size) if (!size)
return 0; /* safety check */ return; /* safety check */
#if CONFIG_CPU == SH7034 #if CONFIG_CPU == SH7034
/* disable the DMA temporarily, to be safe of race condition */ /* disable the DMA temporarily, to be safe of race condition */
CHCR3 &= ~0x0001; CHCR3 &= ~0x0001;
@ -431,50 +455,7 @@ static int queue_clip(unsigned char* buf, long size, bool enqueue)
#endif #endif
} }
return 0; return;
}
/* fetch a clip from the voice file */
static unsigned char* get_clip(long id, long* p_size)
{
long clipsize;
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;
clipbuf = (unsigned char *) p_voicefile + p_voicefile->index[id].offset;
#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;
} }
@ -500,11 +481,12 @@ static void reset_state(void)
p_silence = NULL; /* pause clip not accessible */ p_silence = NULL; /* pause clip not accessible */
} }
/***************** Public implementation *****************/ /***************** Public implementation *****************/
void talk_init(void) void talk_init(void)
{ {
talk_menu_disable = 0; talk_temp_disable_count = 0;
if (talk_initialized && !strcasecmp(last_lang, global_settings.lang_file)) if (talk_initialized && !strcasecmp(last_lang, global_settings.lang_file))
{ {
/* not a new file, nothing to do */ /* not a new file, nothing to do */
@ -558,7 +540,7 @@ int talk_get_bufsize(void)
} }
/* somebody else claims the mp3 buffer, e.g. for regular play/record */ /* somebody else claims the mp3 buffer, e.g. for regular play/record */
int talk_buffer_steal(void) void talk_buffer_steal(void)
{ {
#if CONFIG_CODEC != SWCODEC #if CONFIG_CODEC != SWCODEC
mp3_play_stop(); mp3_play_stop();
@ -570,9 +552,7 @@ int talk_buffer_steal(void)
filehandle = -1; filehandle = -1;
} }
#endif #endif
reset_state(); reset_state();;
return 0;
} }
@ -583,6 +563,8 @@ int talk_id(long id, bool enqueue)
unsigned char* clipbuf; unsigned char* clipbuf;
int unit; int unit;
if (talk_temp_disable_count > 0)
return -1; /* talking has been disabled */
#if CONFIG_CODEC != SWCODEC #if CONFIG_CODEC != SWCODEC
if (audio_status()) /* busy, buffer in use */ if (audio_status()) /* busy, buffer in use */
return -1; return -1;
@ -644,6 +626,8 @@ int talk_file(const char* filename, bool enqueue)
int size; int size;
struct mp3entry info; struct mp3entry info;
if (talk_temp_disable_count > 0)
return -1; /* talking has been disabled */
#if CONFIG_CODEC != SWCODEC #if CONFIG_CODEC != SWCODEC
if (audio_status()) /* busy, buffer in use */ if (audio_status()) /* busy, buffer in use */
return -1; return -1;
@ -689,13 +673,15 @@ int talk_number(long n, bool enqueue)
int level = 2; /* mille count */ int level = 2; /* mille count */
long mil = 1000000000; /* highest possible "-illion" */ long mil = 1000000000; /* highest possible "-illion" */
if (talk_temp_disable_count > 0)
return -1; /* talking has been disabled */
#if CONFIG_CODEC != SWCODEC #if CONFIG_CODEC != SWCODEC
if (audio_status()) /* busy, buffer in use */ if (audio_status()) /* busy, buffer in use */
return -1; return -1;
#endif #endif
if (!enqueue) if (!enqueue)
shutup(); /* cut off all the pending stuff */ talk_shutup(); /* cut off all the pending stuff */
if (n==0) if (n==0)
{ /* special case */ { /* special case */
@ -785,6 +771,8 @@ int talk_value(long n, int unit, bool enqueue)
= VOICE_PM_UNITS_PER_TICK, = VOICE_PM_UNITS_PER_TICK,
}; };
if (talk_temp_disable_count > 0)
return -1; /* talking has been disabled */
#if CONFIG_CODEC != SWCODEC #if CONFIG_CODEC != SWCODEC
if (audio_status()) /* busy, buffer in use */ if (audio_status()) /* busy, buffer in use */
return -1; return -1;
@ -819,13 +807,15 @@ int talk_spell(const char* spell, bool enqueue)
{ {
char c; /* currently processed char */ char c; /* currently processed char */
if (talk_temp_disable_count > 0)
return -1; /* talking has been disabled */
#if CONFIG_CODEC != SWCODEC #if CONFIG_CODEC != SWCODEC
if (audio_status()) /* busy, buffer in use */ if (audio_status()) /* busy, buffer in use */
return -1; return -1;
#endif #endif
if (!enqueue) if (!enqueue)
shutup(); /* cut off all the pending stuff */ talk_shutup(); /* cut off all the pending stuff */
while ((c = *spell++) != '\0') while ((c = *spell++) != '\0')
{ {
@ -849,26 +839,18 @@ int talk_spell(const char* spell, bool enqueue)
return 0; return 0;
} }
bool talk_menus_enabled(void) void talk_disable(bool disable)
{ {
return (global_settings.talk_menu && talk_menu_disable == 0); if (disable)
} talk_temp_disable_count++;
else
talk_temp_disable_count--;
void talk_disable_menus(void)
{
talk_menu_disable++;
}
void talk_enable_menus(void)
{
talk_menu_disable--;
} }
#if CONFIG_RTC #if CONFIG_RTC
void talk_date_time(struct tm *tm, bool speak_current_time_string) void talk_date_time(struct tm *tm, bool speak_current_time_string)
{ {
if(talk_menus_enabled ()) if(global_settings.talk_menu)
{ {
if(speak_current_time_string) if(speak_current_time_string)
talk_id(VOICE_CURRENT_TIME, true); talk_id(VOICE_CURRENT_TIME, true);

View file

@ -66,19 +66,16 @@ void talk_init(void);
bool talk_voice_required(void); /* returns true if voice codec required */ bool talk_voice_required(void); /* returns true if voice codec required */
#endif #endif
int talk_get_bufsize(void); /* get the loaded voice file size */ int talk_get_bufsize(void); /* get the loaded voice file size */
/* talk_buffer_steal - on SWCODEC, for use by buffer functions only */ void talk_buffer_steal(void); /* claim the mp3 buffer e.g. for play/record */
int talk_buffer_steal(void); /* claim the mp3 buffer e.g. for play/record */
bool is_voice_queued(void); /* Are there more voice clips to be spoken? */ bool is_voice_queued(void); /* Are there more voice clips to be spoken? */
int talk_id(long id, bool enqueue); /* play a voice ID from voicefont */ int talk_id(long id, bool enqueue); /* play a voice ID from voicefont */
int talk_file(const char* filename, bool enqueue); /* play a thumbnail from file */ int talk_file(const char* filename, bool enqueue); /* play a thumbnail from file */
int talk_number(long n, bool enqueue); /* say a number */ int talk_number(long n, bool enqueue); /* say a number */
int talk_value(long n, int unit, bool enqueue); /* say a numeric value */ int talk_value(long n, int unit, bool enqueue); /* say a numeric value */
int talk_spell(const char* spell, bool enqueue); /* spell a string */ int talk_spell(const char* spell, bool enqueue); /* spell a string */
bool talk_menus_enabled(void); /* returns true if menus should be voiced */ void talk_disable(bool disable); /* temporarily disable (or re-enable) talking (temporarily, not persisted) */
void talk_disable_menus(void); /* disable voice menus (temporarily, not persisted) */ void talk_force_shutup(void); /* kill voice unconditionally */
void talk_enable_menus(void); /* re-enable voice menus */ void talk_shutup(void); /* Interrupt voice, as when enqueue is false */
int do_shutup(void); /* kill voice unconditionally */
int shutup(void); /* Interrupt voice, as when enqueue is false */
#if CONFIG_RTC #if CONFIG_RTC
/* this is in talk.c which isnt compiled for hwcodec simulator */ /* this is in talk.c which isnt compiled for hwcodec simulator */
@ -94,12 +91,14 @@ void talk_date_time(struct tm *time, bool speak_current_time_string);
/* We don't build talk.c for hwcodec sims so we need to define these as empty */ /* We don't build talk.c for hwcodec sims so we need to define these as empty */
#if defined(SIMULATOR) && !(CONFIG_CODEC == SWCODEC) #if defined(SIMULATOR) && !(CONFIG_CODEC == SWCODEC)
#define talk_init(...)
#define talk_buffer_steal(...)
#define talk_shutup(...)
#define talk_force_enqueue_next(...) #define talk_force_enqueue_next(...)
#define talk_idarray(...) #define talk_idarray(...)
#define talk_ids(...) #define talk_ids(...)
#define cond_talk_ids(...) #define cond_talk_ids(...)
#define cond_talk_ids_fq(...) #define cond_talk_ids_fq(...)
#define shutup(...)
#else #else
/* Enqueue next utterance even if enqueue parameter is false: don't /* Enqueue next utterance even if enqueue parameter is false: don't
@ -116,18 +115,18 @@ int talk_idarray(long *idarray, bool enqueue);
/* This version talks only if talking menus are enabled, and does not /* This version talks only if talking menus are enabled, and does not
enqueue the initial id. */ enqueue the initial id. */
#define cond_talk_ids(ids...) do { \ #define cond_talk_ids(ids...) do { \
if (talk_menus_enabled()) \ if (global_settings.talk_menu) \
talk_ids(false, ids); \ talk_ids(false, ids); \
} while(0) } while(0)
/* And a version that takes the array parameter... */ /* And a version that takes the array parameter... */
#define cond_talk_idarray(idarray) do { \ #define cond_talk_idarray(idarray) do { \
if (talk_menus_enabled() \ if (global_settings.talk_menu \
talk_idarray(idarray, false); \ talk_idarray(idarray, false); \
} while(0) } while(0)
/* Convenience macro to conditionally speak something and not have /* Convenience macro to conditionally speak something and not have
it interrupted. */ it interrupted. */
#define cond_talk_ids_fq(ids...) do { \ #define cond_talk_ids_fq(ids...) do { \
if (talk_menus_enabled()) { \ if (global_settings.talk_menu) { \
talk_ids(false, ids); \ talk_ids(false, ids); \
talk_force_enqueue_next(); \ talk_force_enqueue_next(); \
} \ } \

View file

@ -302,14 +302,6 @@ void button_set_flip(bool yesno)
} }
#if CONFIG_CODEC != SWCODEC #if CONFIG_CODEC != SWCODEC
void talk_init(void)
{
}
int talk_buffer_steal(void)
{
return 0;
}
int talk_id(int id, bool enqueue) int talk_id(int id, bool enqueue)
{ {
@ -347,17 +339,9 @@ int talk_spell(char* spell, bool enqueue)
return 0; return 0;
} }
bool talk_menus_enabled(void) void talk_disable(bool disable)
{
return false;
}
void talk_enable_menus(void)
{
}
void talk_disable_menus(void)
{ {
(void) disable;
} }
const char* const dir_thumbnail_name = "_dirname.talk"; const char* const dir_thumbnail_name = "_dirname.talk";