From 286a4c5caa1945c8d1cb365a3d90fb09d5700cb2 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Thu, 23 Feb 2012 08:14:46 -0500 Subject: Revise the PCM callback system after adding multichannel audio. Additional status callback is added to pcm_play/rec_data instead of using a special function to set it. Status includes DMA error reporting to the status callback. Playback and recording callback become more alike except playback uses "const void **addr" (because the data should not be altered) and recording uses "void **addr". "const" is put in place throughout where appropriate. Most changes are fairly trivial. One that should be checked in particular because it isn't so much is telechips, if anyone cares to bother. PP5002 is not so trivial either but that tested as working. Change-Id: I4928d69b3b3be7fb93e259f81635232df9bd1df2 Reviewed-on: http://gerrit.rockbox.org/166 Reviewed-by: Michael Sevakis Tested-by: Michael Sevakis --- firmware/target/hosted/sdl/pcm-sdl.c | 66 ++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'firmware/target/hosted/sdl') diff --git a/firmware/target/hosted/sdl/pcm-sdl.c b/firmware/target/hosted/sdl/pcm-sdl.c index 020928d572..2c535b2dc5 100644 --- a/firmware/target/hosted/sdl/pcm-sdl.c +++ b/firmware/target/hosted/sdl/pcm-sdl.c @@ -56,7 +56,7 @@ static int sim_volume = 0; #if CONFIG_CODEC == SWCODEC static int cvt_status = -1; -static Uint8* pcm_data; +static const Uint8* pcm_data; static size_t pcm_data_size; static size_t pcm_sample_bytes; static size_t pcm_channel_bytes; @@ -109,7 +109,7 @@ void pcm_play_dma_start(const void *addr, size_t size) { pcm_dma_apply_settings_nolock(); - pcm_data = (Uint8 *) addr; + pcm_data = addr; pcm_data_size = size; SDL_PauseAudio(0); @@ -245,48 +245,48 @@ static void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len) /* Audio card wants more? Get some more then. */ while (len > 0) { - new_buffer = true; - pcm_play_get_more_callback((void **)&pcm_data, &pcm_data_size); + new_buffer = pcm_play_dma_complete_callback(PCM_DMAST_OK, + (const void **)&pcm_data, &pcm_data_size); + + if (!new_buffer) { + DEBUGF("sdl_audio_callback: No Data.\n"); + break; + } + start: - if (pcm_data_size != 0) { - udata->num_in = pcm_data_size / pcm_sample_bytes; - udata->num_out = len / pcm_sample_bytes; + udata->num_in = pcm_data_size / pcm_sample_bytes; + udata->num_out = len / pcm_sample_bytes; - write_to_soundcard(udata); + write_to_soundcard(udata); - udata->num_in *= pcm_sample_bytes; - udata->num_out *= pcm_sample_bytes; + udata->num_in *= pcm_sample_bytes; + udata->num_out *= pcm_sample_bytes; + if (new_buffer) + { + new_buffer = false; + pcm_play_dma_status_callback(PCM_DMAST_STARTED); - if (new_buffer) + if ((size_t)len > udata->num_out) { - new_buffer = false; - pcm_play_dma_started_callback(); + int delay = pcm_data_size*250 / pcm_sampr - 1; - if ((size_t)len > udata->num_out) + if (delay > 0) { - int delay = pcm_data_size*250 / pcm_sampr - 1; - - if (delay > 0) - { - SDL_UnlockMutex(audio_lock); - SDL_Delay(delay); - SDL_LockMutex(audio_lock); - - if (!pcm_is_playing()) - break; - } + SDL_UnlockMutex(audio_lock); + SDL_Delay(delay); + SDL_LockMutex(audio_lock); + + if (!pcm_is_playing()) + break; } } - - pcm_data += udata->num_in; - pcm_data_size -= udata->num_in; - udata->stream += udata->num_out; - len -= udata->num_out; - } else { - DEBUGF("sdl_audio_callback: No Data.\n"); - break; } + + pcm_data += udata->num_in; + pcm_data_size -= udata->num_in; + udata->stream += udata->num_out; + len -= udata->num_out; } SDL_UnlockMutex(audio_lock); -- cgit v1.2.3