a sound synthesis library for Arduino
HTML C C++ JavaScript Python CSS
Permalink
Failed to load latest commit information.
config update 2016-09-16-11:54 Sep 16, 2016
examples removed ADC.h include in examples Dec 22, 2016
extras update 2016-12-11-17:03 Dec 11, 2016
samples update 2016-09-16-11:54 Sep 16, 2016
tables update 2016-09-16-11:54 Sep 16, 2016
utility removed stray FrequencyTimer files which stopped compile Jan 16, 2017
.gitignore towards new version Oct 2, 2016
.mozzi_analog.h.marks update 2013-08-25-18:13 Aug 25, 2013
ADSR.h update 2016-09-16-11:54 Sep 16, 2016
AudioConfigHiSpeed14bitPwm.h update 2016-09-16-11:54 Sep 16, 2016
AudioConfigStandard9bitPwm.h update 2016-09-16-11:54 Sep 16, 2016
AudioConfigStandardPlus.h update 2016-09-16-11:54 Sep 16, 2016
AudioConfigTeensy3_12bit.h update 2016-09-16-11:54 Sep 16, 2016
AudioDelay.h update 2016-09-16-11:54 Sep 16, 2016
AudioDelayFeedback.h update 2016-09-16-11:54 Sep 16, 2016
AutoMap.h update 2016-09-16-11:54 Sep 16, 2016
AutoRange.h update 2016-09-16-11:54 Sep 16, 2016
CapPoll.h towards new release Apr 11, 2015
CircularBuffer.h update 2014-08-09-14:12 Aug 9, 2014
ControlDelay.h update 2016-09-16-11:54 Sep 16, 2016
DCfilter.h update 2016-09-16-11:54 Sep 16, 2016
Ead.h towards new release Apr 11, 2015
EventDelay.h update 2016-09-16-11:54 Sep 16, 2016
IntMap.h update 2016-09-16-11:54 Sep 16, 2016
Line.h update 2016-09-16-11:54 Sep 16, 2016
LowPassFilter.h update 2016-09-16-11:54 Sep 16, 2016
Metronome.h update 2016-09-16-11:54 Sep 16, 2016
MozziGuts.cpp update 2016-12-11-17:03 Dec 11, 2016
MozziGuts.h update 2016-12-11-17:03 Dec 11, 2016
MultiLine.h update 2016-09-16-11:54 Sep 16, 2016
MultiLine2.h update 2016-09-16-11:54 Sep 16, 2016
Oscil.h towards new version Oct 2, 2016
OverSample.h update 2016-09-16-11:54 Sep 16, 2016
PDResonant.h towards new release Apr 11, 2015
Phasor.h update 2016-09-16-11:54 Sep 16, 2016
Portamento.h update 2016-09-16-11:54 Sep 16, 2016
RCpoll.h update 2014-08-09-14:12 Aug 9, 2014
README.md update 2016-12-11-17:03 Dec 11, 2016
ReverbTank.h update 2016-09-16-11:54 Sep 16, 2016
RollingAverage.h update 2016-09-16-11:54 Sep 16, 2016
RollingStat.h update 2016-09-16-11:54 Sep 16, 2016
Sample.h update 2016-09-16-11:54 Sep 16, 2016
SampleHuffman.h update 2016-09-16-11:54 Sep 16, 2016
Smooth.h update 2016-09-16-11:54 Sep 16, 2016
Stack.h update 2016-09-16-11:54 Sep 16, 2016
StateVariable.h update 2016-09-16-11:54 Sep 16, 2016
WavePacket.h update 2016-09-16-11:54 Sep 16, 2016
WavePacketSample.h update 2016-09-16-11:54 Sep 16, 2016
WaveShaper.h update 2016-09-16-11:54 Sep 16, 2016
cogl_sqrti.h update 2016-09-16-11:54 Sep 16, 2016
keywords.txt update 2016-09-16-11:54 Sep 16, 2016
library.properties update 2016-12-11-17:03 Dec 11, 2016
meta.h update 2016-09-16-11:54 Sep 16, 2016
mozzi_analog.cpp update 2016-12-11-17:03 Dec 11, 2016
mozzi_analog.h update 2016-12-11-17:03 Dec 11, 2016
mozzi_config.h update 2016-12-11-17:03 Dec 11, 2016
mozzi_fixmath.cpp update 2016-09-16-11:54 Sep 16, 2016
mozzi_fixmath.h update 2016-09-16-11:54 Sep 16, 2016
mozzi_midi.cpp update 2016-09-16-11:54 Sep 16, 2016
mozzi_midi.h update 2016-09-16-11:54 Sep 16, 2016
mozzi_rand.cpp update 2016-12-11-17:03 Dec 11, 2016
mozzi_rand.h update 2016-09-16-11:54 Sep 16, 2016
mozzi_utils.cpp update 2016-09-16-11:54 Sep 16, 2016
mozzi_utils.h update 2016-09-16-11:54 Sep 16, 2016
mult16x16.h update 2016-09-16-11:54 Sep 16, 2016
mult16x8.h update 2016-09-16-11:54 Sep 16, 2016
mult32x16.h update 2016-09-16-11:54 Sep 16, 2016
primes.h update 2016-09-16-11:54 Sep 16, 2016
twi_nonblock.cpp update 2016-12-11-17:03 Dec 11, 2016
twi_nonblock.h update 2016-12-11-17:03 Dec 11, 2016

README.md

Mozzi

sound synthesis library for Arduino

Tim Barrass
version 2016-12-11-17:03

