Mozzi  version v2.0
sound synthesis library for Arduino
Mozzi on ESP32-based boards.

port by Dieter Vandoren and Thomas Friedrichsmeier

Port status and notes

  • Since flash memory is not built into the ESP32, but connected, externally, it is much too slow for keeping wave tables, audio samples, etc. Instead, these are kept in RAM on this platform.
  • Asynchronous analog reads are not implemented. mozziAnalogRead() relays to analogRead(). MOZZI_AUDIO_INPUT is not implemented
  • twi_nonblock is not ported
  • WIFI-activity not yet tested, but likely the same notes as for ESP8266 apply, i.e. any Wifi activity is likely to introdcue considerable nose. Consider turning off WIFI.
  • The implementation of audioTicks() may be slightly inaccurate on this platform.

Output modes

The following audio modes (see MOZZI_AUDIO_MODE) are currently supported on this hardware:

  • MOZZI_OUTPUT_EXTERNAL_TIMED
  • MOZZI_OUTPUT_EXTERNAL_CUSTOM
  • MOZZI_OUTPUT_PDM_VIA_I2S
  • MOZZI_OUTPUT_I2S_DAC
  • MOZZI_OUTPUT_INTERNAL_DAC

The default mode is MOZZI_OUTPUT_INTERNAL_DAC .

MOZZI_OUTPUT_INTERNAL_DAC

The internal DAC has 8 bit resolution, and outputs to GPIO pins 25 and 26 (non-configurable). For simplicity of code, both pins are always used. In a mono configuration, both pins output the same sample.

TODO: We could really use this to hack in a 2 PIN mode!

Note
The number 25 refers to "GPIO 25" or sometimes labelled "D25". Confusingly, many boards come with an additional, totally different numbering scheme on top of that. Check a detailed pinout diagram, if in any doubt.

Internally, the inbuilt DAC is connected via an I2S interface. Which interface number to use can be configured using:

#define MOZZI_I2S_PORT ... // (default: I2S_NUM_0)

MOZZI_OUTPUT_I2S_DAC

This mode outputs to a PT8211 (or compatible) I2S DAC, which allows for very high quality (mono or stereo) output. Communication needs the BCK, WS, and DATA(out) pins of one I2S interface. Presumably, any pins qualify, and you can configure this using:

#define MOZZI_I2S_PIN_BCK ... // (default: 26)
#define MOZZI_I2S_PIN_WS ... // (default: 15)
#define MOZZI_I2S_PIN_DATA ... // (default: 33)
#define MOZZI_I2S_PORT ... // (default: I2S_NUM_0)

See the note above (esp_internal_dac) regarding pin numbering. Also, please always test the default pinout, should a custom setting fail!

As a technical note, I2S support in the ESP32 SDK has been reworked since this was implemented in Mozzi, and Mozzi uses the "legacy" implementation "i2s.h". This should not be an issue, unless you want to connect additional I2S components, yourself. In which case contributions are certainly welcome!

MOZZI_OUTPUT_PDM_VIA_I2S

This mode uses the same setup as MOZZI_OUTPUT_I2S_DAC, but rather than using an external DAC, the communication signal itself is modulated in PDM (pulse density modulation) encoded form. Thus not extra hardware is needed, and the signal is output on the DATA pin (see above). The BCK and WS pins are also claimed, but should be left non-connected, and do not produce anything meaningful. This can only be used in mono mode.

Output resolution may be adjusted by defining MOZZI_PDM_RESOLUTION , where the default value of 4 means that each audio sample is encoded into four 32 bit blocks of ones and zeros. Obviously, more is potentially better, but at the cost of considerable computation power.

MOZZI_OUTPUT_EXTERNAL_TIMED and MOZZI_OUTPUT_EXTERNAL_CUSTOM

See External audio output