diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2006-08-23 08:21:15 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2006-08-23 08:21:15 +0000 |
commit | 97b56a665c9aafee634ee5ffd6fa86fd2f9c7dd9 (patch) | |
tree | 2abad5a833bc3ea81bc1661a0ae78a5e7044f854 /apps | |
parent | 8a3b6dad94a471f82ae39ed6507074f3c83caf7c (diff) |
Patch #5844 by Steve Bavin - Fix confused voice file memory allocation
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10711 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/playback.c | 31 | ||||
-rw-r--r-- | apps/talk.c | 16 |
2 files changed, 22 insertions, 25 deletions
diff --git a/apps/playback.c b/apps/playback.c index ef93177eec..845fb5c7ff 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -481,14 +481,7 @@ 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; + return &audiobuf[talk_get_bufsize()]; } static void pcmbuf_position_callback(size_t size) ICODE_ATTR; @@ -2559,14 +2552,16 @@ static void reset_buffer(void) { size_t offset; - filebuf = (char *)&audiobuf[MALLOC_BUFSIZE]; - filebuflen = audiobufend - audiobuf - MALLOC_BUFSIZE - GUARD_BUFSIZE - + /* Set up file buffer as all space available */ + filebuf = (char *)&audiobuf[talk_get_bufsize()+MALLOC_BUFSIZE]; + filebuflen = audiobufend - (unsigned char *) filebuf - GUARD_BUFSIZE - (pcmbuf_get_bufsize() + get_pcmbuf_descsize() + PCMBUF_MIX_CHUNK * 2); + /* Allow for codec(s) at end of file buffer */ if (talk_voice_required()) { - filebuf = &filebuf[talk_get_bufsize()]; - filebuflen -= 2*CODEC_IRAM_SIZE + 2*CODEC_SIZE + talk_get_bufsize(); + /* Allow 2 codecs at end of file buffer */ + filebuflen -= 2 * (CODEC_IRAM_SIZE + CODEC_SIZE); #ifndef SIMULATOR iram_buf[0] = &filebuf[filebuflen]; @@ -2577,16 +2572,18 @@ static void reset_buffer(void) } else { - filebuf = &filebuf[talk_get_bufsize()]; - filebuflen -= CODEC_IRAM_SIZE + CODEC_SIZE + talk_get_bufsize(); + /* Allow for 1 codec at end of file buffer */ + filebuflen -= CODEC_IRAM_SIZE + CODEC_SIZE; #ifndef SIMULATOR iram_buf[0] = &filebuf[filebuflen]; + iram_buf[1] = NULL; #endif - dram_buf[0] = (unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE*2]; + dram_buf[0] = (unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE]; + dram_buf[1] = NULL; } - /* Ensure that everything is aligned */ + /* Ensure that file buffer is aligned */ offset = (-(size_t)filebuf) & 3; filebuf += offset; filebuflen -= offset; @@ -3092,7 +3089,7 @@ static void playback_init(void) #endif } - filebuf = (char *)&audiobuf[MALLOC_BUFSIZE]; + filebuf = (char *)&audiobuf[MALLOC_BUFSIZE]; /* Will be reset by reset_buffer */ audio_set_crossfade(global_settings.crossfade); diff --git a/apps/talk.c b/apps/talk.c index 8f507eb700..cf68cdf021 100644 --- a/apps/talk.c +++ b/apps/talk.c @@ -38,6 +38,7 @@ #if CONFIG_CODEC == SWCODEC #include "playback.h" #endif +#include "debug.h" /* Memory layout varies between targets because the @@ -47,7 +48,7 @@ (playing) | (stopped) | audiobuf-----------+-----------+----------- audio | voice | thumbnail - |-----------|----------- + |-----------|----------- filebuf | thumbnail | voice | |----------- | | audio @@ -189,12 +190,10 @@ static void load_voicefile(void) if (((struct voicefile*)audiobuf)->table /* format check */ == offsetof(struct voicefile, index)) { -#if CONFIG_CODEC == SWCODEC - /* SWCODEC: allocate permanent buffer */ - p_voicefile = (struct voicefile*)buffer_alloc(file_size); -#else - /* MASCODEC: now use audiobuf for voice then thumbnail */ p_voicefile = (struct voicefile*)audiobuf; + +#if CONFIG_CODEC != SWCODEC + /* MASCODEC: now use audiobuf for voice then thumbnail */ p_thumbnail = audiobuf + file_size; p_thumbnail += (long)p_thumbnail % 2; /* 16-bit align */ size_for_thumbnail = audiobufend - p_thumbnail; @@ -526,13 +525,14 @@ void talk_init(void) close(filehandle); /* close again, this was just to detect presence */ filehandle = -1; } + } /* return if a voice codec is required or not */ bool talk_voice_required(void) { - return (voicefile_size != 0) - || (global_settings.talk_dir == 3) + return (voicefile_size != 0) /* Voice file is available */ + || (global_settings.talk_dir == 3) /* Thumbnail clips are required */ || (global_settings.talk_file == 3); } |