Arduino “Make Your Uno” Synth – 2 – Mozzi Experiments

Tones was the obvious first choice for some experiments, but I’ve now jumped straight to Mozzi experiments as the second suggested sketch on the Arduino tutorial is a Mozzi sketch.  Otherwise I’d have probably saved this for a little later, but here are some Mozzi experiments you can do with your board right away.

Of course, you’ll need to install the latest Mozzi library.  Details of how to do that are here: https://github.com/sensorium/Mozzi.  Be sure to grab a “ZIP” file using the “Download ZIP” option from the “Code” button (don’t use the listed “releases” – these are very old and no longer used!)

The full index of projects and my personal build notes can be found here: Arduino “Make Your Uno” Synth.

This post contains the following experiments:

  • The recommended Mozzi demo sketch.
  • Some additional Mozzi example sketches to try.
  • My own 5-pot FM synth sketch.

Warning! I strongly recommend using old or second hand equipment for your experiments.  I am not responsible for any damage to expensive instruments!

These are the key Arduino tutorials for the main concepts used in this project:

If you are new to Arduino, see the Getting Started pages.

Parts list

  • Arduino “Make Your Uno” Kit
  • USB-C programming lead

The Circuit

This set of experiments will eventually make use of all five Arduino connected potentiometers and the volume control, but for the first experiments, only A0, A1 and A2 will be used (circled below).

Arduino Synth Shield - Mozzi

Experiment 1 – Default Recommended Mozzi Sketch

Mozzi, by Tim Barrass, is a very comprehensive digital synthesis library for microcontrollers.  As such it is quite complex to use if you’re new to synthesis.

It attempts to model the workings of an analog synthesizer, in that you build up oscillators that create tones, and then send them through filters, get them to modulate each other, add noise, or whatever you like.  Usually the combinations, frequencies and other controlling parameters might be set using physical controls, typically potentiometers, read by your microcontroller.

The sound generation can be shaped by an envelope (to give it a start, stop and various shapes in-between, rather than being continuous) which can be triggered by all sorts of means, from buttons, to sensors, to MIDI controls, to full music keyboards.  But Mozzi doesn’t do any of that, it just does the synthesis part.

The output device varies, it can use PWM audio outputs (as is the default with the Arduino and particularly with the Synth Shield), but it can also use connected digital to analog converters (DACs) and a lot more.

For more details of the potential, it is worth having a look at the tutorial here: https://sensorium.github.io/Mozzi/learn/introductory-tutorial/

But for the purposes of this first experiment, I’m going to use the sketch recommended as part of the Make Your Uno Synth Shield build guide which can be found here:

  • Examples -> Mozzi -> 03.Sensors -> Knob_LightLevel_v2_FMSynth

As stated in the Make You Uno tutorial this was designed for use with a single potentiometer and two light dependant resistors, but it will work fine with three potentiometers too.  The pots are assigned as follows:

  • A0 – carrier frequency – the core basic frequency of the sound.  Adjustable between 22Hz and 440Hz
  • A1 – FM intensity – how “strong” the applied modulation is.
  • A2 – FM modulation rate – the frequency of the modulating frequency.

I suggest you turn up the volume slightly, then adjust A1 and A2 to be fully clockwise which effectively disables the modulation to start with.

Then slowly turning A1 anti-clockwise will increase the intensity of the FM modulation but in a constant manner.  However slowly turning A2 anti-clockwise will introduce the periodic modulating signal.

Some adjustments to the code you could make to make it more “Synth Shield” friendly include:

  • Changing the potentiometers used – in this case I wonder if A1, A3 and A4 would make more sense.  These are set at the top of the code here:
const int KNOB_PIN = 0; // set the input for the knob to analog pin 0
const int LDR1_PIN=1;   // set the analog input for fm_intensity to pin 1
const int LDR2_PIN=2;   // set the analog input for mod rate to pin 2
  • Reversing the sense of the two “LDR” pots as the sketch is setup for the “reverse dynamics” of LDRs.  This can be changed using the MIN/MAX values near the top of the sketch.  Notice how the MIN is greater than the MAX!  Swap these around for a more intuitive result.
