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
This commit is contained in:
Michael Sevakis 2006-11-28 15:00:56 +00:00
parent 9be9767a49
commit 97d1ca5a23
4 changed files with 32 additions and 33 deletions

View file

@ -322,16 +322,6 @@ static void voice_thread(void);
#endif /* PLAYBACK_VOICE */ #endif /* PLAYBACK_VOICE */
/* --- Shared semi-private interfaces --- */
/* imported */
extern void talk_buffer_steal(void);
#ifdef HAVE_RECORDING
extern void pcm_rec_error_clear(void);
extern unsigned long pcm_rec_status(void);
#endif
/* --- External interfaces --- */ /* --- External interfaces --- */
void mp3_play_data(const unsigned char* start, int size, void mp3_play_data(const unsigned char* start, int size,
@ -374,12 +364,31 @@ void mpeg_id3_options(bool _v1first)
v1first = _v1first; v1first = _v1first;
} }
/* If voice could be swapped out - wait for it to return
* Used by buffer claming functions.
*/
static void wait_for_voice_swap_in(void)
{
#ifdef PLAYBACK_VOICE
if (NULL == iram_buf[CODEC_IDX_VOICE])
return;
while (current_codec != CODEC_IDX_VOICE)
yield();
#endif /* PLAYBACK_VOICE */
}
unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size) unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size)
{ {
unsigned char *buf, *end; unsigned char *buf, *end;
if (audio_is_initialized) if (audio_is_initialized)
{
audio_stop(); audio_stop();
wait_for_voice_swap_in();
voice_stop();
}
/* else buffer_state will be BUFFER_STATE_TRASHED at this point */
if (buffer_size == NULL) if (buffer_size == NULL)
{ {
@ -388,9 +397,6 @@ unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size)
return NULL; return NULL;
} }
buf = audiobuf;
end = audiobufend;
if (talk_buf || buffer_state == BUFFER_STATE_TRASHED if (talk_buf || buffer_state == BUFFER_STATE_TRASHED
|| !talk_voice_required()) || !talk_voice_required())
{ {
@ -399,24 +405,18 @@ unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size)
if (buffer_state != BUFFER_STATE_TRASHED) if (buffer_state != BUFFER_STATE_TRASHED)
{ {
talk_buffer_steal(); talk_buffer_steal();
#ifdef PLAYBACK_VOICE
if (NULL != iram_buf[CODEC_IDX_VOICE])
{
/* Voice could be swapped out - wait for it to return */
while (current_codec != CODEC_IDX_VOICE)
yield();
}
#endif /* PLAYBACK_VOICE */
buffer_state = BUFFER_STATE_TRASHED; buffer_state = BUFFER_STATE_TRASHED;
} }
buf = audiobuf;
end = audiobufend;
} }
else else
{ {
/* skip talk buffer and move pcm buffer to end */ /* skip talk buffer and move pcm buffer to end */
logf("get buffer: voice"); logf("get buffer: voice");
mp3_play_stop(); buf = audiobuf + talk_get_bufsize();
buf += talk_get_bufsize(); end = audiobufend - pcmbuf_init(pcmbuf_get_bufsize(), audiobufend);
end -= pcmbuf_init(pcmbuf_get_bufsize(), audiobufend);
buffer_state = BUFFER_STATE_VOICED_ONLY; buffer_state = BUFFER_STATE_VOICED_ONLY;
} }
@ -438,10 +438,7 @@ void audio_iram_steal(void)
if (voice_iram_stolen) if (voice_iram_stolen)
return; return;
/* Wait for voice to swap back in if current codec was audio */ wait_for_voice_swap_in();
while (current_codec != CODEC_IDX_VOICE)
yield();
voice_stop(); voice_stop();
/* Save voice IRAM - safe to do here since state is known */ /* 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)
unsigned char *end; unsigned char *end;
audio_stop(); audio_stop();
wait_for_voice_swap_in();
voice_stop();
talk_buffer_steal(); talk_buffer_steal();
#ifdef PLAYBACK_VOICE #ifdef PLAYBACK_VOICE
@ -478,7 +477,6 @@ unsigned char *audio_get_recording_buffer(size_t *buffer_size)
#endif /* PLAYBACK_VOICE */ #endif /* PLAYBACK_VOICE */
end = audiobufend; end = audiobufend;
buffer_state = BUFFER_STATE_TRASHED; buffer_state = BUFFER_STATE_TRASHED;
*buffer_size = end - audiobuf; *buffer_size = end - audiobuf;

View file

@ -559,7 +559,9 @@ int talk_get_bufsize(void)
/* somebody else claims the mp3 buffer, e.g. for regular play/record */ /* somebody else claims the mp3 buffer, e.g. for regular play/record */
int talk_buffer_steal(void) int talk_buffer_steal(void)
{ {
#if CONFIG_CODEC != SWCODEC
mp3_play_stop(); mp3_play_stop();
#endif
#ifdef HAVE_MMC #ifdef HAVE_MMC
if (filehandle >= 0) /* only relevant for MMC */ if (filehandle >= 0) /* only relevant for MMC */
{ {

View file

@ -62,9 +62,8 @@ extern const char* const file_thumbnail_ext; /* ".talk" for file voicing */
void talk_init(void); void talk_init(void);
bool talk_voice_required(void); /* returns true if voice codec required */ bool talk_voice_required(void); /* returns true if voice codec required */
int talk_get_bufsize(void); /* get the loaded voice file size */ int talk_get_bufsize(void); /* get the loaded voice file size */
#if CONFIG_CODEC != SWCODEC /* talk_buffer_steal - on SWCODEC, for use by buffer functions only */
int talk_buffer_steal(void); /* claim the mp3 buffer e.g. for play/record */ int talk_buffer_steal(void); /* claim the mp3 buffer e.g. for play/record */
#endif
int talk_id(long id, bool enqueue); /* play a voice ID from voicefont */ int talk_id(long id, bool enqueue); /* play a voice ID from voicefont */
int talk_file(const char* filename, bool enqueue); /* play a thumbnail from file */ int talk_file(const char* filename, bool enqueue); /* play a thumbnail from file */
int talk_number(long n, bool enqueue); /* say a number */ int talk_number(long n, bool enqueue); /* say a number */

View file

@ -47,10 +47,10 @@ void pcm_calculate_rec_peaks(int *left, int *right);
/** General functions for high level codec recording **/ /** General functions for high level codec recording **/
/* pcm_rec_error_clear is deprecated for general use. audio_error_clear /* pcm_rec_error_clear is deprecated for general use. audio_error_clear
should be used */ should be used */
/* void pcm_rec_error_clear(void); */ void pcm_rec_error_clear(void);
/* pcm_rec_status is deprecated for general use. audio_status merges the /* pcm_rec_status is deprecated for general use. audio_status merges the
results for consistency with the hardware codec version */ results for consistency with the hardware codec version */
/* unsigned long pcm_rec_status(void); */ unsigned long pcm_rec_status(void);
void pcm_rec_init(void); void pcm_rec_init(void);
int pcm_rec_current_bitrate(void); int pcm_rec_current_bitrate(void);
int pcm_rec_encoder_afmt(void); /* AFMT_* value, AFMT_UNKNOWN if none */ int pcm_rec_encoder_afmt(void); /* AFMT_* value, AFMT_UNKNOWN if none */