Arduino FM MIDI Synthesis with Mozzi – Part 2

This builds on Arduino FM MIDI Synthesis with Mozzi but bases the code on a different example from the Mozzi library and adds a third potentiometer!

Once again, if you are just using the code “as is” this is a beginner project.  To get into the detail of the code though takes it into “advanced” territory!

Warning! I strongly recommend using an old or second hand keyboard for your MIDI 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 Uno
  • 3x 10k potentiometers
  • 1x 270Ω resistor
  • 1x 100nF capacitor
  • MIDI In device (see Arduino MIDI Interfaces)
  • Breadboard and jumper wires

The Circuit

ArduinoMozziMIDIFMSynth_bb

Again the basic sound generation is the same as for the Arduino PWM MIDI Synthesis with Mozzi, with the same added a resistor and capacitor to create a simple low-pass filter on the output from pin 9, as suggested in the Mozzi tutorial on output circuits.

There are now three potentiometers connected to analog inputs A0, A1 and A2 to control the synthesizer parameters and MIDI is connected to the RX pin. Note that, as always, MIDI will have to be disabled to allow the uploading of sketches.

I’ve built this up on a proto-shield but you could easily do the same with a normal breadboard.

The Code

The code is a little more involved this time. Once again though if you just want to experiment you can upload the code and get on with playing about.

This is basically now the Knob_LightLevel_x2_FMsynth example but using potentiometers to control the synthesizer parameters, but I’ve also added MIDI.

Find it on GitHub here.

Advanced Discussion

This code has three oscillators  – a carrier, modulator and a slower-rate “intensity” oscillator.  The carrier frequency is set based on the MIDI note on messages received.  The modulator frequency is set as a ratio of the carrier frequency and that ratio is determined by the position of one of the potentiometers.  The two potentiometers control the modulation rate and intensity.

Once again all the work is done by the phMod() function for the main carrier oscillator but that is as much detail as I can give as, as I said last time, I’m still working out how to use the Mozzi library.

Some notes on the code:

  • The Mozzi updateControl function reads the pots, uses one to set the ratio modulation between 0 and 7; one for the intensity of modulation (between 0 and 1023) and one to set the modulation of the intensity (between 0 and 31).
  • The code uses the same envelope as used in Arduino PWM MIDI Synthesis with Mozzi which is triggered with a note on message and stopped on note off.
  • The frequency of the carrier oscillator is set by the received MIDI note and the frequency of the modulator oscillator is set as a multiple of the carrier specified by the mod_ratio parameter.
  • The oscillators are combined in the updateAudio function, which has to be kept as quick as possible.

This code makes quite a lot of use the Mozzi fixed-point maths variable types, so you’ll see a lot more Q8n16 type references around the code.

Find it on GitHub here.

Closing Thoughts

The results are a lot more pleasing than my first try so I feel like I’m starting to get somewhere now, but there is still a long way to go.

Some other things to try would be the different waveforms and allowing adjustment of the envelope using some more pots.

Kevin

One thought on “Arduino FM MIDI Synthesis with Mozzi – Part 2

  1. Good afternoon! I put everything together according to your scheme and uploaded the code, but I ran into a problem! A diode flashes, indicating that the Arduino is receiving a signal, but only some quiet clicking and whistling sounds are heard on the audio output. Please tell me, what could be the problem? I don’t know English well and I write using an auto-translator, please forgive me for possible mistakes.

    Like

Leave a comment