const int MIN_INTENSITY = 700;
const int MAX_INTENSITY = 10;

const int MIN_MOD_SPEED = 10000;
const int MAX_MOD_SPEED = 1;
  • In fact while you’re here you can “up” that INTENSITY value to get even wilder effects!  Experiment, but 1000 gives a great range.
  • You can also adjust the top frequency point.  At present it is set to 400Hz which is A4.  Doubling this to 880 gives you an extra octave to play with:
const int MIN_CARRIER_FREQ = 22;
const int MAX_CARRIER_FREQ = 440;
  • Finally the modulation ratio is another fun setting to play with.  This sets the multiplier between the carrier and modulation frequency.  I quite like using 3, especially with a wider range of the other parameters.
int mod_ratio = 5; // brightness (harmonics)

The biggest problem with adjusting these is that a larger range gives you a larger space of very discordant sounds to interesting sounds!  But when you find a new interesting sound, it is definitely interesting!

Of course, more of these updates can be tied to other potentiometers, which is essentially what I did in my own sketch, so I’ll come back to that in a moment.

Experiment 2 – Alternative Mozzi Examples

There are many, many example sketches provided in Mozzi.  Some require extra connected IO and some don’t.  The full list can be “heard” here: https://sensorium.github.io/Mozzi/examples/

But some that work ok with the Synth Shield with minimal adjustment include the following:

  • 01.Basics
    • Sinewave – a basic output signal useful for troubleshooting or investigating the different wave shapes.
    • Vibrato – shows how to use one signal to modulate another.
  • 02.Control
    • Line_Gliss – a fun rising tone sound (very 80s video game like).
  • 03.Sensors
    • Knob_LightLevel_FMSynth – similar to the above LightLevel synth but with simpler controls – just uses A0 (carrier) and A1 (modulation).
    • Knob_LightLevel_v2_FMSynth – the sketch used in experiment 1.
  • 06.Synthesis
    • AM_Synth – amplitude modulation demo.  No additional controls, but will keep playing random notes with their amplitudes modulated in a “tremolo” style effect.
    • FM_Synth – a fun sound-effect type sketch showing off the FM synthesis engine.
    • PDResonant – uses A0 and A1 as the inputs from an X-Y joystick to control the attack and decay of a phase distorted note, so can work quite well with this sketch. Note that by default it keeps playing random notes whilst performing the synthesis.
  • 07.Envelopes
    • Phasemod_Envelop – again no controls, but creates an interesting varying set of synthesized notes showing different envelop parameters being applied.

These will all “do something” with the Synth Shield “as is” and give you a bit of an idea of what the Mozzi library can do.  Nearly all will have some tweakable parameters near the top of the sketch so it is definitely worth having a play!

Experiment 3 – Multi-pot FM Synth

In my project: Arduino Multi-pot Mozzi FM Synthesis – Revisited I’ve provided a sketch that will work with my own synth shield but also with the Make Your Uno shield.

Here I’ve simplified it slightly and removed the MIDI side of things (for now) to let it just play a continuous tone.

The potentiometers are mapped as follows:

Arduino Synth Shield - FM Synth

Start with all pots turned fully anti-clockwise, then increase A4 (and volume) to find a starting note.  Then to get some basic modulation going, increase A3 to set a modulation ratio and then slowly increase A1 to increase the intensity of modulation.  At this point if you wish, you can start adjusting A0 to try different waves (there are four).  You can add some periodic modulation by increasing A2 and vary the modulation ratio by adjusting A3.

Note: if the sound stops, just turn A4 fully “off” and then bring it back up for a new frequency.

There are more details of how the “full” MIDI version works here: Arduino Multi-pot Mozzi FM Synthesis – Revisited.

This version can be downloaded from GitHub here.

Closing Thoughts

As I said, I wouldn’t ordinarily have jumped straight into Mozzi as it is a complicated library to use, but you can get some great results.  So as this was the second official sketch recommended for the Synth Shield tutorial, I thought it would be a good one to do second.

After this I plan to start adding some IO, maybe getting into MIDI, and perhaps revisiting direct digital synthesis from first principles.

Kevin

Leave a comment