summaryrefslogtreecommitdiffstats
path: root/firmware/pcm_mixer.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/pcm_mixer.c')
-rw-r--r--firmware/pcm_mixer.c28
1 files changed, 27 insertions, 1 deletions
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)
{