From 39eec730b055a21d284c73095cbc42c4e4f56787 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Fri, 17 Feb 2012 03:54:45 -0500 Subject: [PATCH] PCM mixer: Simplify mixer_channel_play_data. Streamline it to do fewer PCM lock calls in the case of having a prepared buffer. Change-Id: I7fca2b95cc5da314ae257522bb6f1ad7aec6634a --- firmware/pcm_mixer.c | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/firmware/pcm_mixer.c b/firmware/pcm_mixer.c index 0038b0f5e7..fcd9a1c4fd 100644 --- a/firmware/pcm_mixer.c +++ b/firmware/pcm_mixer.c @@ -256,26 +256,31 @@ static void mixer_start_pcm(void) pcm_play_data(mixer_pcm_callback, start, MIX_FRAME_SIZE); } -/* Initialize the channel and start it if it has data */ -static void mixer_channel_play_start(struct mixer_channel *chan, - pcm_play_callback_type get_more, - unsigned char *start, size_t size) +/** Public interfaces **/ + +/* Start playback on a channel */ +void mixer_channel_play_data(enum pcm_mixer_channel channel, + pcm_play_callback_type get_more, + unsigned char *start, size_t size) { - pcm_play_unlock(); /* Allow playback while doing any callback */ + struct mixer_channel *chan = &channels[channel]; ALIGN_AUDIOBUF(start, size); - if (!(start && size)) + if (!(start && size) && get_more) { /* Initial buffer not passed - call the callback now */ + pcm_play_lock(); + mixer_deactivate_channel(chan); /* Protect chan struct if active */ + pcm_play_unlock(); /* Allow playback while doing callback */ + size = 0; - if (get_more) - { - get_more(&start, &size); - ALIGN_AUDIOBUF(start, size); - } + get_more(&start, &size); + ALIGN_AUDIOBUF(start, size); } + pcm_play_lock(); + if (start && size) { /* We have data - start the channel */ @@ -285,31 +290,15 @@ static void mixer_channel_play_start(struct mixer_channel *chan, chan->last_size = 0; chan->get_more = get_more; - pcm_play_lock(); mixer_activate_channel(chan); mixer_start_pcm(); } else { /* Never had anything - stop it now */ - pcm_play_lock(); channel_stopped(chan); } -} - -/** Public interfaces **/ - -/* Start playback on a channel */ -void mixer_channel_play_data(enum pcm_mixer_channel channel, - pcm_play_callback_type get_more, - unsigned char *start, size_t size) -{ - struct mixer_channel *chan = &channels[channel]; - - pcm_play_lock(); - mixer_deactivate_channel(chan); - mixer_channel_play_start(chan, get_more, start, size); pcm_play_unlock(); }