Description
As a continuation of #204 but not strictly dependent, here are some thoughts on what I would like to change regarding the configuration itself.
The first change I propose is easy enough to summarize: Prefix each Mozzi configuration #define
with MOZZI_
in order to avoid name clashes. Since this only affects customization of the configuration, the extra typing should not be too cumbersome. Exceptions will be made for AUDIO_RATE and CONTROL_RATE, which are also commonly used inside existing sketches.
The second proposed change is the general setup for configuration. This would consist of:
- MozziCustomConfig.h This file will simply contain definitions to be used in the configuration, i.e. (and I'm actually trying to be complete, here):
#define MOZZI_MONO 1
#define MOZZI_STEREO 2
#define MOZZI_OUTPUT_PWM 1 // Corresponds to "STANDARD_PLUS" on AVR; "STANDARD" has been deprecated for ages, let's drop it
#define MOZZI_OUTPUT_2PIN_PWM 2 // Formerly known as "HIFI"
#define MOZZI_OUTPUT_EXTERNAL 3 // Formerly known as EXTERNAL_AUDIO_OUTPUT
#define MOZZI_OUTPUT_PDM_VIA_I2S 4
#define MOZZI_OUTPUT_PDM_VIA_SERIAL 5
#define MOZZI_OUTPUT_I2S_DAC 6
#define MOZZI_OUTPUT_INTERNAL_DAC 7
#include <hardware_defines.h>
I.e. we're actually trying to use exactly the same config values across all boards. Naturally, not each value will be supported on each board.
Next, the user may (or may not) customize some of these options like so:
#include <MozziCustomConfig.>
#define AUDIO_RATE 32768
#define MOZZI_AUDIO_MODE MOZZI_OUTPUT_EXTERNAL
// [...]
#include <MozziGuts.h>
Finally, MozziGuts.h will (automatically) apply defaults, where nothing has been set, and check for invalid settings. This will likely be mostly handled inside (internal) platform specific files like, e.g.
- mozzi_check_config_avr.h
#if not defined(AUDIO_RATE)
#define AUDIO_RATE 16384
#endif
#if not defined(MOZZI_USE_AUDIO_INPUT)
#define MOZZI_USE_AUDIO_INPUT false
#endif
#if not defined(MOZZI_AUDIO_MODE)
#define MOZZI_AUDIO_MODE MOZZI_OUTPUT_PWM
#endif
/// [...] The above is a bit boring to type out, so I'm skipping ahead to the second stage:
#if not (MOZZI_AUDIO_MODE == MOZZI_OUTPUT_PWM || MOZZI_AUDIO_MODE == MOZZI_OUTPUT_2PIN_PWM || MOZZI_AUDIO_MODE == MOZZI_OUTPUT_EXTERNAL)
#error Specified MOZZI_AUDIO_MODE is not supported on this platform
#endif
// [...] Etc., and finally:
#if (MOZZI_AUDIO_MODE == MOZZI_OUTPUT_PWM)
#define MOZZI_AUDIO_BITS 8
#define MOZZI_AUDIO_BITS_EXTENDED true
#elif (MOZZI_AUDIO_MODE == MOZZI_OUTPUT_2PIN_PWM)
#define MOZZI_AUDIO_BITS 14
#elif (MOZZI_AUDIO_MODE == MOZZI_OUTPUT_EXTERNAL)
#if not defined (MOZZI_AUDIO_BITS)
#define MOZZI_AUDIO_BITS 16
#endif
#endif
Ok, I've skipped over quite some stuff, here, but you get the basic idea. But also, you will probably have noted that there are a couple of details that will still need to be addressed.
I imagine, some of this proposal may actually be controversial, so please voice your concerns (and your additional thoughts).