Mozzi  version v2.0
sound synthesis library for Arduino
Mozzi on classic Arduino, Teensy 2.x, Arduino Mega, and other 8 bit "AVR"/ATMEGA architecture boards

Port status and notes

This is the original "port" of Mozzi, and thus very elaborate. The main challenges on this platform, compared to other MCUs, are limitations in flash, RAM, and CPU power.

Output modes

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

  • MOZZI_OUTPUT_PWM
  • MOZZI_OUTPUT_2PIN_PWM
  • MOZZI_OUTPUT_EXTERNAL_TIMED
  • MOZZI_OUTPUT_EXTERNAL_CUSTOM

In all modes, except MOZZI_OUTPUT_EXTERNAL_CUSTOM, Timer 1 is claimed, and is not available for any other purpose. This means, among other things, that pins 9 and 10 cannot be used for analogWrite(), while pins 3 and 11 should still be available except in MOZZI_OUTPUT_2PIN_PWM mode (as Timer2 is also claimed, then; for definite info on which pin is connected to which timer, check a suitable reference, as your board may differ). See Mozzi>examples>11.Communication>Sinewave_PWM_pins_HIFI. for an example of emulating analogWrite() on any digital pin, without the need for a hardware timer.

MOZZI_OUTPUT_PWM

For MOZZI_OUTPUT_PWM, output is restricted to pins that are hardware-attached to Timer 1, but can be configured within this tight limit. In particular, the default setup on the Arduino UNO is:

  • Mono: Pin 9 -> configurable using MOZZI_AUDIO_PIN_1
  • Stereo: Pin 9 (left) and Pin 10 (right) -> configurable using MOZZI_AUDIO_PIN_1 and MOZZI_AUDIO_PIN_2 For pinouts on other boards, refer to config/known_16bit_timers.

Rate of the PWM output can be controlled separately from MOZZI_AUDIO_RATE: MOZZI_PWM_RATE.

The available sample resolution is 488, i.e. almost 9 bits, providing some headroom above the 8 bit table resolution currently used by the oscillators. You can look at the TimerOne library for more info about how interrupt rate and pwm resolution relate.

MOZZI_OUTPUT_2PIN_PWM

In this mode, output is split across two pins (again, both connected to Timer 1), with each outputting 7 bits for a total of 14. This allows for much better dynamic range, providing much more definition than can be achieved using MOZZI_OUTPUT_PWM , while using only modestly more processing power. Further, it allows for a much higher PWM carrier rate can be much higher (125 kHz by default; see MOZZI_PWM_RATE), which is well beyond the audible range.

On the downside, this mode requires an extra hardware timer (Timer2 in addition to Timer1), which may increase compatibility problems with other Arduino libraries that also require a timer. Further, a more elaborate hardware setup is needed, making it less convenient for rapid prototyping. For circuit details, see https://sensorium.github.io/Mozzi/learn/output/ .

On the classic Arduino Uno, the default pinout in this mode is:

  • Pin 9 (high bits) and Pin 10 (low bits) -> configurable using MOZZI_AUDIO_PIN_1 and MOZZI_AUDIO_PIN_1_LOW

Here is table of the default pins on some other boards. Rows with an x on it have actually been tested (and importantly, the outcome recoreded; input welcome on further boards.)

resistor.....3.9k......499k
x................9..........10...............Arduino Uno
x................9..........10...............Arduino Duemilanove
x................9..........10...............Arduino Nano
x................9..........10...............Arduino Leonardo
x................9..........10...............Ardweeny
x................9..........10...............Boarduino
x...............11.........12...............Freetronics EtherMega
.................11.........12...............Arduino Mega
.................14.........15...............Teensy
.............B5(14)...B6(15)...........Teensy2
x...........B5(25)...B6(26)...........Teensy2++
.................13.........12...............Sanguino
For pinouts on other AVR boards, config/known_16bit_timers might contain some hints.

Rate of the PWM output can be controlled separately from MOZZI_AUDIO_RATE, and is much higher (125kHz), by default: MOZZI_PWM_RATE.

The default sample resolution is 7 bits per pin, for a total of 14 bits. This can be configured within hardware limits (MOZZI_PWM_RATE) using MOZZI_AUDIO_BITS_PER_CHANNEL, but beware that increasing this will require even more accuracy in our output resistors (see the linked documentation, above).

MOZZI_OUTPUT_EXTERNAL_TIMED and MOZZI_OUTPUT_EXTERNAL_CUSTOM

See External audio output