Currently your Arduino can only beep like a microwave oven. Mozzi brings your Arduino to life by allowing it to produce much more complex and interesting growls, sweeps and chorusing atmospherics. These sounds can be quickly and easily constructed from familiar synthesis units like oscillators, delays, filters and envelopes.

You can use Mozzi to generate algorithmic music for an installation or performance, or make interactive sonifications of sensors, on a small, modular and super cheap Arduino, without the need for additional shields, message passing or external synths.


Features

  • 16384 Hz sample rate, or experimental 32768 Hz rate.
  • 8 bit or 14 bit audio output modes.
  • Variable control rate from 64 Hz upwards.
  • Useful basic audio toolkit: oscillators, samples, lines, envelopes, scheduling, filtering.
  • Fast ADC and other cpu-efficient code utilities to help keep audio running smoothly.
  • Example sketches for easy modification.
  • Readymade wavetables and a script to convert your own soundfiles for Mozzi.
  • Mozzi is designed to be easy to use, open source and extendable.

Installation

Download the most recent version of Mozzi from Github. Then, following the instructions from the Arduino libraries guide.

In the Arduino IDE, navigate to Sketch > Import Library. At the top of the drop down list, select the option to Add Library. Navigate to the folder's location and open it. Return to the Sketch > Import Library menu. You should now see the library at the bottom of the drop-down menu. It is ready to be used in your sketch.


Quick Start

To hear Mozzi, connect a 3.5mm audio jack with the centre wire to the PWM output on Digital Pin 9* on Arduino, and the ground to the Ground on the Arduino. Use this as a line out which you can plug into your computer and listen to with a sound program like Audacity. Try some examples from the File > Examples > Mozzi menu.

Below is a list of the Digital Pins used by Mozzi for STANDARD mode PWM audio out on different boards. Those which have been tested and reported to work have an x. Feedback about others is welcome.

x 9 Arduino Uno
x 9 Arduino Duemilanove
x 9 Arduino Nano
x 9 Arduino Pro Mini
x 9 Arduino Leonardo ..11 Arduino Mega *broken since Jan 2015
..11 Freetronics EtherMega *broken since Jan 2015 x 9 Ardweeny
x 9 Boarduino ..14 Teensy
x B5 Teensy2
x B5(25) Teensy2++
..13 Sanguino

For details about HIFI mode, read the Mozzi core module documentation.


Using Mozzi

Here's a template for an empty Mozzi sketch:

#include <MozziGuts.h>   // at the top of your sketch

void setup() {
    startMozzi();
}

void updateControl(){
    // your control code
}

int updateAudio(){
    // your audio code which returns an int between -244 and 243
}

void loop() {
    audioHook();
}

There's a detailed example explaining the different parts here.


Documentation

There's documentation in the doc folder in the Mozzi download and online.
There is practical help on the learn page on the Mozzi site.
Start or look up a topic on the users forum.
Also, feel free to submit any issues on the GitHub Mozzi site.
Look for code and usage changes here.


Tweaking Arduino for Faster Audio Code

If you need your synth to run fast, Arduino versions above 1.5 can be tweaked to optimise compiled code for speed instead of small size.

Find Arduino’s platform.txt (on OSX you can find it by searching in Users/your_name/Library/Arduino15). Search and replace -Os with -O2. Save.

It’s explained more thoroughly (for Windows) here.

If you still need more speed, Arduino 1.0.5 produces slightly faster code.


Caveats and Workarounds

  • While Mozzi is running, the Arduino time functions millis(), micros(), delay(), and delayMicroseconds() are disabled.

Mozzi provides EventDelay() for scheduling instead of delay, and mozziMicros() for timing, with 61us resolution (in STANDARD mode).

  • Mozzi interferes with analogWrite(). In STANDARD audio mode, Mozzi takes over Timer0 (pins 5 and 6) and Timer1 (pins 9 and 10), but you can use the Timer2 pins, 3 and 11 (your board may differ). In HIFI mode, Mozzi uses Timer0, Timer1 (or Timer4 on some boards), and Timer2, so pins 3 and 11 are also out.

If you need PWM output (analogWrite()), you can do it on any digital pins using the technique in Mozzi>examples>11.Communication>Sinewave_PWM_pins_HIFI.

  • analogRead() is replaced by mozziAnalogRead(), which works in the background instead of blocking the processor.

Last Resort

The timers can be made available with pauseMozzi(), which suspends audio and control interrupts until you call unpauseMozzi().


If you enjoy using Mozzi for a project, or have extended it, we would be pleased to hear about it and provide support wherever possible. Contribute suggestions, improvements and bug fixes to the Mozzi wiki on Github, or Fork it to contribute directly to future developments.

Mozzi is a development of research into Mobile Sonification in the SweatSonics project.


Contributions / Included Dependencies

Modified versions of the following libraries are included in the Mozzi download:

TimerOne library
FrequencyTimer2 library - now a fork with support for ATmega32u4 processors

Mozzi has also drawn on and been influenced by (among many others):

xorshift random number generator, George Marsaglia, (2003)
ead~.c puredata external (creb library) Copyright (c) 2000-2003 by Tom Schouten (GPL2)
AF_precision_synthesis by Adrian Freed, 2009
Resonant filter posted to musicdsp.org by Paul Kellett, and fixed point version of the filter on dave's blog of art and programming
State Variable filter pseudocode at musicdsp.org
Various examples from Pure Data by Miller Puckette
Practical synthesis tutorials by Andy Farnell