From d54ce9b784ef1bba22c075b281bb877abf53ea18 Mon Sep 17 00:00:00 2001 From: Dr John Vidler Date: Mon, 13 Nov 2023 12:37:49 +0000 Subject: [PATCH] Added a new CONFIG_MIXER_DEFAULT_CHANNEL_SAMPLERATE constant for channels with no defined rate to use --- inc/Mixer2.h | 11 ++++++++++- source/MicroBitAudio.cpp | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/inc/Mixer2.h b/inc/Mixer2.h index c07f01a1..49828f9c 100644 --- a/inc/Mixer2.h +++ b/inc/Mixer2.h @@ -39,6 +39,15 @@ DEALINGS IN THE SOFTWARE. #define CONFIG_MIXER_DEFAULT_SAMPLERATE 44100 #endif +// The default sample rate, for when the user does not supply us with anything +// This applies to both ADC input rates and mixer output rates. +// +// This is distinct from CONFIG_MIXER_DEFAULT_SAMPLERATE which sets the mixer's absolute maximum rate +// whereas this is simply the 'normal' operating rate for audio peripherals. +#ifndef CONFIG_MIXER_DEFAULT_CHANNEL_SAMPLERATE +#define CONFIG_MIXER_DEFAULT_CHANNEL_SAMPLERATE 11000 +#endif + #define DEVICE_ID_MIXER 3030 #define DEVICE_MIXER_EVT_SILENCE 1 @@ -156,7 +165,7 @@ class Mixer2 : public DataSource * @param sampleRate (samples per second) - if set to zero, defaults to the output sample rate of the Mixer * @param sampleRange (quantization levels) the difference between the maximum and minimum sample level on the input channel */ - MixerChannel *addChannel(DataSource &stream, float sampleRate = 0, int sampleRange = CONFIG_MIXER_INTERNAL_RANGE); + MixerChannel *addChannel(DataSource &stream, float sampleRate = CONFIG_MIXER_DEFAULT_CHANNEL_SAMPLERATE, int sampleRange = CONFIG_MIXER_INTERNAL_RANGE); /** * Removes a channel from the mixer diff --git a/source/MicroBitAudio.cpp b/source/MicroBitAudio.cpp index b5543846..e1ba10d3 100644 --- a/source/MicroBitAudio.cpp +++ b/source/MicroBitAudio.cpp @@ -57,7 +57,7 @@ MicroBitAudio::MicroBitAudio(NRF52Pin &pin, NRF52Pin &speaker, NRF52ADC &adc, NR synth.allowEmptyBuffers(true); mic = adc.getChannel(microphone, false); - adc.setSamplePeriod( 1e6 / 11000 ); + adc.setSamplePeriod( 1e6 / CONFIG_MIXER_DEFAULT_CHANNEL_SAMPLERATE ); mic->setGain(7, 0); // Implementers note: The order that the pipeline comes up here is quite sensitive. If we connect up to splitters after starting to