From fe17896b118541e3db5f4bd8982b2d07f3285a05 Mon Sep 17 00:00:00 2001 From: tomcombriat Date: Fri, 18 Apr 2025 19:16:13 +0200 Subject: [PATCH 1/9] Initial changes to CircularBuffer for smaller buffer sizes Typo --- CircularBuffer.h | 62 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/CircularBuffer.h b/CircularBuffer.h index e8c164a5b..d6983c465 100644 --- a/CircularBuffer.h +++ b/CircularBuffer.h @@ -14,11 +14,36 @@ Modified from https://en.wikipedia.org/wiki/Circular_buffer Mirroring version On 18 April 2014, the simplified version on the Wikipedia page for power of 2 sized buffers doesn't work - cbIsEmpty() returns true whether the buffer is full or empty. + +April 2025: modified for different buffer sizes under the suggestion +of Meebleeps (https://github.com/sensorium/Mozzi/issues/281) */ -#define MOZZI_BUFFER_SIZE 256 // do not expect to change and it to work. - // just here for forward compatibility if one day - // the buffer size might be editable +// TODO: remove this define from here, put a default value in config +#define MOZZI_BUFFER_SIZE 256 + +// This is to get the correct cound for audioticks() +#if (MOZZI_BUFFER_SIZE == 256) +#define COUNT_LSHIFT 8 +#elif (MOZZI_BUFFER_SIZE == 128) +#define COUNT_LSHIFT 7 +#elif (MOZZI_BUFFER_SIZE == 64) +#define COUNT_LSHIFT 6 +#elif (MOZZI_BUFFER_SIZE == 32) +#define COUNT_LSHIFT 5 +#elif (MOZZI_BUFFER_SIZE == 16) +#define COUNT_LSHIFT 4 +#elif (MOZZI_BUFFER_SIZE == 8) +#define COUNT_LSHIFT 3 +#elif (MOZZI_BUFFER_SIZE == 4) +#define COUNT_LSHIFT 2 +#elif (MOZZI_BUFFER_SIZE == 2) +#define COUNT_LSHIFT 1 +#elif (MOZZI_BUFFER_SIZE == 1) +#define COUNT_LSHIFT 0 +#endif + + /** Circular buffer object. Has a fixed number of cells, set to 256. @tparam ITEM_TYPE the kind of data to store, eg. int, int8_t etc. @@ -60,7 +85,7 @@ class CircularBuffer inline unsigned long count() { - return (num_buffers_read << 8) + start; + return (num_buffers_read << COUNT_LSHIFT) + start; } inline ITEM_TYPE * address() { @@ -75,7 +100,7 @@ class CircularBuffer uint8_t e_msb; unsigned long num_buffers_read; - +#if (CIRCULAR_BUFFER_SIZE == 256) inline void cbIncrStart() { start++; @@ -90,5 +115,32 @@ class CircularBuffer end++; if (end == 0) e_msb ^= 1; } +#else // if circular buffer length is != 256, use less efficient version for to manage start/end index buffer index + inline + void cbIncrStart() { + start++; + if (start == CIRCULAR_BUFFER_SIZE) + { + start = 0; + s_msb ^= 1; + num_buffers_read++; + } + } + + inline + void cbIncrEnd() + { + end++; + if (end == CIRCULAR_BUFFER_SIZE) + { + end = 0; + e_msb ^= 1; + } + } +#endif + }; + + +#undef COUNT_LSHIFT // avoid macro spil From 98e9cc77026729065362d8003758c64767c6f95b Mon Sep 17 00:00:00 2001 From: tomcombriat Date: Fri, 18 Apr 2025 19:16:36 +0200 Subject: [PATCH 2/9] Started documentation of MOZZI_BUFFER_SIZE --- config/mozzi_config_documentation.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/config/mozzi_config_documentation.h b/config/mozzi_config_documentation.h index fc5b1c9f0..a7172db9d 100644 --- a/config/mozzi_config_documentation.h +++ b/config/mozzi_config_documentation.h @@ -249,6 +249,23 @@ * */ #define MOZZI_AUDIO_PIN_1 FOR_DOXYGEN_ONLY +/** @ingroup config + * @def MOZZI_BUFFER_SIZE + * + * @brief Audio buffer setting. + * + * For a lot of outputting modes, Mozzi is buffering the audio samples in order to be able to coop with varying loads on the processor. + * The bigger the buffer, the more able Mozzi will be to coop with big change of processor loads as the buffered values can compensate for that. + * At the same time, a bigger buffer produces a bigger latency as the time between when Mozzi produces the sample and the time it is actually outputted increases. For instance, for a long time Mozzi's buffer size was of a fixed size of 256. This produces a potential latency of 15.6 ms for a MOZZI_AUDIO_RATE of 16384, and half this value for a MOZZI_AUDIO_RATE of 32768. + * Depending on the application, this is usually not a problem but can lead to synchronisation issues in some cases (for instance when working with clocks). + * MOZZI_BUFFER_SIZE can be reduced to smaller values with this config, leading to more accurate timings but potentially to glitches if the buffer runs low. + * Valid values are power of two from 256 downward (128, 64, …). + * Note that this might not have an effect in all modes/platforms combination as Mozzi is sometimes using an external buffer which is not always configurable. + * + * TODO: Throw a warning if config does not have an effect +*/ +#define MOZZI_BUFFER_SIZE FOR_DOXYGEN_ONLY + /***************************************** ADVANCED SETTTINGS -- External audio output ****************************************** * From 1c469114c51f3b20e4b42d74b692a16bf52ef248 Mon Sep 17 00:00:00 2001 From: tomcombriat Date: Fri, 18 Apr 2025 19:39:04 +0200 Subject: [PATCH 3/9] Changed MOZZI_BUFFER_SIZE to MOZZI_OUTPUT_BUFFER_SIZE --- CircularBuffer.h | 30 ++++++++++++++--------------- config/mozzi_config_documentation.h | 6 +++--- internal/MozziGuts_impl_RENESAS.hpp | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/CircularBuffer.h b/CircularBuffer.h index d6983c465..0fd0d2aba 100644 --- a/CircularBuffer.h +++ b/CircularBuffer.h @@ -20,26 +20,26 @@ of Meebleeps (https://github.com/sensorium/Mozzi/issues/281) */ // TODO: remove this define from here, put a default value in config -#define MOZZI_BUFFER_SIZE 256 +#define MOZZI_OUTPUT_BUFFER_SIZE 256 -// This is to get the correct cound for audioticks() -#if (MOZZI_BUFFER_SIZE == 256) +// This is to get the correct cound for audioticks() (there might be a smarter way...) +#if (MOZZI_OUTPUT_BUFFER_SIZE == 256) #define COUNT_LSHIFT 8 -#elif (MOZZI_BUFFER_SIZE == 128) +#elif (MOZZI_OUTPUT_BUFFER_SIZE == 128) #define COUNT_LSHIFT 7 -#elif (MOZZI_BUFFER_SIZE == 64) +#elif (MOZZI_OUTPUT_BUFFER_SIZE == 64) #define COUNT_LSHIFT 6 -#elif (MOZZI_BUFFER_SIZE == 32) +#elif (MOZZI_OUTPUT_BUFFER_SIZE == 32) #define COUNT_LSHIFT 5 -#elif (MOZZI_BUFFER_SIZE == 16) +#elif (MOZZI_OUTPUT_BUFFER_SIZE == 16) #define COUNT_LSHIFT 4 -#elif (MOZZI_BUFFER_SIZE == 8) +#elif (MOZZI_OUTPUT_BUFFER_SIZE == 8) #define COUNT_LSHIFT 3 -#elif (MOZZI_BUFFER_SIZE == 4) +#elif (MOZZI_OUTPUT_BUFFER_SIZE == 4) #define COUNT_LSHIFT 2 -#elif (MOZZI_BUFFER_SIZE == 2) +#elif (MOZZI_OUTPUT_BUFFER_SIZE == 2) #define COUNT_LSHIFT 1 -#elif (MOZZI_BUFFER_SIZE == 1) +#elif (MOZZI_OUTPUT_BUFFER_SIZE == 1) #define COUNT_LSHIFT 0 #endif @@ -93,14 +93,14 @@ class CircularBuffer } private: - ITEM_TYPE items[MOZZI_BUFFER_SIZE]; + ITEM_TYPE items[MOZZI_OUTPUT_BUFFER_SIZE]; uint8_t start; /* index of oldest itement */ uint8_t end; /* index at which to write new itement */ uint8_t s_msb; uint8_t e_msb; unsigned long num_buffers_read; -#if (CIRCULAR_BUFFER_SIZE == 256) +#if (MOZZI_OUTPUT_BUFFER_SIZE == 256) inline void cbIncrStart() { start++; @@ -119,7 +119,7 @@ class CircularBuffer inline void cbIncrStart() { start++; - if (start == CIRCULAR_BUFFER_SIZE) + if (start == MOZZI_OUTPUT_BUFFER_SIZE) { start = 0; s_msb ^= 1; @@ -131,7 +131,7 @@ class CircularBuffer void cbIncrEnd() { end++; - if (end == CIRCULAR_BUFFER_SIZE) + if (end == MOZZI_OUTPUT_BUFFER_SIZE) { end = 0; e_msb ^= 1; diff --git a/config/mozzi_config_documentation.h b/config/mozzi_config_documentation.h index a7172db9d..e2d5a9706 100644 --- a/config/mozzi_config_documentation.h +++ b/config/mozzi_config_documentation.h @@ -250,7 +250,7 @@ #define MOZZI_AUDIO_PIN_1 FOR_DOXYGEN_ONLY /** @ingroup config - * @def MOZZI_BUFFER_SIZE + * @def MOZZI_OUTPUT_BUFFER_SIZE * * @brief Audio buffer setting. * @@ -258,13 +258,13 @@ * The bigger the buffer, the more able Mozzi will be to coop with big change of processor loads as the buffered values can compensate for that. * At the same time, a bigger buffer produces a bigger latency as the time between when Mozzi produces the sample and the time it is actually outputted increases. For instance, for a long time Mozzi's buffer size was of a fixed size of 256. This produces a potential latency of 15.6 ms for a MOZZI_AUDIO_RATE of 16384, and half this value for a MOZZI_AUDIO_RATE of 32768. * Depending on the application, this is usually not a problem but can lead to synchronisation issues in some cases (for instance when working with clocks). - * MOZZI_BUFFER_SIZE can be reduced to smaller values with this config, leading to more accurate timings but potentially to glitches if the buffer runs low. + * MOZZI_OUTPUT_BUFFER_SIZE can be reduced to smaller values with this config, leading to more accurate timings but potentially to glitches if the buffer runs low. * Valid values are power of two from 256 downward (128, 64, …). * Note that this might not have an effect in all modes/platforms combination as Mozzi is sometimes using an external buffer which is not always configurable. * * TODO: Throw a warning if config does not have an effect */ -#define MOZZI_BUFFER_SIZE FOR_DOXYGEN_ONLY +#define MOZZI_OUTPUT_BUFFER_SIZE FOR_DOXYGEN_ONLY /***************************************** ADVANCED SETTTINGS -- External audio output ****************************************** diff --git a/internal/MozziGuts_impl_RENESAS.hpp b/internal/MozziGuts_impl_RENESAS.hpp index 7ba7afda4..12bb6c26b 100644 --- a/internal/MozziGuts_impl_RENESAS.hpp +++ b/internal/MozziGuts_impl_RENESAS.hpp @@ -159,7 +159,7 @@ static void startAudio() { // The following branches the DAC straight on Mozzi's circular buffer. dtc_cfg.p_info->p_src = output_buffer.address(); - dtc_cfg.p_info->length = MOZZI_BUFFER_SIZE; + dtc_cfg.p_info->length = MOZZI_OUTPUT_BUFFER_SIZE; R_DTC_Reconfigure(&dtc_ctrl, dtc_cfg.p_info); timer_dac.start(); #endif From 3d6c5ea21d2f75c7d61a13a406dfb7e84b229528 Mon Sep 17 00:00:00 2001 From: tomcombriat Date: Fri, 18 Apr 2025 20:53:03 +0200 Subject: [PATCH 4/9] Added generic config --- internal/config_checks_generic.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/config_checks_generic.h b/internal/config_checks_generic.h index 3bd8f0b23..6886882eb 100644 --- a/internal/config_checks_generic.h +++ b/internal/config_checks_generic.h @@ -78,6 +78,10 @@ #define MOZZI_AUDIO_INPUT_PIN 0 #endif +#if not defined(MOZZI_OUTPUT_BUFFER_SIZE) +#define MOZZI_OUTPUT_BUFFER_SIZE 256 +#endif + //MOZZI_PWM_RATE -> hardware specific //MOZZI_AUDIO_PIN_1 -> hardware specific //MOZZI_AUDIO_PIN_1_LOW -> hardware specific @@ -121,6 +125,10 @@ /// Step 3: Apply various generic checks that make sense on more than one platform MOZZI_CHECK_POW2(MOZZI_AUDIO_RATE) MOZZI_CHECK_POW2(MOZZI_CONTROL_RATE) +MOZZI_CHECK_POW2(MOZZI_OUTPUT_BUFFER_SIZE) +#if (MOZZI_OUTPUT_BUFFER_SIZE > 256) +#error "Mozzi does not support buffer sizes greated than 256 at the moment" +#endif #if MOZZI_IS(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_STANDARD) && MOZZI_IS(MOZZI_ANALOG_READ, MOZZI_ANALOG_READ_NONE) #error "MOZZI_AUDIO_INPUT depends on MOZZI_ANALOG_READ option" From ff7b7828a77694e5e075f3957c184858b1b0d8cf Mon Sep 17 00:00:00 2001 From: tomcombriat Date: Fri, 18 Apr 2025 21:44:35 +0200 Subject: [PATCH 5/9] Modified CircularBuffer to have the buffer size as a template parameter hence allowing for differently sized bufers to be used (for instance with audio input) --- CircularBuffer.h | 140 ++++++++++++++++++++++++++++++----------------- 1 file changed, 91 insertions(+), 49 deletions(-) diff --git a/CircularBuffer.h b/CircularBuffer.h index 0fd0d2aba..d05d2f0a6 100644 --- a/CircularBuffer.h +++ b/CircularBuffer.h @@ -19,36 +19,13 @@ April 2025: modified for different buffer sizes under the suggestion of Meebleeps (https://github.com/sensorium/Mozzi/issues/281) */ -// TODO: remove this define from here, put a default value in config -#define MOZZI_OUTPUT_BUFFER_SIZE 256 - -// This is to get the correct cound for audioticks() (there might be a smarter way...) -#if (MOZZI_OUTPUT_BUFFER_SIZE == 256) -#define COUNT_LSHIFT 8 -#elif (MOZZI_OUTPUT_BUFFER_SIZE == 128) -#define COUNT_LSHIFT 7 -#elif (MOZZI_OUTPUT_BUFFER_SIZE == 64) -#define COUNT_LSHIFT 6 -#elif (MOZZI_OUTPUT_BUFFER_SIZE == 32) -#define COUNT_LSHIFT 5 -#elif (MOZZI_OUTPUT_BUFFER_SIZE == 16) -#define COUNT_LSHIFT 4 -#elif (MOZZI_OUTPUT_BUFFER_SIZE == 8) -#define COUNT_LSHIFT 3 -#elif (MOZZI_OUTPUT_BUFFER_SIZE == 4) -#define COUNT_LSHIFT 2 -#elif (MOZZI_OUTPUT_BUFFER_SIZE == 2) -#define COUNT_LSHIFT 1 -#elif (MOZZI_OUTPUT_BUFFER_SIZE == 1) -#define COUNT_LSHIFT 0 -#endif - - - -/** Circular buffer object. Has a fixed number of cells, set to 256. + + +/** Circular buffer object. Has a fixed number of cells, set by BUFFER_SIZE. @tparam ITEM_TYPE the kind of data to store, eg. int, int8_t etc. +@tparam BUFFER_SIZE the size of the circular buffer */ -template +template class CircularBuffer { @@ -93,33 +70,26 @@ class CircularBuffer } private: - ITEM_TYPE items[MOZZI_OUTPUT_BUFFER_SIZE]; + ITEM_TYPE items[BUFFER_SIZE]; uint8_t start; /* index of oldest itement */ uint8_t end; /* index at which to write new itement */ uint8_t s_msb; uint8_t e_msb; unsigned long num_buffers_read; + static constexpr unsigned long COUNT_LSHIFT = + (BUFFER_SIZE == 256) ? 8 : + (BUFFER_SIZE == 128) ? 7 : + (BUFFER_SIZE == 64) ? 6 : + (BUFFER_SIZE == 32) ? 5 : + (BUFFER_SIZE == 16) ? 4 : + (BUFFER_SIZE == 8) ? 3 : + (BUFFER_SIZE == 4) ? 2 : + (BUFFER_SIZE == 2) ? 1 : 0; -#if (MOZZI_OUTPUT_BUFFER_SIZE == 256) - inline - void cbIncrStart() { - start++; - if (start == 0) { - s_msb ^= 1; - num_buffers_read++; - } - } - - inline - void cbIncrEnd() { - end++; - if (end == 0) e_msb ^= 1; - } -#else // if circular buffer length is != 256, use less efficient version for to manage start/end index buffer index inline void cbIncrStart() { start++; - if (start == MOZZI_OUTPUT_BUFFER_SIZE) + if (start == BUFFER_SIZE) { start = 0; s_msb ^= 1; @@ -131,16 +101,88 @@ class CircularBuffer void cbIncrEnd() { end++; - if (end == MOZZI_OUTPUT_BUFFER_SIZE) + if (end == BUFFER_SIZE) { end = 0; e_msb ^= 1; } } -#endif }; -#undef COUNT_LSHIFT // avoid macro spil + +/** Circular buffer object. Specialization for size of 256. +Note: Lot of duplication but C++ does not allow for specialization of the +function member only (partial specialization). +@tparam ITEM_TYPE the kind of data to store, eg. int, int8_t etc. +*/ +template +class CircularBuffer +{ +public: + /** Constructor + */ + CircularBuffer(): start(0),end(0),s_msb(0),e_msb(0) + { + } + + inline + bool isFull() { + return end == start && e_msb != s_msb; + } + + inline + bool isEmpty() { + return end == start && e_msb == s_msb; + } + + inline + void write(ITEM_TYPE in) { + items[end] = in; + //if (isFull()) cbIncrStart(); /* full, overwrite moves start pointer */ + cbIncrEnd(); + } + + inline + ITEM_TYPE read() { + ITEM_TYPE out = items[start]; + cbIncrStart(); + return out; + } + + inline + unsigned long count() { + return (num_buffers_read << 8) + start; + } + inline + ITEM_TYPE * address() { + return items; + } + +private: + ITEM_TYPE items[256]; + uint8_t start; /* index of oldest itement */ + uint8_t end; /* index at which to write new itement */ + uint8_t s_msb; + uint8_t e_msb; + unsigned long num_buffers_read; + + + inline + void cbIncrStart() { + start++; + if (start == 0) { + s_msb ^= 1; + num_buffers_read++; + } + } + + inline + void cbIncrEnd() { + end++; + if (end == 0) e_msb ^= 1; + } +}; + From ba7857166e08332e06a2575821641d16d403b99c Mon Sep 17 00:00:00 2001 From: tomcombriat Date: Fri, 18 Apr 2025 21:46:37 +0200 Subject: [PATCH 6/9] Updated MozziGuts for different buffer size --- internal/MozziGuts.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/MozziGuts.hpp b/internal/MozziGuts.hpp index 660171f28..a060af371 100644 --- a/internal/MozziGuts.hpp +++ b/internal/MozziGuts.hpp @@ -86,7 +86,7 @@ inline void bufferAudioOutput(const AudioOutput f) { ++samples_written_to_buffer; } #else -CircularBuffer output_buffer; // fixed size 256 + CircularBuffer output_buffer; # define canBufferAudioOutput() (!output_buffer.isFull()) # define bufferAudioOutput(f) output_buffer.write(f) static void CACHED_FUNCTION_ATTR defaultAudioOutput() { @@ -150,7 +150,7 @@ uint16_t getAudioInput() { return audio_input; } #if MOZZI_IS(MOZZI__LEGACY_AUDIO_INPUT_IMPL, 1) // ring buffer for audio input -CircularBuffer input_buffer; // fixed size 256 + CircularBuffer input_buffer; // fixed size 256 #define audioInputAvailable() (!input_buffer.isEmpty()) #define readAudioInput() (input_buffer.read()) /** NOTE: Triggered at MOZZI_AUDIO_RATE via defaultAudioOutput(). In addition to the MOZZI_AUDIO_INPUT_PIN, at most one reading is taken for mozziAnalogRead(). */ From 8c1a6e742e4cb9d621dace4e2aa93dcc249e82b4 Mon Sep 17 00:00:00 2001 From: tomcombriat Date: Fri, 18 Apr 2025 21:56:14 +0200 Subject: [PATCH 7/9] Fix Renesas compilation with MOZZI_OUTPUT_BUFFER_SIZE --- internal/MozziGuts_impl_RENESAS.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/MozziGuts_impl_RENESAS.hpp b/internal/MozziGuts_impl_RENESAS.hpp index 12bb6c26b..c30c18177 100644 --- a/internal/MozziGuts_impl_RENESAS.hpp +++ b/internal/MozziGuts_impl_RENESAS.hpp @@ -86,7 +86,7 @@ FspTimer timer; #endif #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_INTERNAL_DAC) -CircularBuffer output_buffer; + CircularBuffer output_buffer; } // namespace MozziPrivate #include "MozziGuts_impl_RENESAS_analog.hpp" namespace MozziPrivate { From 9ecdd0900e4221b2d3bfec5301572e35b93a5d3b Mon Sep 17 00:00:00 2001 From: tomcombriat Date: Sat, 19 Apr 2025 18:45:24 +0200 Subject: [PATCH 8/9] FixESP8266 I2S --- internal/MozziGuts_impl_ESP8266.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/MozziGuts_impl_ESP8266.hpp b/internal/MozziGuts_impl_ESP8266.hpp index f4623c96d..20d37d2e2 100644 --- a/internal/MozziGuts_impl_ESP8266.hpp +++ b/internal/MozziGuts_impl_ESP8266.hpp @@ -48,7 +48,7 @@ uint16_t output_buffer_size = 0; # if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_PDM_VIA_I2S) } // namespace MozziPrivate -# include +# include namespace MozziPrivate { inline bool canBufferAudioOutput() { return (i2s_available() >= MOZZI_PDM_RESOLUTION); @@ -60,7 +60,7 @@ inline void audioOutput(const AudioOutput f) { } # elif MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_I2S_DAC) } // namespace MozziPrivate -# include +# include namespace MozziPrivate { inline bool canBufferAudioOutput() { return (i2s_available() >= MOZZI_PDM_RESOLUTION); From fd6dfaed20182c1edc5ca4030e800d5ce983287f Mon Sep 17 00:00:00 2001 From: tomcombriat Date: Sat, 19 Apr 2025 18:45:41 +0200 Subject: [PATCH 9/9] Added warning messages when defining a smaller does not have an effect --- internal/config_checks_esp32.h | 3 +++ internal/config_checks_esp8266.h | 3 +++ internal/config_checks_mbed.h | 5 ++++- internal/config_checks_rp2040.h | 14 ++++++++++++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/internal/config_checks_esp32.h b/internal/config_checks_esp32.h index e4f1d6cc7..989a3bb1c 100644 --- a/internal/config_checks_esp32.h +++ b/internal/config_checks_esp32.h @@ -220,6 +220,9 @@ MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_NONE) // All modes besides timed external bypass the output buffer! #if !MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED, MOZZI_OUTPUT_INTERNAL_DAC, MOZZI_OUTPUT_PWM) # define BYPASS_MOZZI_OUTPUT_BUFFER true +#if (MOZZI_OUTPUT_BUFFER_SIZE != 256) +# warning MOZZI_OUTPUT_BUFFER_SIZE does not have an effect in this mode. +#endif #endif #define MOZZI__INTERNAL_ANALOG_READ_RESOLUTION 12 diff --git a/internal/config_checks_esp8266.h b/internal/config_checks_esp8266.h index 00cfff8ab..ab6c516f8 100644 --- a/internal/config_checks_esp8266.h +++ b/internal/config_checks_esp8266.h @@ -114,6 +114,9 @@ MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_BITS, 16) // esp. since i2s output already has output rate control -> no need for a // separate output timer #define BYPASS_MOZZI_OUTPUT_BUFFER true +#if (MOZZI_OUTPUT_BUFFER_SIZE != 256) +# warning MOZZI_OUTPUT_BUFFER_SIZE does not have an effect in this mode. +#endif #endif #define MOZZI__INTERNAL_ANALOG_READ_RESOLUTION 10 diff --git a/internal/config_checks_mbed.h b/internal/config_checks_mbed.h index 7ac69ba91..a99c8de7f 100644 --- a/internal/config_checks_mbed.h +++ b/internal/config_checks_mbed.h @@ -117,9 +117,12 @@ MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_INPUT, MOZZI_AUDIO_INPUT_NONE, MOZZI_AUDIO_INP # endif #endif -// All modes besides timed external bypass the output buffer! +// All modes besides timed external bypass the output buffer! In these modes, the buffer size is not configurable at the moment: throw an error if the user tries to change it. #if !MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED) # define BYPASS_MOZZI_OUTPUT_BUFFER true +# if (MOZZI_OUTPUT_BUFFER_SIZE != 256) // has been modified +# warning MOZZI_OUTPUT_BUFFER_SIZE does not have an effect in this mode. +# endif #endif // TODO: This value is correct for Arduino Giga and Arduino Portenta, but not necessarily everywhere else diff --git a/internal/config_checks_rp2040.h b/internal/config_checks_rp2040.h index 5ba884415..569e3406d 100644 --- a/internal/config_checks_rp2040.h +++ b/internal/config_checks_rp2040.h @@ -95,7 +95,12 @@ MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED, MOZZI_OUTPU # endif # define BYPASS_MOZZI_OUTPUT_BUFFER true # define MOZZI_RP2040_BUFFERS 8 // number of DMA buffers used -# define MOZZI_RP2040_BUFFER_SIZE 256 // total size of the buffer, in samples +# if !defined MOZZI_RP2040_BUFFER_SIZE +# define MOZZI_RP2040_BUFFER_SIZE MOZZI_OUTPUT_BUFFER_SIZE // total size of the buffer, in samples +# if (MOZZI_OUTPUT_BUFFER_SIZE < MOZZI_RP2040_BUFFERS) +# error MOZZI_OUTPUT_BUFFER_SIZE cannot be lower than 8 on this platform at the moment +# endif +# endif #endif #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_I2S_DAC) @@ -115,7 +120,12 @@ MOZZI_CHECK_SUPPORTED(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED, MOZZI_OUTPU MOZZI_CHECK_SUPPORTED(MOZZI_I2S_FORMAT, MOZZI_I2S_FORMAT_PLAIN, MOZZI_I2S_FORMAT_LSBJ) # define BYPASS_MOZZI_OUTPUT_BUFFER true # define MOZZI_RP2040_BUFFERS 8 // number of DMA buffers used -# define MOZZI_RP2040_BUFFER_SIZE 256 // total size of the buffer, in samples +# if !defined MOZZI_RP2040_BUFFER_SIZE +# define MOZZI_RP2040_BUFFER_SIZE MOZZI_OUTPUT_BUFFER_SIZE // total size of the buffer, in samples +# if (MOZZI_OUTPUT_BUFFER_SIZE < MOZZI_RP2040_BUFFERS) +# error MOZZI_OUTPUT_BUFFER_SIZE cannot be lower than 8 on this platform at the moment +# endif +# endif #endif #if !defined(MOZZI_ANALOG_READ)