path: root/firmware/pcm_mixer.c
diff options
authorMichael Sevakis <>2013-05-23 13:58:51 -0400
committerMichael Sevakis <>2013-07-06 04:22:04 +0200
commitd37bf24d9011addbfbd40942a4e9bbf26de7df00 (patch)
treedafb7eaeb494081668a4841d490fce2bfbb2438d /firmware/pcm_mixer.c
parent00faabef5e902008172e08d3bcd77683cbafef51 (diff)
Enable setting of global output samplerate on certain targets.
Replaces the NATIVE_FREQUENCY constant with a configurable frequency. The user may select 48000Hz if the hardware supports it. The default is still 44100Hz and the minimum is 44100Hz. The setting is located in the playback settings, under "Frequency". "Frequency" was duplicated in english.lang for now to avoid having to fix every .lang file for the moment and throwing everything out of sync because of the new play_frequency feature in features.txt. The next cleanup should combine it with the one included for recording and generalize the ID label. If the hardware doesn't support 48000Hz, no setting will be available. On particular hardware where very high rates are practical and desireable, the upper bound can be extended by patching. The PCM mixer can be configured to play at the full hardware frequency range. The DSP core can configure to the hardware minimum up to the maximum playback setting (some buffers must be reserved according to the maximum rate). If only 44100Hz is supported or possible on a given target for playback, using the DSP and mixer at other samperates is possible if the hardware offers them. Change-Id: I6023cf0c0baa8bc6292b6919b4dd3618a6a25622 Reviewed-on: Reviewed-by: Michael Sevakis <> Tested-by: Michael Sevakis <>
Diffstat (limited to 'firmware/pcm_mixer.c')
1 files changed, 24 insertions, 3 deletions
diff --git a/firmware/pcm_mixer.c b/firmware/pcm_mixer.c
index 34852e97e9..ceba31962e 100644
--- a/firmware/pcm_mixer.c
+++ b/firmware/pcm_mixer.c
@@ -25,7 +25,6 @@
#include "pcm.h"
#include "pcm-internal.h"
#include "pcm_mixer.h"
-#include "dsp_core.h" /* For NATIVE_FREQUENCY */
/* Channels use standard-style PCM callback interface but a latency of one
frame by double-buffering is introduced in order to facilitate mixing and
@@ -33,6 +32,8 @@
before the last samples are sent to the codec and so things are done in
parallel (as much as possible) with sending-out data. */
+static unsigned int mixer_sampr = HW_SAMPR_DEFAULT;
/* Define this to nonzero to add a marker pulse at each frame start */
@@ -65,7 +66,7 @@ static struct mixer_channel channels[PCM_MIXER_NUM_CHANNELS] IBSS_ATTR;
static struct mixer_channel * active_channels[PCM_MIXER_NUM_CHANNELS+1] IBSS_ATTR;
/* Number of silence frames to play after all data has played */
+#define MAX_IDLE_FRAMES (mixer_sampr*3 / MIX_FRAME_SAMPLES)
static unsigned int idle_counter = 0;
/** Mixing routines, CPU optmized **/
@@ -256,7 +257,7 @@ static void mixer_start_pcm(void)
/* Requires a shared global sample rate for all channels */
- pcm_set_frequency(NATIVE_FREQUENCY);
+ pcm_set_frequency(mixer_sampr);
/* Prepare initial frames and set up the double buffer */
@@ -438,3 +439,23 @@ void mixer_reset(void)
idle_counter = 0;
+/* Set output samplerate */
+void mixer_set_frequency(unsigned int samplerate)
+ pcm_set_frequency(samplerate);
+ samplerate = pcm_get_frequency();
+ if (samplerate == mixer_sampr)
+ return;
+ /* All data is now invalid */
+ mixer_reset();
+ mixer_sampr = samplerate;
+/* Get output samplerate */
+unsigned int mixer_get_frequency(void)
+ return mixer_sampr;