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

port by Thomas Friedrichsmeier

Port status and notes

  • Since flash memory is not built into the ESP8266, 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 available
  • twi_nonblock is not ported
  • Note that the ESP8266 pins can output less current than the other supported CPUs. The maximum is 12mA, with a recommendation to stay below 6mA.
    • WHEN CONNECTING A HEADPHONE, DIRECTLY, USE APPROPRIATE CURRENT LIMITING RESISTORS (>= 500Ohms).
  • Any WiFi-activity can cause severe spikes in power consumption. This can cause audible "ticking" artifacts, long before any other symptoms.
    • If you do not require WiFi in your sketch, you should turn it off, explicitly, using
      WiFi.mode(WIFI_OFF)
      .
  • A juicy enough, well regulated power supply, and a stabilizing capacitor between VCC and Gnd can help a lot.
  • As the (PDM) output signal is digital, a single (fast!) transistor can be used to amplify it to an independent voltage level.
  • audioHook() calls yield() once for every audio sample generated. Thus, as long as your audio output buffer does not run empty, you should not need any additional yield()s inside loop().

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_PDM_VIA_SERIAL
  • MOZZI_OUTPUT_I2S_DAC

The default mode is MOZZI_OUTPUT_PDM_VIA_SERIAL .

Note
This port really does not currently come with a PWM mode!

MOZZI_OUTPUT_PDM_VIA_SERIAL

Output is coded using pulse density modulation, and sent via GPIO2 (Serial1 TX).

  • This output mode uses timer1 for queuing audio sample, so that timer is not available for other uses.
  • Note that this mode has slightly lower effective analog output range than esp8266_pdm_via_i2s, due to start/stop bits being added to the output stream.
  • Supports mono output, only, pins not configurable.

The option MOZZI_PDM_RESOLTUON (default value 2, corresponding to 64 ones and zeros per audio sample) can be used to adjust the output resolution. Obviously higher values demand more computation power.

MOZZI_OUTPUT_PDM_VIA_SERIAL

Output is coded using pulse density modulation, and sent via the I2S pins. The I2S data out pin (GPIO3, which is also "RX") will have the output, but all I2S output pins (RX, GPIO2 and GPIO15) will be affected. Mozzi tries to set GPIO2 and GPIO15 to input mode, and at the time of this writing, this allows I2S output on RX even on boards such as the ESP01 (where GPIO15 is tied to Ground). However, it seems safest to assume that this mode may not be useable on boards where GPIO2 or GPIO15 are not available as output pins.

Supports mono output, only, pins not configurable.

Resolution may be controlled using MOZZI_PDM_RESOLUTION (see above; default value is 2).

MOZZI_OUTPUT_I2S_DAC

Output is sent to an external DAC (such as a PT8211), digitally coded. This is the only mode that supports stereo (MOZZI_AUDIO_CHANNELS). It also needs the least processing power. The pins cannot be configured (GPIO3/RX, GPIO2, and GPIO15).

MOZZI_OUTPUT_EXTERNAL_TIMED and MOZZI_OUTPUT_EXTERNAL_CUSTOM

See External audio output