From 5663e1cd0afc62e212c43c8fb374c791d554fb1b Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Fri, 8 Jul 2011 22:31:15 +0000 Subject: Have mpegplayer use the mixer (the playback channel, since it's mutually exclusive to audio playback) so the clicks and skip beep can be used according to user settings. Introduce some system sound functions to make easier playing event sounds from various places and convert files calling 'beep_play' to use 'system_sound_play' and 'keyclick_click'. Event sound could be become themeable. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30130 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/mpegplayer/pcm_output.c | 65 +++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 30 deletions(-) (limited to 'apps/plugins/mpegplayer/pcm_output.c') diff --git a/apps/plugins/mpegplayer/pcm_output.c b/apps/plugins/mpegplayer/pcm_output.c index fb7ff434aa..8db9531049 100644 --- a/apps/plugins/mpegplayer/pcm_output.c +++ b/apps/plugins/mpegplayer/pcm_output.c @@ -23,6 +23,9 @@ #include "plugin.h" #include "mpegplayer.h" +/* PCM channel we're using */ +#define MPEG_PCM_CHANNEL PCM_MIXER_CHAN_PLAYBACK + /* Pointers */ /* Start of buffer */ @@ -217,24 +220,22 @@ bool pcm_output_empty(void) /* Flushes the buffer - clock keeps counting */ void pcm_output_flush(void) { - bool playing, paused; - rb->pcm_play_lock(); - playing = rb->pcm_is_playing(); - paused = rb->pcm_is_paused(); + enum channel_status status = rb->mixer_channel_status(MPEG_PCM_CHANNEL); /* Stop PCM to clear current buffer */ - if (playing) - rb->pcm_play_stop(); + if (status != CHANNEL_STOPPED) + rb->mixer_channel_stop(MPEG_PCM_CHANNEL); + + rb->pcm_play_unlock(); pcm_reset_buffer(); /* Restart if playing state was current */ - if (playing && !paused) - rb->pcm_play_data(get_more, NULL, 0); - - rb->pcm_play_unlock(); + if (status == CHANNEL_PLAYING) + rb->mixer_channel_play_data(MPEG_PCM_CHANNEL, + get_more, NULL, 0); } /* Seek the reference clock to the specified time - next audio data ready to @@ -264,10 +265,12 @@ uint32_t pcm_output_get_clock(void) do { time = clock_time; - rem = rb->pcm_get_bytes_waiting() >> 2; + rem = rb->mixer_channel_get_bytes_waiting(MPEG_PCM_CHANNEL) >> 2; } while (UNLIKELY(time != clock_time || - (rem == 0 && rb->pcm_is_playing() && !rb->pcm_is_paused()))); + (rem == 0 && + rb->mixer_channel_status(MPEG_PCM_CHANNEL) == CHANNEL_PLAYING)) + ); return time - rem; @@ -283,10 +286,12 @@ uint32_t pcm_output_get_ticks(uint32_t *start) do { tick = clock_tick; - rem = rb->pcm_get_bytes_waiting() >> 2; + rem = rb->mixer_channel_get_bytes_waiting(MPEG_PCM_CHANNEL) >> 2; } while (UNLIKELY(tick != clock_tick || - (rem == 0 && rb->pcm_is_playing() && !rb->pcm_is_paused()))); + (rem == 0 && + rb->mixer_channel_status(MPEG_PCM_CHANNEL) == CHANNEL_PLAYING)) + ); if (start) *start = clock_start; @@ -299,16 +304,22 @@ void pcm_output_play_pause(bool play) { rb->pcm_play_lock(); - if (rb->pcm_is_playing()) + if (rb->mixer_channel_status(MPEG_PCM_CHANNEL) != CHANNEL_STOPPED) { - rb->pcm_play_pause(play); + rb->mixer_channel_play_pause(MPEG_PCM_CHANNEL, play); + rb->pcm_play_unlock(); } - else if (play) + else { - rb->pcm_play_data(get_more, NULL, 0); - } + rb->pcm_play_unlock(); - rb->pcm_play_unlock(); + if (play) + { + rb->mixer_channel_set_amplitude(MPEG_PCM_CHANNEL, MIX_AMP_UNITY); + rb->mixer_channel_play_data(MPEG_PCM_CHANNEL, + get_more, NULL, 0); + } + } } /* Stops all playback and resets the clock */ @@ -316,13 +327,13 @@ void pcm_output_stop(void) { rb->pcm_play_lock(); - if (rb->pcm_is_playing()) - rb->pcm_play_stop(); + if (rb->mixer_channel_status(MPEG_PCM_CHANNEL) != CHANNEL_STOPPED) + rb->mixer_channel_stop(MPEG_PCM_CHANNEL); + + rb->pcm_play_unlock(); pcm_output_flush(); pcm_output_set_clock(0); - - rb->pcm_play_unlock(); } /* Drains any data if the start threshold hasn't been reached */ @@ -343,11 +354,6 @@ bool pcm_output_init(void) pcm_reset_buffer(); - /* Some targets could play at the movie frequency without resampling but - * as of now DSP assumes a certain frequency (always 44100Hz) so - * resampling will be needed for other movie audio rates. */ - rb->pcm_set_frequency(NATIVE_FREQUENCY); - #if INPUT_SRC_CAPS != 0 /* Select playback */ rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); @@ -379,5 +385,4 @@ bool pcm_output_init(void) void pcm_output_exit(void) { - rb->pcm_set_frequency(HW_SAMPR_DEFAULT); } -- cgit v1.2.3