summaryrefslogtreecommitdiff
path: root/apps/talk.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/talk.c')
-rw-r--r--apps/talk.c60
1 files changed, 18 insertions, 42 deletions
diff --git a/apps/talk.c b/apps/talk.c
index c264bd7179..e1eea4d3c4 100644
--- a/apps/talk.c
+++ b/apps/talk.c
@@ -113,14 +113,13 @@ struct queue_entry /* one entry of the internal queue */
113 113
114/***************** Globals *****************/ 114/***************** Globals *****************/
115 115
116#if CONFIG_STORAGE & STORAGE_MMC 116#if (CONFIG_CODEC == SWCODEC && MEMORYSIZE <= 2) \
117/* The MMC storage on the Ondios is slow enough that we want to buffer the 117 || (CONFIG_STORAGE & STORAGE_MMC)
118 * talk clips only when they are needed */ 118/* On low memory swcodec targets the entire voice file wouldn't fit in memory
119# define TALK_PROGRESSIVE_LOAD 119 * together with codecs, so we load clips each time they are accessed.
120#elif CONFIG_CODEC == SWCODEC && MEMORYSIZE <= 2 120 * The Ondios have slow storage access and loading the entire voice file would
121/* The entire voice file wouldn't fit in memory together with codecs, so we 121 * take several seconds, so we use the same mechanism. */
122 * load clips each time they are accessed */ 122#define TALK_PARTIAL_LOAD
123# define TALK_PARTIAL_LOAD
124#endif 123#endif
125 124
126#ifdef TALK_PARTIAL_LOAD 125#ifdef TALK_PARTIAL_LOAD
@@ -213,10 +212,9 @@ static unsigned char* get_clip(long id, long* p_size)
213 clipbuf = (unsigned char *) p_voicefile + p_voicefile->index[id].offset; 212 clipbuf = (unsigned char *) p_voicefile + p_voicefile->index[id].offset;
214#endif 213#endif
215 214
216#if defined(TALK_PROGRESSIVE_LOAD) || defined(TALK_PARTIAL_LOAD) 215#ifdef TALK_PARTIAL_LOAD
217 if (!(clipsize & LOADED_MASK)) 216 if (!(clipsize & LOADED_MASK))
218 { /* clip needs loading */ 217 { /* clip needs loading */
219#ifdef TALK_PARTIAL_LOAD
220 int idx = 0; 218 int idx = 0;
221 if (id == VOICE_PAUSE) { 219 if (id == VOICE_PAUSE) {
222 idx = QUEUE_SIZE; /* we keep VOICE_PAUSE loaded */ 220 idx = QUEUE_SIZE; /* we keep VOICE_PAUSE loaded */
@@ -242,7 +240,6 @@ static unsigned char* get_clip(long id, long* p_size)
242 clip_age[idx] = 0; /* reset clip's age */ 240 clip_age[idx] = 0; /* reset clip's age */
243 } 241 }
244 clipbuf = clip_buffer + idx * max_clipsize; 242 clipbuf = clip_buffer + idx * max_clipsize;
245#endif
246 243
247 lseek(filehandle, p_voicefile->index[id].offset, SEEK_SET); 244 lseek(filehandle, p_voicefile->index[id].offset, SEEK_SET);
248 if (read(filehandle, clipbuf, clipsize) != clipsize) 245 if (read(filehandle, clipbuf, clipsize) != clipsize)
@@ -250,7 +247,6 @@ static unsigned char* get_clip(long id, long* p_size)
250 247
251 p_voicefile->index[id].size |= LOADED_MASK; /* mark as loaded */ 248 p_voicefile->index[id].size |= LOADED_MASK; /* mark as loaded */
252 249
253#ifdef TALK_PARTIAL_LOAD
254 if (id != VOICE_PAUSE) { 250 if (id != VOICE_PAUSE) {
255 if (buffered_id[idx] >= 0) { 251 if (buffered_id[idx] >= 0) {
256 /* mark previously loaded clip as unloaded */ 252 /* mark previously loaded clip as unloaded */
@@ -258,11 +254,9 @@ static unsigned char* get_clip(long id, long* p_size)
258 } 254 }
259 buffered_id[idx] = id; 255 buffered_id[idx] = id;
260 } 256 }
261#endif
262 } 257 }
263 else 258 else
264 { /* clip is in memory already */ 259 { /* clip is in memory already */
265#ifdef TALK_PARTIAL_LOAD
266 /* Find where it was loaded */ 260 /* Find where it was loaded */
267 clipbuf = clip_buffer; 261 clipbuf = clip_buffer;
268 if (id == VOICE_PAUSE) { 262 if (id == VOICE_PAUSE) {
@@ -276,10 +270,9 @@ static unsigned char* get_clip(long id, long* p_size)
276 break; 270 break;
277 } 271 }
278 } 272 }
279#endif
280 clipsize &= ~LOADED_MASK; /* without the extra bit gives true size */ 273 clipsize &= ~LOADED_MASK; /* without the extra bit gives true size */
281 } 274 }
282#endif /* defined(TALK_PROGRESSIVE_LOAD) || defined(TALK_PARTIAL_LOAD) */ 275#endif /* TALK_PARTIAL_LOAD */
283 276
284 *p_size = clipsize; 277 *p_size = clipsize;
285 return clipbuf; 278 return clipbuf;
@@ -297,9 +290,6 @@ static void load_voicefile(bool probe, char* buf, size_t bufsize)
297 290
298 size_t load_size, alloc_size; 291 size_t load_size, alloc_size;
299 ssize_t got_size; 292 ssize_t got_size;
300#ifndef TALK_PARTIAL_LOAD
301 size_t file_size;
302#endif
303#ifdef ROCKBOX_LITTLE_ENDIAN 293#ifdef ROCKBOX_LITTLE_ENDIAN
304 int i; 294 int i;
305#endif 295#endif
@@ -313,23 +303,15 @@ static void load_voicefile(bool probe, char* buf, size_t bufsize)
313 if (!voicebuf.buf) 303 if (!voicebuf.buf)
314 goto load_err; 304 goto load_err;
315 305
316#ifndef TALK_PARTIAL_LOAD 306#ifdef TALK_PARTIAL_LOAD
317 file_size = filesize(filehandle);
318 if (file_size > bufsize) /* won't fit? */
319 goto load_err;
320#endif
321
322#if defined(TALK_PROGRESSIVE_LOAD) || defined(TALK_PARTIAL_LOAD)
323 /* load only the header for now */ 307 /* load only the header for now */
324 load_size = sizeof(struct voicefile); 308 load_size = sizeof(struct voicefile);
325#else /* load the full file */ 309#else
326 load_size = file_size; 310 /* load the entire file */
311 load_size = filesize(filehandle);
327#endif 312#endif
328
329#ifdef TALK_PARTIAL_LOAD
330 if (load_size > bufsize) /* won't fit? */ 313 if (load_size > bufsize) /* won't fit? */
331 goto load_err; 314 goto load_err;
332#endif
333 315
334 got_size = read(filehandle, voicebuf.buf, load_size); 316 got_size = read(filehandle, voicebuf.buf, load_size);
335 if (got_size != (ssize_t)load_size /* failure */) 317 if (got_size != (ssize_t)load_size /* failure */)
@@ -357,15 +339,13 @@ static void load_voicefile(bool probe, char* buf, size_t bufsize)
357 else 339 else
358 goto load_err; 340 goto load_err;
359 341
360#if defined(TALK_PROGRESSIVE_LOAD) || defined(TALK_PARTIAL_LOAD) 342#ifdef TALK_PARTIAL_LOAD
361 /* load the index table, now that we know its size from the header */ 343 /* load the index table, now that we know its size from the header */
362 load_size = (p_voicefile->id1_max + p_voicefile->id2_max) 344 load_size = (p_voicefile->id1_max + p_voicefile->id2_max)
363 * sizeof(struct clip_entry); 345 * sizeof(struct clip_entry);
364 346
365#ifdef TALK_PARTIAL_LOAD
366 if (load_size > bufsize) /* won't fit? */ 347 if (load_size > bufsize) /* won't fit? */
367 goto load_err; 348 goto load_err;
368#endif
369 349
370 got_size = read(filehandle, &p_voicefile->index[0], load_size); 350 got_size = read(filehandle, &p_voicefile->index[0], load_size);
371 if (got_size != (ssize_t)load_size) /* read error */ 351 if (got_size != (ssize_t)load_size) /* read error */
@@ -375,7 +355,7 @@ static void load_voicefile(bool probe, char* buf, size_t bufsize)
375#else 355#else
376 close(filehandle); 356 close(filehandle);
377 filehandle = -1; 357 filehandle = -1;
378#endif /* defined(TALK_PROGRESSIVE_LOAD) || defined(TALK_PARTIAL_LOAD) */ 358#endif /* TALK_PARTIAL_LOAD */
379 359
380#ifdef ROCKBOX_LITTLE_ENDIAN 360#ifdef ROCKBOX_LITTLE_ENDIAN
381 for (i = 0; i < p_voicefile->id1_max + p_voicefile->id2_max; i++) 361 for (i = 0; i < p_voicefile->id1_max + p_voicefile->id2_max; i++)
@@ -394,10 +374,6 @@ static void load_voicefile(bool probe, char* buf, size_t bufsize)
394 374
395#ifdef TALK_PARTIAL_LOAD 375#ifdef TALK_PARTIAL_LOAD
396 alloc_size += silence_len + QUEUE_SIZE; 376 alloc_size += silence_len + QUEUE_SIZE;
397#else
398 /* allocate for the entire file, TALK_PROGRESSIVE_LOAD doesn't
399 * load everything just yet */
400 alloc_size = file_size;
401#endif 377#endif
402 378
403 if (alloc_size > bufsize) 379 if (alloc_size > bufsize)
@@ -736,11 +712,11 @@ bool talk_voice_required(void)
736/* return size of voice file */ 712/* return size of voice file */
737static int talk_get_buffer(void) 713static int talk_get_buffer(void)
738{ 714{
739 int ret = voicefile_size;
740#if CONFIG_CODEC == SWCODEC 715#if CONFIG_CODEC == SWCODEC
741 ret += MAX_THUMBNAIL_BUFSIZE; 716 return voicefile_size + MAX_THUMBNAIL_BUFSIZE;
717#else
718 return audio_buffer_available();
742#endif 719#endif
743 return ret;
744} 720}
745 721
746/* Sets the buffer for the voicefile and returns how many bytes of this 722/* Sets the buffer for the voicefile and returns how many bytes of this