1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Linus Nielsen Feltzing 2006-08-23 08:21:15 +00:00
parent 8a3b6dad94
commit 97b56a665c
2 changed files with 22 additions and 25 deletions

View file

@ -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);

View file

@ -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);
}