Patch #5766 by Steve Bavin - Fix for various voice related crashes

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10590 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2006-08-15 18:01:42 +00:00
parent 599fa9a627
commit 42f0ad3c8f
4 changed files with 37 additions and 12 deletions

View file

@ -481,9 +481,13 @@ static void* get_voice_memory_callback(size_t *size)
static void* get_codec_memory_callback(size_t *size)
{
*size = MALLOC_BUFSIZE;
#if CONFIG_CODEC != SWCODEC
/* MASCODEC cannot play audio and voice simultaneously, so its
voice strategy is different - see talk.c for details */
if (voice_codec_loaded)
return &audiobuf[talk_get_bufsize()];
else
#endif
return audiobuf;
}
@ -2559,7 +2563,7 @@ static void reset_buffer(void)
filebuflen = audiobufend - audiobuf - MALLOC_BUFSIZE - GUARD_BUFSIZE -
(pcmbuf_get_bufsize() + get_pcmbuf_descsize() + PCMBUF_MIX_CHUNK * 2);
if (talk_get_bufsize())
if (talk_voice_required())
{
filebuf = &filebuf[talk_get_bufsize()];
filebuflen -= 2*CODEC_IRAM_SIZE + 2*CODEC_SIZE + talk_get_bufsize();
@ -2569,8 +2573,17 @@ static void reset_buffer(void)
iram_buf[1] = &filebuf[filebuflen+CODEC_IRAM_SIZE];
#endif
dram_buf[0] = (unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE*2];
dram_buf[1] =
(unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE*2+CODEC_SIZE];
dram_buf[1] = (unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE*2+CODEC_SIZE];
}
else
{
filebuf = &filebuf[talk_get_bufsize()];
filebuflen -= CODEC_IRAM_SIZE + CODEC_SIZE + talk_get_bufsize();
#ifndef SIMULATOR
iram_buf[0] = &filebuf[filebuflen];
#endif
dram_buf[0] = (unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE*2];
}
/* Ensure that everything is aligned */
@ -2616,8 +2629,8 @@ void voice_init(void)
voice_codec_loaded = false;
}
if (!talk_get_bufsize())
return ;
if (!talk_voice_required())
return;
logf("Starting voice codec");
queue_init(&voice_codec_queue);

View file

@ -1264,16 +1264,20 @@ static const struct opt_items voice_names[] = {
static bool voice_dirs(void)
{
return set_option( str(LANG_VOICE_DIR),
bool ret = set_option( str(LANG_VOICE_DIR),
&global_settings.talk_dir, INT, voice_names, 4, NULL);
audio_set_crossfade(global_settings.crossfade);
return ret;
}
static bool voice_files(void)
{
int oldval = global_settings.talk_file;
bool ret;
ret = set_option( str(LANG_VOICE_FILE),
&global_settings.talk_file, INT, voice_names, 4, NULL);
audio_set_crossfade(global_settings.crossfade);
if (oldval != 3 && global_settings.talk_file == 3)
{ /* force reload if newly talking thumbnails,
because the clip presence is cached only if enabled */
@ -1462,9 +1466,7 @@ static bool crossfade(void)
ret=set_option( str(LANG_CROSSFADE_ENABLE),
&global_settings.crossfade, INT, names, 4, NULL);
audio_set_crossfade(global_settings.crossfade);
return ret;
}

View file

@ -146,10 +146,6 @@ static int open_voicefile(void)
return open(buf, O_RDONLY);
}
int talk_get_bufsize(void)
{
return voicefile_size;
}
/* load the voice file into the mp3 buffer */
static void load_voicefile(void)
@ -532,6 +528,19 @@ void talk_init(void)
}
}
/* return if a voice codec is required or not */
bool talk_voice_required(void)
{
return (voicefile_size != 0)
|| (global_settings.talk_dir == 3)
|| (global_settings.talk_file == 3);
}
/* return size of voice file */
int talk_get_bufsize(void)
{
return voicefile_size;
}
/* somebody else claims the mp3 buffer, e.g. for regular play/record */
int talk_buffer_steal(void)

View file

@ -58,6 +58,7 @@ extern const char* const dir_thumbnail_name; /* "_dirname.talk" */
extern const char* const file_thumbnail_ext; /* ".talk" for file voicing */
void talk_init(void);
bool talk_voice_required(void); /* returns true if voice codec required */
int talk_get_bufsize(void); /* get the loaded voice file size */
int talk_buffer_steal(void); /* claim the mp3 buffer e.g. for play/record */
int talk_id(long id, bool enqueue); /* play a voice ID from voicefont */