diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2006-11-28 15:00:56 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2006-11-28 15:00:56 +0000 |
commit | 97d1ca5a238b9fa676fd59cb81cb0ec9069a4ba9 (patch) | |
tree | cbb2526852c17dbeb2ad361a8362f36fd0ad693f | |
parent | 9be9767a49fea9b12ff0437acabb0ad0e30b3d52 (diff) | |
download | rockbox-97d1ca5a238b9fa676fd59cb81cb0ec9069a4ba9.tar.gz rockbox-97d1ca5a238b9fa676fd59cb81cb0ec9069a4ba9.zip |
SWCODEC: Audio-related threads must be free of further tasks before returning buffers. Cleanup declarations of related functions.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11618 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/playback.c | 56 | ||||
-rw-r--r-- | apps/talk.c | 2 | ||||
-rw-r--r-- | apps/talk.h | 3 | ||||
-rw-r--r-- | firmware/export/pcm_record.h | 4 |
4 files changed, 32 insertions, 33 deletions
diff --git a/apps/playback.c b/apps/playback.c index f88c7f6d18..02af5b6ec4 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -322,16 +322,6 @@ static void voice_thread(void); | |||
322 | 322 | ||
323 | #endif /* PLAYBACK_VOICE */ | 323 | #endif /* PLAYBACK_VOICE */ |
324 | 324 | ||
325 | /* --- Shared semi-private interfaces --- */ | ||
326 | |||
327 | /* imported */ | ||
328 | extern void talk_buffer_steal(void); | ||
329 | #ifdef HAVE_RECORDING | ||
330 | extern void pcm_rec_error_clear(void); | ||
331 | extern unsigned long pcm_rec_status(void); | ||
332 | #endif | ||
333 | |||
334 | |||
335 | /* --- External interfaces --- */ | 325 | /* --- External interfaces --- */ |
336 | 326 | ||
337 | void mp3_play_data(const unsigned char* start, int size, | 327 | void mp3_play_data(const unsigned char* start, int size, |
@@ -374,12 +364,31 @@ void mpeg_id3_options(bool _v1first) | |||
374 | v1first = _v1first; | 364 | v1first = _v1first; |
375 | } | 365 | } |
376 | 366 | ||
367 | /* If voice could be swapped out - wait for it to return | ||
368 | * Used by buffer claming functions. | ||
369 | */ | ||
370 | static void wait_for_voice_swap_in(void) | ||
371 | { | ||
372 | #ifdef PLAYBACK_VOICE | ||
373 | if (NULL == iram_buf[CODEC_IDX_VOICE]) | ||
374 | return; | ||
375 | |||
376 | while (current_codec != CODEC_IDX_VOICE) | ||
377 | yield(); | ||
378 | #endif /* PLAYBACK_VOICE */ | ||
379 | } | ||
380 | |||
377 | unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size) | 381 | unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size) |
378 | { | 382 | { |
379 | unsigned char *buf, *end; | 383 | unsigned char *buf, *end; |
380 | 384 | ||
381 | if (audio_is_initialized) | 385 | if (audio_is_initialized) |
386 | { | ||
382 | audio_stop(); | 387 | audio_stop(); |
388 | wait_for_voice_swap_in(); | ||
389 | voice_stop(); | ||
390 | } | ||
391 | /* else buffer_state will be BUFFER_STATE_TRASHED at this point */ | ||
383 | 392 | ||
384 | if (buffer_size == NULL) | 393 | if (buffer_size == NULL) |
385 | { | 394 | { |
@@ -388,9 +397,6 @@ unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size) | |||
388 | return NULL; | 397 | return NULL; |
389 | } | 398 | } |
390 | 399 | ||
391 | buf = audiobuf; | ||
392 | end = audiobufend; | ||
393 | |||
394 | if (talk_buf || buffer_state == BUFFER_STATE_TRASHED | 400 | if (talk_buf || buffer_state == BUFFER_STATE_TRASHED |
395 | || !talk_voice_required()) | 401 | || !talk_voice_required()) |
396 | { | 402 | { |
@@ -399,24 +405,18 @@ unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size) | |||
399 | if (buffer_state != BUFFER_STATE_TRASHED) | 405 | if (buffer_state != BUFFER_STATE_TRASHED) |
400 | { | 406 | { |
401 | talk_buffer_steal(); | 407 | talk_buffer_steal(); |
402 | #ifdef PLAYBACK_VOICE | ||
403 | if (NULL != iram_buf[CODEC_IDX_VOICE]) | ||
404 | { | ||
405 | /* Voice could be swapped out - wait for it to return */ | ||
406 | while (current_codec != CODEC_IDX_VOICE) | ||
407 | yield(); | ||
408 | } | ||
409 | #endif /* PLAYBACK_VOICE */ | ||
410 | buffer_state = BUFFER_STATE_TRASHED; | 408 | buffer_state = BUFFER_STATE_TRASHED; |
411 | } | 409 | } |
410 | |||
411 | buf = audiobuf; | ||
412 | end = audiobufend; | ||
412 | } | 413 | } |
413 | else | 414 | else |
414 | { | 415 | { |
415 | /* skip talk buffer and move pcm buffer to end */ | 416 | /* skip talk buffer and move pcm buffer to end */ |
416 | logf("get buffer: voice"); | 417 | logf("get buffer: voice"); |
417 | mp3_play_stop(); | 418 | buf = audiobuf + talk_get_bufsize(); |
418 | buf += talk_get_bufsize(); | 419 | end = audiobufend - pcmbuf_init(pcmbuf_get_bufsize(), audiobufend); |
419 | end -= pcmbuf_init(pcmbuf_get_bufsize(), audiobufend); | ||
420 | buffer_state = BUFFER_STATE_VOICED_ONLY; | 420 | buffer_state = BUFFER_STATE_VOICED_ONLY; |
421 | } | 421 | } |
422 | 422 | ||
@@ -438,10 +438,7 @@ void audio_iram_steal(void) | |||
438 | if (voice_iram_stolen) | 438 | if (voice_iram_stolen) |
439 | return; | 439 | return; |
440 | 440 | ||
441 | /* Wait for voice to swap back in if current codec was audio */ | 441 | wait_for_voice_swap_in(); |
442 | while (current_codec != CODEC_IDX_VOICE) | ||
443 | yield(); | ||
444 | |||
445 | voice_stop(); | 442 | voice_stop(); |
446 | 443 | ||
447 | /* Save voice IRAM - safe to do here since state is known */ | 444 | /* Save voice IRAM - safe to do here since state is known */ |
@@ -466,6 +463,8 @@ unsigned char *audio_get_recording_buffer(size_t *buffer_size) | |||
466 | unsigned char *end; | 463 | unsigned char *end; |
467 | 464 | ||
468 | audio_stop(); | 465 | audio_stop(); |
466 | wait_for_voice_swap_in(); | ||
467 | voice_stop(); | ||
469 | talk_buffer_steal(); | 468 | talk_buffer_steal(); |
470 | 469 | ||
471 | #ifdef PLAYBACK_VOICE | 470 | #ifdef PLAYBACK_VOICE |
@@ -478,7 +477,6 @@ unsigned char *audio_get_recording_buffer(size_t *buffer_size) | |||
478 | #endif /* PLAYBACK_VOICE */ | 477 | #endif /* PLAYBACK_VOICE */ |
479 | end = audiobufend; | 478 | end = audiobufend; |
480 | 479 | ||
481 | |||
482 | buffer_state = BUFFER_STATE_TRASHED; | 480 | buffer_state = BUFFER_STATE_TRASHED; |
483 | 481 | ||
484 | *buffer_size = end - audiobuf; | 482 | *buffer_size = end - audiobuf; |
diff --git a/apps/talk.c b/apps/talk.c index cabc93576b..107cb72e6e 100644 --- a/apps/talk.c +++ b/apps/talk.c | |||
@@ -559,7 +559,9 @@ int talk_get_bufsize(void) | |||
559 | /* somebody else claims the mp3 buffer, e.g. for regular play/record */ | 559 | /* somebody else claims the mp3 buffer, e.g. for regular play/record */ |
560 | int talk_buffer_steal(void) | 560 | int talk_buffer_steal(void) |
561 | { | 561 | { |
562 | #if CONFIG_CODEC != SWCODEC | ||
562 | mp3_play_stop(); | 563 | mp3_play_stop(); |
564 | #endif | ||
563 | #ifdef HAVE_MMC | 565 | #ifdef HAVE_MMC |
564 | if (filehandle >= 0) /* only relevant for MMC */ | 566 | if (filehandle >= 0) /* only relevant for MMC */ |
565 | { | 567 | { |
diff --git a/apps/talk.h b/apps/talk.h index 4c1ef7c625..e863a3d25b 100644 --- a/apps/talk.h +++ b/apps/talk.h | |||
@@ -62,9 +62,8 @@ extern const char* const file_thumbnail_ext; /* ".talk" for file voicing */ | |||
62 | void talk_init(void); | 62 | void talk_init(void); |
63 | bool talk_voice_required(void); /* returns true if voice codec required */ | 63 | bool talk_voice_required(void); /* returns true if voice codec required */ |
64 | int talk_get_bufsize(void); /* get the loaded voice file size */ | 64 | int talk_get_bufsize(void); /* get the loaded voice file size */ |
65 | #if CONFIG_CODEC != SWCODEC | 65 | /* talk_buffer_steal - on SWCODEC, for use by buffer functions only */ |
66 | int talk_buffer_steal(void); /* claim the mp3 buffer e.g. for play/record */ | 66 | int talk_buffer_steal(void); /* claim the mp3 buffer e.g. for play/record */ |
67 | #endif | ||
68 | int talk_id(long id, bool enqueue); /* play a voice ID from voicefont */ | 67 | int talk_id(long id, bool enqueue); /* play a voice ID from voicefont */ |
69 | int talk_file(const char* filename, bool enqueue); /* play a thumbnail from file */ | 68 | int talk_file(const char* filename, bool enqueue); /* play a thumbnail from file */ |
70 | int talk_number(long n, bool enqueue); /* say a number */ | 69 | int talk_number(long n, bool enqueue); /* say a number */ |
diff --git a/firmware/export/pcm_record.h b/firmware/export/pcm_record.h index 84db80680d..38ec202cdc 100644 --- a/firmware/export/pcm_record.h +++ b/firmware/export/pcm_record.h | |||
@@ -47,10 +47,10 @@ void pcm_calculate_rec_peaks(int *left, int *right); | |||
47 | /** General functions for high level codec recording **/ | 47 | /** General functions for high level codec recording **/ |
48 | /* pcm_rec_error_clear is deprecated for general use. audio_error_clear | 48 | /* pcm_rec_error_clear is deprecated for general use. audio_error_clear |
49 | should be used */ | 49 | should be used */ |
50 | /* void pcm_rec_error_clear(void); */ | 50 | void pcm_rec_error_clear(void); |
51 | /* pcm_rec_status is deprecated for general use. audio_status merges the | 51 | /* pcm_rec_status is deprecated for general use. audio_status merges the |
52 | results for consistency with the hardware codec version */ | 52 | results for consistency with the hardware codec version */ |
53 | /* unsigned long pcm_rec_status(void); */ | 53 | unsigned long pcm_rec_status(void); |
54 | void pcm_rec_init(void); | 54 | void pcm_rec_init(void); |
55 | int pcm_rec_current_bitrate(void); | 55 | int pcm_rec_current_bitrate(void); |
56 | int pcm_rec_encoder_afmt(void); /* AFMT_* value, AFMT_UNKNOWN if none */ | 56 | int pcm_rec_encoder_afmt(void); /* AFMT_* value, AFMT_UNKNOWN if none */ |