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.

Mozzi supports quite a lot of different Micro controllers, but it does not have any output method that would let you capture the audio to a stream of data, so I have added some simple integration layer for Mozzi to my AudioTools: This lets you send the generated audio via the network or bluetooth, save it to a file or whatever you can imagine…

Example Sketch

Here is the sketch, inspired by Mozzi/examples/#01.Basics converted to use the AudioTools integration:

#include "AudioTools.h"
#include "AudioLibs/AudioBoardStream.h"
#include "AudioLibs/MozziStream.h"
#include <Oscil.h>                // oscillator template
#include <tables/sin2048_int8.h>  // sine table for oscillator

const int sample_rate = 16000;
AudioInfo info(sample_rate, 1, 16);
AudioBoardStream i2s(AudioKitEs8388V1);  // audio sink
MozziStream mozzi; // audio source
StreamCopy copier(i2s, mozzi); // copy source to sink
// use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file
// of table #included above
Oscil<SIN2048_NUM_CELLS, sample_rate> aSin(SIN2048_DATA);
// control variable, use the smallest data size you can for anything used in
// audio
byte gain = 255;

void setup() {
  AudioLogger::instance().begin(Serial, AudioLogger::Info);

  // setup mozzi
  auto cfg = mozzi.defaultConfig();
  cfg.control_rate = CONTROL_RATE;

  // setup output
  auto out_cfg = i2s.defaultConfig();

  // setup mozzi sine
  aSin.setFreq(3320);  // set the frequency

void loop() { copier.copy(); }

void updateControl() {
  // as byte, this will automatically roll around to 255 when it passes 0
  gain = gain - 3;

int updateAudio() {
  return ( * gain) >>
         8;  // shift back to STANDARD audio range, like /256 but faster

We just copy the audio from the MozziStream source to the AudioBoardStream audio sink which is the I2S output for an Audiokit.

Compared with the original sketch, startMozzi() has been replaced with the mozzi.begin(cfg); and instead of calling audioHook() in the loop we use copier.copy();

This and further examples can be found in the examples directory and on Github


With Mozzi I am supporting now quite a rich set of Audio DSP Libraries

  • arduino-stk Synthesis ToolKit in C++ (STK) examples
  • Maximilian cross-platform and multi-target audio synthesis and signal processing library examples
  • Faust A functional programming language for sound synthesis and audio
  • Pure Data Pure Data (or just “Pd”) is an open source visual
  • Mozzi A sound synthesis library for Arduino


Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *