summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/talk.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/apps/talk.c b/apps/talk.c
index a22aac02b7..ed7d55d455 100644
--- a/apps/talk.c
+++ b/apps/talk.c
@@ -51,16 +51,17 @@
51 MASCODEC | MASCODEC | SWCODEC 51 MASCODEC | MASCODEC | SWCODEC
52 (playing) | (stopped) | 52 (playing) | (stopped) |
53 voicebuf-----------+-----------+------------ 53 voicebuf-----------+-----------+------------
54 audio | voice | thumbnail 54 audio | voice | voice
55 |-----------|------------ 55 |-----------|------------
56 | thumbnail | voice 56 | thumbnail | thumbnail
57 | |------------ 57 | |------------
58 | | filebuf 58 | | filebuf
59 | |------------ 59 | |------------
60 | | audio 60 | | audio
61 voicebufend----------+-----------+------------ 61 voicebufend----------+-----------+------------
62 62
63 SWCODEC allocates dedicated buffers, MASCODEC reuses audiobuf. */ 63 SWCODEC allocates dedicated buffers (except voice and thumbnail are together
64 in the talkbuf), MASCODEC reuses audiobuf. */
64 65
65 66
66/***************** Constants *****************/ 67/***************** Constants *****************/
@@ -349,12 +350,12 @@ static void load_voicefile(bool probe, char* buf, size_t bufsize)
349 logf("Incompatible voice file"); 350 logf("Incompatible voice file");
350 goto load_err; 351 goto load_err;
351 } 352 }
352#if CONFIG_CODEC != SWCODEC
353 /* MASCODEC: now use audiobuf for voice then thumbnail */
354 p_thumbnail = voicebuf.buf + file_size; 353 p_thumbnail = voicebuf.buf + file_size;
355 p_thumbnail += (long)p_thumbnail % 2; /* 16-bit align */ 354 p_thumbnail += (long)p_thumbnail % 2; /* 16-bit align */
356 size_for_thumbnail = voicebuf.buf + bufsize - p_thumbnail; 355 size_for_thumbnail =
357#endif 356 MIN(voicebuf.buf + bufsize - p_thumbnail, MAX_THUMBNAIL_BUFSIZE);
357 if (size_for_thumbnail <= 0)
358 p_thumbnail = NULL;
358 } 359 }
359 else 360 else
360 goto load_err; 361 goto load_err;
@@ -604,19 +605,9 @@ static void queue_clip(unsigned char* buf, long size, bool enqueue)
604 605
605static void alloc_thumbnail_buf(void) 606static void alloc_thumbnail_buf(void)
606{ 607{
607#if CONFIG_CODEC == SWCODEC
608 /* Allocate a dedicated thumbnail buffer - once */
609 if (p_thumbnail == NULL)
610 {
611 size_for_thumbnail = buffer_available();
612 if (size_for_thumbnail > MAX_THUMBNAIL_BUFSIZE)
613 size_for_thumbnail = MAX_THUMBNAIL_BUFSIZE;
614 p_thumbnail = buffer_alloc(size_for_thumbnail);
615 }
616#else
617 /* use the audio buffer now, need to release before loading a voice */ 608 /* use the audio buffer now, need to release before loading a voice */
618 p_thumbnail = voicebuf; 609 p_thumbnail = voicebuf;
619#endif 610 size_for_thumbnail = MAX_THUMBNAIL_BUFSIZE;
620 thumbnail_buf_used = 0; 611 thumbnail_buf_used = 0;
621} 612}
622 613
@@ -625,9 +616,7 @@ static void reset_state(void)
625{ 616{
626 queue_write = queue_read = 0; /* reset the queue */ 617 queue_write = queue_read = 0; /* reset the queue */
627 p_voicefile = NULL; /* indicate no voicefile (trashed) */ 618 p_voicefile = NULL; /* indicate no voicefile (trashed) */
628#if CONFIG_CODEC != SWCODEC 619 p_thumbnail = NULL; /* no thumbnails either */
629 p_thumbnail = NULL; /* don't leak buffer_alloc() for swcodec */
630#endif
631 620
632#ifdef TALK_PARTIAL_LOAD 621#ifdef TALK_PARTIAL_LOAD
633 int i; 622 int i;
@@ -733,7 +722,11 @@ bool talk_voice_required(void)
733/* return size of voice file */ 722/* return size of voice file */
734int talk_get_buffer(void) 723int talk_get_buffer(void)
735{ 724{
736 return voicefile_size; 725 int ret = voicefile_size;
726#if CONFIG_CODEC == SWCODEC
727 ret += MAX_THUMBNAIL_BUFSIZE;
728#endif
729 return ret;
737} 730}
738 731
739/* Sets the buffer for the voicefile and returns how many bytes of this 732/* Sets the buffer for the voicefile and returns how many bytes of this
@@ -747,7 +740,7 @@ size_t talkbuf_init(char *bufstart)
747 if (bufstart) 740 if (bufstart)
748 voicebuf = bufstart; 741 voicebuf = bufstart;
749 742
750 return voicefile_size; 743 return talk_get_buffer();
751} 744}
752 745
753/* somebody else claims the mp3 buffer, e.g. for regular play/record */ 746/* somebody else claims the mp3 buffer, e.g. for regular play/record */