MOZZI

sound synthesis library for Arduino

Output

The default AUDIO_MODE since March 2014 is STANDARD_PLUS. On Atmel-based boards this mode has a pwm carrier rate of 32768 Hz, double the rate for STANDARD mode. The higher pwm rate is above hearing range, an advance on STANDARD mode’s 16384 Hz which can be audible for children and some adults.
Teensy 3.1 boards provide true analog DAC rather than pwm, so Teensy 3.1 is a great option for cleaner sounding audio and you won’t need a pwm carrier filter. Teensy 3.1 also runs much faster than the Atmel based Arduinos, so you can generate more complex sounds.
STANDARD_PLUS can still benefit from a low pass filter, as outlined below for STANDARD mode.

Output circuit for HIFI mode

Mozzi’s HIFI audio mode combines the output of 2 pins in a technique called dual PWM, which is explained in detail at Open Music Labs.

Here’s the circuit for Mozzi, based on the Open Music Labs article.

Mozzi output circuit for HIFI audio mode

Teensy 3.1 doesn’t use 14 bit pwm HIFI mode, but has 12 bit DAC analog output enabled by default, even in STANDARD and STANDARD_PLUS modes.

Advantages of HIFI mode

  • Higher resolution sound than STANDARD or STANDARD_PLUS modes.
  • Doesn’t need a notch filter on the audio signal because the carrier frequency is out of hearing range (STANDARD_PLUS also doesn’t need it).

Disadvantages

  • Requires 2 pins, 2 resistors and a capacitor, so it’s not so quick to set up compared to a rough, direct single-pin output in STANDARD mode.

Pins and where to put the resistors on various boards for HIFI mode

Boards tested in HIFI mode have an x, though most of these have been tested in STANDARD mode and there’s no reason for them not to work in HIFI (unless the pin number is wrong or something). Any reports are welcome.

resistor…..3.9k……499k (or 2 1M in parallel)
x…………….9……….10……………Arduino Uno
x…………….9……….10……………Arduino Duemilanove
x…………….9……….10……………Arduino Nano
………………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

Low pass audio filter

Mozzi’s sound output can be filtered to reduce aliasing at high frequencies. Here’s some info about low pass RC filters and a calculator to help choose components. For Mozzi, an RC filter with a roll-off frequency of just under 6kHz works well, using a 270 Ω resistor and a 100n capacitor, as shown below. In HIFI mode, this would be on the combined audio output signal rather than straight from pin 9.

RC circuit

Notch filter for STANDARD mode carrier frequency

This may still be useful if you need to use STANDARD mode for some reason, for instance if you need Timer 2 for another process (making HIFI unavailable), or if your sketch is too intensive for STANDARD_PLUS and you need 10% more juice.

People who have used Mozzi in STANDARD mode with children report that kids find the carrier frequency particularly irritating, however adults are often unable to perceive it at any level! Many thanks to Andrew McPherson, who sent a schematic and equation for a twin-T notch filter which he used successfully to remove the offending frequency.

Twin-T Notch Filter equation

Here’s a design tool for calculating Twin-T notch filters.

Andrew also reported that the low-pass and notch filter described here can be used together in series without any problems.

Here’s a schematic for the 6kHz low pass and the notch filter using commonly available parts chosen to exactly match STANDARD mode’s 16384Hz carrier frequency, using the notch filter design tool.

Schematic

Download

Download a Fritzing file with breadboard, schematic and circuit board layouts here.