CircuitPython Synthio Tricks
This is a small list of tricks and techniques I use for my experiments
in making synthesizers with synthio, and similar to my "circuitpython-tricks" page.
Some of the synths/boards I've made that can use these techniques:
pico_touch_synth,
qtpy_synth,
pico_test_synth,
macropadsynthplug.
Also check out the "examples" directory for larger examples.
For a more lesson-based approach, with
videos for every lesson,
see the CircuitPython_Synthio_Tutorial.
What is synthio?
- CircuitPython core library
available since 8.2.0-beta0 and still in development!
- Features:
- Polyphonic (12 oscillator) & stereo, 16-bit, with adjustable sample rate
- Oscillators are single-cycle waveform-based allowing for real-time adjustable wavetables
- ADSR amplitude envelope per oscillator
- Oscillator ring modulation w/ customizable ring oscillator waveform
- Extensive LFO system
- multiple LFOs per oscillator (amplitude, panning, pitch bend, ring mod)
- LFOs can repeat or run once (becoming a kind of envelope)
- Each LFO can have a custom waveform with linear interpolation
- LFO outputs can be used by user code
- LFOs can plug into one another
- Customizable LFO wavetables and can be applied to your own code
- Math blocks
with 14 three-term Math operations to adjust LFO ranges, offsets, scales
- Utility functions to easily convert from MIDI note to frequency or V/Oct modular to frequency
- Two-pole resonant low-pass (LPF) / high-pass (HPF) / band-pass (BPF) / notch filter, per-oscillator
- Plugs into existing the
AudioMixer system for use alongside audiocore.WaveFile sample playing
How synthio differs from other synthesis systems
Signal flow in traditional sythesis systems is "wired up" once
(either physically with circuits or virtually with software components)
and then controlled with various inputs. For instance, one may create oscillator, filter, and
amplifier objects, flowing audio from one to the other.
You then twiddle these objects to, for example, adjust pitch and trigger filter and
amplifier envelope generators.
In synthio, the signal chain is re-created each time a note is triggered.
The synthio.Note object is the holder of the oscillator (note.waveform),
the filter (note.filter), the amplitude envelope (note.envelope), among others.
In many cases, to change these features, you create new versions of them with different parameters,
e.g.
note.filter = synth.low_pass_filter(1200,1.3) -- create a new LPF at 1200 Hz w/ 1.3 resonance
note.envelope = synthio.Envelope(release_time=0.8) -- create an envelope w/ 0.8 sec release time
Thus, if you're getting started in the reference docs, the best place to start is
synthio.Note.
What synthio is not
While synthio has extensive modulation capabilities, the signal flow is fixed. It is not a modular-style
synthesis engine. Conceptually it is VCO->VCF->VCA and that cannot be changed.
You cannot treat an oscillator as an LFO, nor can you use an LFO as an audio oscillator.
(however there is built-in ring modulation for multi-waveform mixing)
You cannot swap out the default 2-pole Biquad filter for a 4-pole Moog-style ladder filter emulation,
and you cannot stack filters.
But since each synthio.Note is its own entire signal chain, you can create interesting effects by creating
multiple Notes at the same frequency but with different waveform, filter, amplitude, and modulation settings.
Some examples
If you're familiar with CircuitPython and synthesis, and want to dive in, there are larger
synthio-tricks examples with wiring diagrams. In there you'll find:
Getting started
Which boards does synthio work on?
There's a good chance synthio works on your CircuitPython board. Some boards I like:
- Adafruit QT Py RP2040 with
audiopwmio and PWM circuit
- Raspberry Pi Pico with
audiopwmio and PWM circuit
- Adafruit QT Py ESP32-S3 with
audiobusio and PCM5102 I2S board
- Lolin S2 Mini ESP32-S2 with
audiobusio and PCM5102 I2S board
Since synthio is built in to CircuitPython and CirPy has varying support on different boards,
you will need to check your board's "Built-in modules avialble" section on
circuitpython.org/downloads.
Here's what that section looks like for the QTPy RP2040:
Note that synthio is there, and two audio output methods. CircuitPython supports three
different audio output techniques, with varying availability:
Notice that not all audio output techniques are supported everywhere.
An I2S DAC board is the most widely supported, and highest quality.
Even so, this guide will focus mostly on PWMAudioOut on Pico RP2040 because it's quick and simple,
but any of the above will work.
Audio out hardware
Because there are many audio output methods, there are many different circuits.
Ready-made boards
The simplest will be ready-made boards, like
These all have built in I2S DACs and use audiobusio.I2SOut.
RC filter and audiopwmio.PWMAudioOut
The Pico and some other chips can output sound using PWM (~10-bit resolution) with an RC-filter.
(R1=1k, C1=100nF, Sparkfun TRRS)
Note: this is a very minimal RC filter stage that doesn't do DC-blocking
and proper line driving, but is strong enough to power many headphones.
See here for a more complete RC filter circuit.
I2S stereo DAC
An example I2S DAC is the I2S PCM5102.
An I2S DAC board is capable of stereo CD-quality sound and they're very affordable.
The line out is also strong enough to drive many headphones too, but I usually feed
the output into a portable bluetooth speaker with line in.
Note that in addition to the three I2S signals:
- PCM5102 BCK pin =
bit_clock,
- PCM5102 LRCK pin =
word_select
- PCM5102 DIN pin =
data
you will need to wire:
in addition to wiring up Vin & Gnd. For more details, check out
this post on PCM5102 modules.
Play a note every second
Use one of the above circuits, we can now hear what synthio is doing.