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) | |
download | rockbox-97b56a665c9aafee634ee5ffd6fa86fd2f9c7dd9.tar.gz rockbox-97b56a665c9aafee634ee5ffd6fa86fd2f9c7dd9.zip |
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) | |||
481 | static void* get_codec_memory_callback(size_t *size) | 481 | static void* get_codec_memory_callback(size_t *size) |
482 | { | 482 | { |
483 | *size = MALLOC_BUFSIZE; | 483 | *size = MALLOC_BUFSIZE; |
484 | #if CONFIG_CODEC != SWCODEC | 484 | return &audiobuf[talk_get_bufsize()]; |
485 | /* MASCODEC cannot play audio and voice simultaneously, so its | ||
486 | voice strategy is different - see talk.c for details */ | ||
487 | if (voice_codec_loaded) | ||
488 | return &audiobuf[talk_get_bufsize()]; | ||
489 | else | ||
490 | #endif | ||
491 | return audiobuf; | ||
492 | } | 485 | } |
493 | 486 | ||
494 | static void pcmbuf_position_callback(size_t size) ICODE_ATTR; | 487 | static void pcmbuf_position_callback(size_t size) ICODE_ATTR; |
@@ -2559,14 +2552,16 @@ static void reset_buffer(void) | |||
2559 | { | 2552 | { |
2560 | size_t offset; | 2553 | size_t offset; |
2561 | 2554 | ||
2562 | filebuf = (char *)&audiobuf[MALLOC_BUFSIZE]; | 2555 | /* Set up file buffer as all space available */ |
2563 | filebuflen = audiobufend - audiobuf - MALLOC_BUFSIZE - GUARD_BUFSIZE - | 2556 | filebuf = (char *)&audiobuf[talk_get_bufsize()+MALLOC_BUFSIZE]; |
2557 | filebuflen = audiobufend - (unsigned char *) filebuf - GUARD_BUFSIZE - | ||
2564 | (pcmbuf_get_bufsize() + get_pcmbuf_descsize() + PCMBUF_MIX_CHUNK * 2); | 2558 | (pcmbuf_get_bufsize() + get_pcmbuf_descsize() + PCMBUF_MIX_CHUNK * 2); |
2565 | 2559 | ||
2560 | /* Allow for codec(s) at end of file buffer */ | ||
2566 | if (talk_voice_required()) | 2561 | if (talk_voice_required()) |
2567 | { | 2562 | { |
2568 | filebuf = &filebuf[talk_get_bufsize()]; | 2563 | /* Allow 2 codecs at end of file buffer */ |
2569 | filebuflen -= 2*CODEC_IRAM_SIZE + 2*CODEC_SIZE + talk_get_bufsize(); | 2564 | filebuflen -= 2 * (CODEC_IRAM_SIZE + CODEC_SIZE); |
2570 | 2565 | ||
2571 | #ifndef SIMULATOR | 2566 | #ifndef SIMULATOR |
2572 | iram_buf[0] = &filebuf[filebuflen]; | 2567 | iram_buf[0] = &filebuf[filebuflen]; |
@@ -2577,16 +2572,18 @@ static void reset_buffer(void) | |||
2577 | } | 2572 | } |
2578 | else | 2573 | else |
2579 | { | 2574 | { |
2580 | filebuf = &filebuf[talk_get_bufsize()]; | 2575 | /* Allow for 1 codec at end of file buffer */ |
2581 | filebuflen -= CODEC_IRAM_SIZE + CODEC_SIZE + talk_get_bufsize(); | 2576 | filebuflen -= CODEC_IRAM_SIZE + CODEC_SIZE; |
2582 | 2577 | ||
2583 | #ifndef SIMULATOR | 2578 | #ifndef SIMULATOR |
2584 | iram_buf[0] = &filebuf[filebuflen]; | 2579 | iram_buf[0] = &filebuf[filebuflen]; |
2580 | iram_buf[1] = NULL; | ||
2585 | #endif | 2581 | #endif |
2586 | dram_buf[0] = (unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE*2]; | 2582 | dram_buf[0] = (unsigned char *)&filebuf[filebuflen+CODEC_IRAM_SIZE]; |
2583 | dram_buf[1] = NULL; | ||
2587 | } | 2584 | } |
2588 | 2585 | ||
2589 | /* Ensure that everything is aligned */ | 2586 | /* Ensure that file buffer is aligned */ |
2590 | offset = (-(size_t)filebuf) & 3; | 2587 | offset = (-(size_t)filebuf) & 3; |
2591 | filebuf += offset; | 2588 | filebuf += offset; |
2592 | filebuflen -= offset; | 2589 | filebuflen -= offset; |
@@ -3092,7 +3089,7 @@ static void playback_init(void) | |||
3092 | #endif | 3089 | #endif |
3093 | } | 3090 | } |
3094 | 3091 | ||
3095 | filebuf = (char *)&audiobuf[MALLOC_BUFSIZE]; | 3092 | filebuf = (char *)&audiobuf[MALLOC_BUFSIZE]; /* Will be reset by reset_buffer */ |
3096 | 3093 | ||
3097 | audio_set_crossfade(global_settings.crossfade); | 3094 | audio_set_crossfade(global_settings.crossfade); |
3098 | 3095 | ||
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 @@ | |||
38 | #if CONFIG_CODEC == SWCODEC | 38 | #if CONFIG_CODEC == SWCODEC |
39 | #include "playback.h" | 39 | #include "playback.h" |
40 | #endif | 40 | #endif |
41 | #include "debug.h" | ||
41 | 42 | ||
42 | 43 | ||
43 | /* Memory layout varies between targets because the | 44 | /* Memory layout varies between targets because the |
@@ -47,7 +48,7 @@ | |||
47 | (playing) | (stopped) | | 48 | (playing) | (stopped) | |
48 | audiobuf-----------+-----------+----------- | 49 | audiobuf-----------+-----------+----------- |
49 | audio | voice | thumbnail | 50 | audio | voice | thumbnail |
50 | |-----------|----------- | 51 | |-----------|----------- filebuf |
51 | | thumbnail | voice | 52 | | thumbnail | voice |
52 | | |----------- | 53 | | |----------- |
53 | | | audio | 54 | | | audio |
@@ -189,12 +190,10 @@ static void load_voicefile(void) | |||
189 | if (((struct voicefile*)audiobuf)->table /* format check */ | 190 | if (((struct voicefile*)audiobuf)->table /* format check */ |
190 | == offsetof(struct voicefile, index)) | 191 | == offsetof(struct voicefile, index)) |
191 | { | 192 | { |
192 | #if CONFIG_CODEC == SWCODEC | ||
193 | /* SWCODEC: allocate permanent buffer */ | ||
194 | p_voicefile = (struct voicefile*)buffer_alloc(file_size); | ||
195 | #else | ||
196 | /* MASCODEC: now use audiobuf for voice then thumbnail */ | ||
197 | p_voicefile = (struct voicefile*)audiobuf; | 193 | p_voicefile = (struct voicefile*)audiobuf; |
194 | |||
195 | #if CONFIG_CODEC != SWCODEC | ||
196 | /* MASCODEC: now use audiobuf for voice then thumbnail */ | ||
198 | p_thumbnail = audiobuf + file_size; | 197 | p_thumbnail = audiobuf + file_size; |
199 | p_thumbnail += (long)p_thumbnail % 2; /* 16-bit align */ | 198 | p_thumbnail += (long)p_thumbnail % 2; /* 16-bit align */ |
200 | size_for_thumbnail = audiobufend - p_thumbnail; | 199 | size_for_thumbnail = audiobufend - p_thumbnail; |
@@ -526,13 +525,14 @@ void talk_init(void) | |||
526 | close(filehandle); /* close again, this was just to detect presence */ | 525 | close(filehandle); /* close again, this was just to detect presence */ |
527 | filehandle = -1; | 526 | filehandle = -1; |
528 | } | 527 | } |
528 | |||
529 | } | 529 | } |
530 | 530 | ||
531 | /* return if a voice codec is required or not */ | 531 | /* return if a voice codec is required or not */ |
532 | bool talk_voice_required(void) | 532 | bool talk_voice_required(void) |
533 | { | 533 | { |
534 | return (voicefile_size != 0) | 534 | return (voicefile_size != 0) /* Voice file is available */ |
535 | || (global_settings.talk_dir == 3) | 535 | || (global_settings.talk_dir == 3) /* Thumbnail clips are required */ |
536 | || (global_settings.talk_file == 3); | 536 | || (global_settings.talk_file == 3); |
537 | } | 537 | } |
538 | 538 | ||