From 22b6def065ab7c2ca030f405577e34104ad20011 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Sat, 2 Jul 2011 11:55:38 +0000 Subject: Use playback channel directly for peakmeters and plugins using peak calculation. Also, for now, don't allow mixer playback to overlap recording, even if full duplex works. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30119 a1c6a512-1295-4272-9138-f99709370657 --- firmware/pcm_mixer.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'firmware/pcm_mixer.c') diff --git a/firmware/pcm_mixer.c b/firmware/pcm_mixer.c index 69a43cfbda..c84762938e 100644 --- a/firmware/pcm_mixer.c +++ b/firmware/pcm_mixer.c @@ -23,6 +23,7 @@ #include "general.h" #include "kernel.h" #include "pcm.h" +#include "pcm-internal.h" #include "pcm_mixer.h" #include "dsp.h" @@ -59,6 +60,9 @@ static size_t next_size = 0; /* Size of buffer to play next time */ /* Descriptors for all available channels */ static struct mixer_channel channels[PCM_MIXER_NUM_CHANNELS] IBSS_ATTR; +/* History for channel peaks */ +static struct pcm_peaks channel_peaks[PCM_MIXER_NUM_CHANNELS]; + /* Packed pointer array of all playing (active) channels in "channels" array */ static struct mixer_channel * active_channels[PCM_MIXER_NUM_CHANNELS+1] IBSS_ATTR; @@ -343,11 +347,14 @@ static void mixer_start_pcm(void) if (pcm_is_playing()) return; -#if defined(HAVE_RECORDING) && !defined(HAVE_PCM_FULL_DUPLEX) +#if defined(HAVE_RECORDING) if (pcm_is_recording()) return; #endif + /* Requires a shared global sample rate for all channels */ + pcm_set_frequency(NATIVE_FREQUENCY); + /* Prepare initial frames and set up the double buffer */ mixer_buffer_callback(); @@ -492,6 +499,25 @@ void * mixer_channel_get_buffer(enum pcm_mixer_channel channel, int *count) return NULL; } +/* Calculate peak values for channel */ +void mixer_channel_calculate_peaks(enum pcm_mixer_channel channel, + int *left, int *right) +{ + struct mixer_channel *chan = &channels[channel]; + struct pcm_peaks *peaks = &channel_peaks[channel]; + int count; + const void *addr = mixer_channel_get_buffer(channel, &count); + + pcm_do_peak_calculation(peaks, chan->status == CHANNEL_PLAYING, + addr, count); + + if (left) + *left = peaks->val[0]; + + if (right) + *right = peaks->val[1]; +} + /* Stop ALL channels and PCM and reset state */ void mixer_reset(void) { -- cgit