# Audio Synthesis with CircuitPython synthio

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/124/368/medium800/circuitpython_fundamental_synthio.jpg?1694572924)

https://youtu.be/q4MBm8w-dTM

![](https://cdn-learn.adafruit.com/assets/assets/000/124/652/medium800/circuitpython_propmaker_4692.jpg?1695225352)

You can create your own polyphonic audio synthesizer on a microcontroller board using CircuitPython. The `synthio` module makes it sound great and it's easy to use.

This guide covers the fundamentals of audio synthesis using `synthio`, including practical examples. You'll be building your own small-but-powerful synths in no time.&nbsp;

### synthio History

The `synthio` library was originally created as single-voice, monophonic square wave player for MIDI files.

As of CircuitPython 8.1, `synthio` received significant development effort from [Jeff Epler](https://learn.adafruit.com/u/jepler) to turn it into a 12-voice, polyphonic synthesizer that uses a wide variety of waveforms, while adding filters, envelopes, modulation control, and a ring-modulation effect.

Check out the full `synthio` [documentation here](https://docs.circuitpython.org/en/latest/shared-bindings/synthio/index.html#).

Warning: 

### Hardware Requirements

While `synthio` is built into CircuitPython, this doesn't mean that every CircuitPython-capable board can run synthio effectively. Some chips to use for the best results are:

- RP2040/RP2350 -- e.g., Raspberry Pi Pico, QT Py RP2040, Feather RP2350
- EPS32-S2
- EPS32-S3
- iMX RT1011 -- e.g., Metro M7
- SAMD51 "M4" (N.B., a bit hard to find these days)
- nRF52 -- e.g., Feather nRF52840, CLUE

Your chosen board will also need to to support one of the three audio output methods:

- `audioio.AudioOut` -- output to a built-in Digital to Analog Converter (DAC)
- `audiobusio.I2SOut` -- output to I2S DAC amplifier board
- `audiopwmio.PWMAudioOut` -- output of pulse-width modulated square waves that will go through an external resistor-capacitor (RC) circuit to convert to audio

We'll cover these in more depth later in the guide.

### Board Check

You can check to see which modules are supported on any given board by checking the [CircuitPython.org](circuitpython.org/downloads) download page for that board.

In this example, the Feather RP2040 has `synthio` listed, as well as two different audio output modules that will work: `audiobusio` and `audiopwmio`.

![circuitpython_frp2040_4-3.jpg](https://cdn-learn.adafruit.com/assets/assets/000/123/939/medium640/circuitpython_frp2040_4-3.jpg?1692919601)

## Parts

You can run `synthio` on a wide variety of boards, as noted above.

The simplest hardware to get up and running quickly is the PropMaker Feather RP2040, thanks to its on-board I2S amplifier and terminal blocks to screw in your speaker wires.

### Adafruit RP2040 Prop-Maker Feather with I2S Audio Amplifier

[Adafruit RP2040 Prop-Maker Feather with I2S Audio Amplifier](https://www.adafruit.com/product/5768)
The Adafruit Feather series gives you lots of options for a small, portable, rechargeable microcontroller board. By picking a feather and stacking on a FeatherWing you can create advanced projects quickly. One popular combo is our [Feather M4](https://www.adafruit.com/product/3857)...

In Stock
[Buy Now](https://www.adafruit.com/product/5768)
[Related Guides to the Product](https://learn.adafruit.com/products/5768/guides)
![Video of a white hand pressing a button to briefly turn an LED strip into white lights. Also wired up to the microcontroller are a servo motor and a speaker.](https://cdn-shop.adafruit.com/product-videos/640x480/5768-09.jpg)

### Mono Enclosed Speaker with Plain Wires - 3W 4 Ohm

[Mono Enclosed Speaker with Plain Wires - 3W 4 Ohm](https://www.adafruit.com/product/4445)
Listen up! This single&nbsp; 2.8" x 1.2" speaker&nbsp;is&nbsp;the perfect addition to any audio project where you need 4 ohm impedance and 3W or less of power. We particularly like these speakers as they are small and enclosed for good audio volume and quality. This speaker _does..._

In Stock
[Buy Now](https://www.adafruit.com/product/4445)
[Related Guides to the Product](https://learn.adafruit.com/products/4445/guides)
![Enclosed Speaker with wires](https://cdn-shop.adafruit.com/640x480/4445-01.jpg)

For the example videos in this guide we used the parts listed below. Note: any QT Py ESP32-S2, QT Py ESP32-S3, or QT Py RP2040 will work the same for the examples in this guide.

### Adafruit QT Py ESP32-S2 WiFi Dev Board with STEMMA QT

[Adafruit QT Py ESP32-S2 WiFi Dev Board with STEMMA QT](https://www.adafruit.com/product/5325)
What has your favorite Espressif WiFi microcontroller, comes with&nbsp;[our favorite connector - the STEMMA QT](http://adafruit.com/stemma), a chainable I2C port, and has lots of Flash and RAM memory for your next IoT project? What will make your next IoT project flyyyyy? What a...

In Stock
[Buy Now](https://www.adafruit.com/product/5325)
[Related Guides to the Product](https://learn.adafruit.com/products/5325/guides)
![Angled shot of small square purple dev board.](https://cdn-shop.adafruit.com/640x480/5325-12.jpg)

### Adafruit Audio BFF Add-on for QT Py and Xiao

[Adafruit Audio BFF Add-on for QT Py and Xiao](https://www.adafruit.com/product/5769)
Our QT Py boards are a great way to make very small microcontroller projects that pack a ton of power - and now we have a way for you to turn many QT Py boards into powerful audio play projects that are super small!

This BFF comes with a MicroSD card slot that can address up to 64 GB of...

In Stock
[Buy Now](https://www.adafruit.com/product/5769)
[Related Guides to the Product](https://learn.adafruit.com/products/5769/guides)
![Angled shot of small square audio breakout board.](https://cdn-shop.adafruit.com/640x480/5769-00.jpg)

### or
### Adafruit I2S Amplifier BFF Add-On for QT Py and Xiao

[Adafruit I2S Amplifier BFF Add-On for QT Py and Xiao](https://www.adafruit.com/product/5770)
Our QT Py boards are a great way to make very small microcontroller projects that pack a ton of power - and now we have a way for you to add an I2S 3 Watt amplifier, for high quality audio playback,&nbsp;that can fit on the back of your miniature dev board. It uses just three GPIO pins that do...

In Stock
[Buy Now](https://www.adafruit.com/product/5770)
[Related Guides to the Product](https://learn.adafruit.com/products/5770/guides)
![Adafruit I2S Amplifier BFF Add-On for QT Py and Xiao.](https://cdn-shop.adafruit.com/640x480/5770-00.jpg)

### Molex PicoBlade 2-pin Cable - 200mm

[Molex PicoBlade 2-pin Cable - 200mm](https://www.adafruit.com/product/3922)
When 0.1" is too big, and JST PH's too chunky, the ultra-slim "PicoBlade" is a reliable alternative. These are only 1.25mm pitch, but have a nice clicky connection.

This cable is nice and long, 200mm in fact. It's got both small form factor (won't take up a lot...

In Stock
[Buy Now](https://www.adafruit.com/product/3922)
[Related Guides to the Product](https://learn.adafruit.com/products/3922/guides)
![Molex Pico Blade 2-pin Cable pigtail ](https://cdn-shop.adafruit.com/640x480/3922-05.jpg)

### Also:
### Mini Oval Speaker - 8 Ohm 1 Watt

[Mini Oval Speaker - 8 Ohm 1 Watt](https://www.adafruit.com/product/3923)
Hear the good news! This wee speaker&nbsp;is&nbsp;a&nbsp;great addition to any audio project where you need 8 ohm impedance and 1W or less of power. We particularly like this&nbsp;speaker&nbsp;as it is&nbsp;small and comes with nice skinny wires with a connector on the end. It has a handy...

In Stock
[Buy Now](https://www.adafruit.com/product/3923)
[Related Guides to the Product](https://learn.adafruit.com/products/3923/guides)
![Small, black, oval speaker with Pico Blade connector.](https://cdn-shop.adafruit.com/640x480/3923-06.jpg)

### Short Male Header Kit for ItsyBitsy

[Short Male Header Kit for ItsyBitsy](https://www.adafruit.com/product/4173)
These three&nbsp; **Short** &nbsp; **Male&nbsp;Headers** &nbsp;alone are, well, lonely. But pair them with&nbsp;our [ItsyBitsy boards](https://www.adafruit.com/?q=itsybitsy), and you're in business!

These 2.54mm / 0.1" pitch headers are...

In Stock
[Buy Now](https://www.adafruit.com/product/4173)
[Related Guides to the Product](https://learn.adafruit.com/products/4173/guides)
![Angled shot of two short 14-pin plug headers and one short 5-pin plug header.](https://cdn-shop.adafruit.com/640x480/4173-00.jpg)

### Short Female Header Kit for ItsyBitsy

[Short Female Header Kit for ItsyBitsy](https://www.adafruit.com/product/4174)
These three **Short** &nbsp; **Female&nbsp;Headers** &nbsp;alone are, well, lonely. But pair them with any of our&nbsp;[ItsyBitsy](https://www.adafruit.com/?q=itsybitsy)&nbsp;boards, and you're in business!

These headers are particularly cute and...

In Stock
[Buy Now](https://www.adafruit.com/product/4174)
[Related Guides to the Product](https://learn.adafruit.com/products/4174/guides)
![Angled shot of two short 14-pin socket headers and one short 5-pin socket headers.](https://cdn-shop.adafruit.com/640x480/4174-00.jpg)

# Audio Synthesis with CircuitPython synthio

## Synthesizer Fundamentals

Time to review some fundamental synthesis concepts and how they relate to `synthio`.

There are many different ways to approach audio synthesis -- additive synthesis, subtractive synthesis, frequency modulation, phase distortion, waveshaping, physical modeling, wavetables, and more.&nbsp;

We'll look at the building blocks of how **subtractive synthesis** works, since it is the most similar to the `synthio` approach, as well as **wavetable synthesis** , as this is another feature of `synthio`.

Warning: 

## Audio Oscillator, a.k.a VCO

Arguably the most important piece of the subtractive synthesis puzzle -- the audio rate **oscillator**. This is a wave that oscillates at an audible rate -- anywhere from ~20Hz to 20,000Hz. Ultimately, this electrical signal is used to vibrate a speaker cone which disturbs the air, creating sound waves that can reach your ear.

The rate of the oscillation determines the pitch we hear. In many synthesizers the rate/pitch is controlled via voltage signals, hence the name Voltage Controlled Oscillator, or **VCO**. These pitch CV signals typically come from a keyboard or step sequencer.

There is a secondary pitch modification control on most oscillators called&nbsp; **pitch bend** which can nudge the key that's currently being played up or down. Many keyboards have a dedicated pitch bend wheel used for this purpose.

![circuitpython_vco-saw.png](https://cdn-learn.adafruit.com/assets/assets/000/124/152/medium640/circuitpython_vco-saw.png?1693418061)

![circuitpython_vco-triangle.png](https://cdn-learn.adafruit.com/assets/assets/000/124/153/medium640/circuitpython_vco-triangle.png?1693418079)

![circuitpython_vco-square.png](https://cdn-learn.adafruit.com/assets/assets/000/124/154/medium640/circuitpython_vco-square.png?1693418094)

![circuitpython_vco-sine.png](https://cdn-learn.adafruit.com/assets/assets/000/124/155/medium640/circuitpython_vco-sine.png?1693418110)

Primary: 

## Wave Shapes/Wavetables

The shape of the oscillator's wave determines the timbre or "character" of the sound, based on the different harmonic content of the sound above and beyond the fundamental frequency.

Common wave shapes include sawtooth, triangle, square, and sine.

Some oscillators (including `synthio`) have an extra trick up their sleeve -- instead of being confined to a single wave shape, they can use buffered single-cycle waveforms of any shape imaginable, and can morph between two or more of these shapes! This is called **wavetable**  **synthesis** , and it gives huge flexibility in sound design.

![circuitpython_vco-wavetable.png](https://cdn-learn.adafruit.com/assets/assets/000/124/188/medium640/circuitpython_vco-wavetable.png?1693588902)

https://youtu.be/fkfNWBzf6-0

<sub>Patch Symbols from PATCH &amp; TWEAK by Kim Bjørn and Chris Meyer, published by Bjooks, are licensed under CC BY-ND 4.0 </sub><sub>The included symbols are <a href="http://patchandtweak.com/symbols/">available free of use</a> under the <a href="https://creativecommons.org/licenses/by-nd/4.0/deed.en">following terms and license</a>.</sub>

Info: 

## Filter, a.k.a. LPF, HPF, BP, notch

Most oscillator waveforms include a lot of rich harmonics that give them their distinct characters, such as the "buzziness" of a sawtooth wave. A **filter** can be used to cut off some of those harmonics above or below a certain frequency.&nbsp;

**Low-pass filters** can be set to reduce or remove sound above a certain cutoff frequency you chose, which can give your audio a sort of muffled sound.

**High-pass filters** can be set to reduce or remove sound below a certain cutoff frequency, which can give your sound a sort of bright or "tinny" character.

**Band-pass filters** reduce or remove sound both above and below their cutoff frequency.

**Notch filters** work like an inverted band-pass filter, by reducing or removing sound within a min-max cutoff frequency

Many filters also include a control called **resonance** (or **'**** Q'**), which allows you to emphasize the harmonics right at the cutoff frequency. This is the little hump seen in the first two diagrams shown here. Strong resonance loops can start to feedback on themselves and even self-oscillate, which can be an interesting sounding effect.

The particular cutoff frequency of a filter is often modified with incoming control voltage, sent from another modulation source such an **LFO** (more on this below).

![circuitpython_vcf-lowpass-res.png](https://cdn-learn.adafruit.com/assets/assets/000/124/161/medium640/circuitpython_vcf-lowpass-res.png?1693421978)

![circuitpython_vcf-highpass-res.png](https://cdn-learn.adafruit.com/assets/assets/000/124/162/medium640/circuitpython_vcf-highpass-res.png?1693422023)

![circuitpython_vcf-bandpass.png](https://cdn-learn.adafruit.com/assets/assets/000/124/163/medium640/circuitpython_vcf-bandpass.png?1693422596)

![circuitpython_vcf-notch.png](https://cdn-learn.adafruit.com/assets/assets/000/124/190/medium640/circuitpython_vcf-notch.png?1693589567)

https://youtu.be/-0OZNb87zXE

Primary: 

## Amplifier/Attenuator, a.k.a. VCA

An oscillator that drones on forever could get pretty tiresome. In order to play sounds for fixed durations we need a ways to turn the volume up and down!

An **amplifier** (a misnomer we live with in the synth world, because it is technically a loudness attenuator) is used to adjust the volume of the audio oscillator. It will generally be "off" until a CV signal tells it to open up to partial or full volume, allowing the sound to pass through.

Again, this signal that opens and closes the amplifier varying amounts is a control voltage (often coming from an envelope generator as discussed below), hence the name Voltage Controlled Amplifier, or **VCA**.&nbsp;

![circuitpython_vca.png](https://cdn-learn.adafruit.com/assets/assets/000/124/158/medium640/circuitpython_vca.png?1693418899)

Primary: 

https://youtu.be/Re3Il-k05pQ

## Envelope Generator, a.k.a. EG

**Envelope generators** are used to "shape" the loudness of a sound over time, so that we don't live with simple ON-OFF attenuation of the volume.

The envelope generator, or **EG** , is what tells the VCA how loud or quiet to get during the different stages of a note's lifetime.

A typical set of stages on an **EG** are:

- **Attack** - how long it takes from the onset of a note until it reaches it's full volume
- **Decay** - how long it takes for the volume to drop from full attack level to the sustain level
- **Sustain** - the level to stay at while a note is held
- **Release** - how long to take to drop from the sustain level to fully "off" after the note is told to stop playing

For brevity, this type of parameter set is usually referred to as an **ADSR** envelope generator.&nbsp;

The **EG** sends control voltage (CV) to the **VCA** that varies as the **EG** moves through its stages, thus attenuating the loudness of the **VCO** signal traveling through the **VCA**.

But what tells the&nbsp; **EG** when to start and stop? This is a simple ON-OFF signal called a **Gate**. A typical scenario is a key being pressed on a keyboard sends a high Gate signal to the **EG** , and when the key is released on the keyboard a low **Gate** signal is sent to the **EG**.

![circuitpython_env-adsr.png](https://cdn-learn.adafruit.com/assets/assets/000/124/159/medium640/circuitpython_env-adsr.png?1693418960)

https://youtu.be/qqmwITiDADA

Primary: 

Info: 

## Subtractive Synth Signal Flow

Using the above building blocks here is the signal flow for a typical subtractive synth:

![](https://cdn-learn.adafruit.com/assets/assets/000/124/167/medium800/circuitpython_subtractive_patch_01.jpg?1693429787)

Here's how it works:

- You press a key on a keyboard, which sends 1V/Oct pitch CV to the sawtooth **oscillator** , and a Gate signal to the ADSR **envelope generator**
- **Oscillator** sends audio to the **filter** , where certain harmonic above a frequency are reduced
- **Filter** sends the audio to the **amplifier**. The **envelope generator** tells the **amplifier** to attenuate the audio loudness according to its ADSR stages/settings
- The audio then heads off to an **audio output** device, e.g., speakers/headphones/amp, etc. (optionally, it first passes through a **mixer** where it can be combined with other audio)

https://youtu.be/hY-fYOop6x0

## Low Frequency Oscillator, a.k.a., LFO

At any step of the synth signal chain where a knob can be twiddled by hand to modulate the signal, a Low Frequency Oscillator, or **LFO** , can automate the twiddling.

**LFOs** are very similar to audio oscillators, they just have much slower rates, running anywhere from just below audible rates to many seconds or even minutes to complete a single cycle.

A typical use for an **LFO** is to send CV signal to the cutoff frequency input of a filter so that it varies over time.

![circuitpython_lfo-sine.png](https://cdn-learn.adafruit.com/assets/assets/000/124/178/medium640/circuitpython_lfo-sine.png?1693536372)

Primary: 

## Ring Modulation

Ring modulation is a method of multiplying the oscillator frequency (called the "carrier") by a second frequency (called the "modulator"), and then passing along only the sideband frequencies.

Ring mods can produce special effects (Dalek voice from Dr. Who is a classic example) and metallic sounds, since the harmonics produced tend to not be very musical sounding ones.

![circuitpython_ringmod.png](https://cdn-learn.adafruit.com/assets/assets/000/124/189/medium640/circuitpython_ringmod.png?1693589385)

![](https://cdn-learn.adafruit.com/assets/assets/000/124/196/medium800/circuitpython_patch_ringmod.jpg?1693606309)

![](https://cdn-learn.adafruit.com/assets/assets/000/124/191/medium800/circuitpython_ring_mod.jpg?1693591863)

https://youtu.be/QNhQhTXKLjo

Primary: 

## Multiple Voices / Polyphony

The examples above represent a single synthesizer voice, sometimes referred to as a **monophonic** synth. These are great for basslines and sometimes leads, but what about when you want to play a chord?

The good news is, you simply add more voices! `synthio` is a truly **polyphonic** synthesizer, meaning it can play multiple full voices/notes at once. Each note has a full signal chain, so you can adjust all of the parameters (wave shape, pitch, filter, envelope) individually per voice.

These voices/notes can be sent through the **audio mixer** to combine them on their way to the **audio output**.

### Single Voice

Here is a graphical example of a single voice/note.

![circuitpython_note_1.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/184/medium640/circuitpython_note_1.jpg?1693587503)

### Two Voices

This is an example of two voices/notes, running through an **audio mixer** on their way to the **audio output**.

![circuitpython_note_2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/185/medium640/circuitpython_note_2.jpg?1693588431)

### LFOs Added

We've added a couple of LFOs for modulation of filter cutoff on one voice and pitch bend on another.

![circuitpython_note_3.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/186/medium640/circuitpython_note_3.jpg?1693588534)

### Big Polyphony!

Here's an example with eight voices. `synthio` is capable of 12 (or possibly more) note polyphony!

![circuitpython_eight_voice.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/187/medium640/circuitpython_eight_voice.jpg?1693588590)

# Audio Synthesis with CircuitPython synthio

## CircuitPython

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## CircuitPython Quickstart

Follow this step-by-step to quickly get CircuitPython running on your board.

[Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/adafruit_feather_rp2040_prop_maker/)
 **Click the link above to download the latest CircuitPython UF2 file.**

Save it wherever is convenient for you.

![install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/655/medium640/install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg?1618943202)

![](https://cdn-learn.adafruit.com/assets/assets/000/121/865/medium800/adafruit_products_boot_reset.jpg?1686710555)

To enter the bootloader, hold down the **BOOT/**** BOOTSEL button**(highlighted in red above), and while continuing to hold it (don't let go!), press and release the**reset button**(highlighted in red or blue above).&nbsp;**Continue to hold the BOOT/BOOTSEL button until the RPI-RP2 drive appears!**

If the drive does not appear, release all the buttons, and then repeat the process above.

You can also start with your board unplugged from USB, press and hold the BOOTSEL button (highlighted in red above), continue to hold it while plugging it into USB, and wait for the drive to appear before releasing the button.

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

You will see a new disk drive appear called **RPI-RP2**.

&nbsp;

Drag the **adafruit\_circuitpython\_etc.uf2** file to **RPI-RP2.**

![install_circuitpython_on_rp2040_RP2040_bootloader_drive.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/656/medium640/install_circuitpython_on_rp2040_RP2040_bootloader_drive.jpg?1618943666)

![install_circuitpython_on_rp2040_RP2040_drag_UF2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/657/medium640/install_circuitpython_on_rp2040_RP2040_drag_UF2.jpg?1618943674)

The **RPI-RP2** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it, you're done! :)

![install_circuitpython_on_rp2040_RP2040_CIRCUITPY.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/658/medium640/install_circuitpython_on_rp2040_RP2040_CIRCUITPY.jpg?1618943864)

## Safe Mode

You want to edit your **code.py** or modify the files on your **CIRCUITPY** drive, but find that you can't. Perhaps your board has gotten into a state where **CIRCUITPY** is read-only. You may have turned off the **CIRCUITPY** drive altogether. Whatever the reason, safe mode can help.

Safe mode in CircuitPython does not run any user code on startup, and disables auto-reload. This means a few things. First, safe mode _bypasses any code in_ **boot.py** (where you can set **CIRCUITPY** read-only or turn it off completely). Second, _it does not run the code in_ **code.py**. And finally, _it does not automatically soft-reload when data is written to the_ **CIRCUITPY** _drive_.

Therefore, whatever you may have done to put your board in a non-interactive state, safe mode gives you the opportunity to correct it without losing all of the data on the **CIRCUITPY** drive.

### Entering Safe Mode
To enter safe mode when using CircuitPython, plug in your board or hit reset (highlighted in red above). Immediately after the board starts up or resets, it waits 1000ms. On some boards, the onboard status LED (highlighted in green above) will blink yellow during that time. If you press reset during that 1000ms, the board will start up in safe mode. It can be difficult to react to the yellow LED, so you may want to think of it simply as a slow double click of the reset button. (Remember, a fast double click of reset enters the bootloader.)

### In Safe Mode

If you successfully enter safe mode on CircuitPython, the LED will intermittently blink yellow three times.

If you connect to the serial console, you'll find the following message.

```terminal
Auto-reload is off.
Running in safe mode! Not running saved code.

CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.
```

You can now edit the contents of the **CIRCUITPY** drive. Remember, _your code will not run until you press the reset button, or unplug and plug in your board, to get out of safe mode._

## Flash Resetting UF2

If your board ever gets into a really _weird_ state and CIRCUITPY doesn't show up as a disk drive after installing CircuitPython, try loading this 'nuke' UF2 to RPI-RP2. which will do a 'deep clean' on your Flash Memory. **You will lose all the files on the board** , but at least you'll be able to revive it! After loading this UF2, follow the steps above to re-install CircuitPython.

[Download flash erasing "nuke" UF2](https://cdn-learn.adafruit.com/assets/assets/000/101/659/original/flash_nuke.uf2?1618945856)
# Audio Synthesis with CircuitPython synthio

## synthio Getting Started

You can choose from a number of different boards when using synthio. The simplest setup is to use the PropMaker Feather RP2040 with a speaker's negative and positive wires screwed into the speaker terminal blocks as shown here.

![](https://cdn-learn.adafruit.com/assets/assets/000/124/682/medium800/circuitpython_propmaker_4690.jpg?1695235439)

Alternately, you can use a **QT Py ESP32-S2** with either the **I2S Amplifier BFF** or the **Audio BFF** (which has the same amplifier but also adds an SD card reader).

Solder header pins and sockets onto the QT Py and BFF to connect them belly-to-belly as shown, then plug in your speaker (no need for an SD card).

![](https://cdn-learn.adafruit.com/assets/assets/000/124/231/medium800/circuitpython_adafruit_products_5769-06.jpg?1693956023)

## synthio Specific Nomenclature
### Envelope

The Envelope controls how a note's amplitude changes over time. This is divided into 4 sections and controlled by 5 numbers:

- In the first phase, the attack, the note's amplitude rises to the&nbsp;`attack_amplitude`&nbsp;over&nbsp;`attack_time`&nbsp;seconds.
- In the second phase, the decay, the note's amplitude falls by a factor of&nbsp;`sustain_amplitude`&nbsp;over&nbsp;`decay_time`&nbsp;seconds.
- This amplitude is maintained until the note is released, unless the&nbsp;`sustain_amplitude`&nbsp;is zero, in which case the note is released automatically when the amplitude reaches 0.
- When the note is released, it falls to zero amplitude at a rate given by&nbsp;`release_time`.

Different values evoke different kinds of instruments. For instance, a plucked instrument has a very small&nbsp;`attack_time`&nbsp;and fades away in a defined length of time, meaning it has a&nbsp;`sustain_amplitude`&nbsp;of zero.

```auto
envelope = synthio.Envelope(attack_time=0.1, decay_time = 0.1, release_time=0.1, attack_level=1, sustain_level=0.05)
```

### Waveform

A "waveform" is an abstract kind of object. It can be an&nbsp;`array.array('h', ...)`&nbsp;or a&nbsp;`np.array(..., dtype=np.int16)`, a&nbsp;`memoryview`&nbsp;or any other in memory buffer that contains signed 16-bit values.

This waveform is usually a small file, with just a few hundred samples, because it represents just a single "cycle" of the sound.

Waveforms are used by `Notes` and by `LFOs`.

```auto
import synthio
import ulab.numpy as np

wave_sine = np.array(np.sin(np.linspace(0, 2*np.pi, SAMPLE_SIZE, endpoint=False)) * SAMPLE_VOLUME, dtype=np.int16)
wave_saw = np.linspace(SAMPLE_VOLUME, -SAMPLE_VOLUME, num=SAMPLE_SIZE, dtype=np.int16)
wave_tri = np.concatenate((np.linspace(-SAMPLE_VOLUME, SAMPLE_VOLUME, num=half_period, dtype=np.int16),
                                np.linspace(SAMPLE_VOLUME, -SAMPLE_VOLUME, num=half_period, dtype=np.int16)))
wave_square = np.concatenate((np.full(half_period, SAMPLE_VOLUME, dtype=np.int16),
                              np.full(half_period, -SAMPLE_VOLUME, dtype=np.int16)))
```

### Note

Each individual sound is a&nbsp;`Note`. A note has a bunch of properties:

- `waveform`: a small memory buffer that sets the overall tone of an instrument.
- `envelope`: an object to define how the overall note amplitude changes over time
- `frequency`: the basic frequency of the note in Hz (which can be modified by&nbsp;`bend`)
- `bend`: a modification to the basic frequency of the note, in units of 1/octave. This can be a number, or a&nbsp;`Block`&nbsp;in case the bend value should vary over time (e.g., a vibrato effect)
- `amplitude`: a modification to the note amplitude. This can be a number, or a&nbsp;`Block`&nbsp;in case the amplitude value should vary over time (e.g., a tremolo effect)
- `ring_waveform`,&nbsp;`ring_frequency`,&nbsp;`ring_bend`: A second, optional waveform that modulates the main waveform to create richer sounds

```auto
note1 = synthio.Note(frequency, panning, waveform, envelope, amplitude, bend, filter, ring_frequency, ring_bend, ring_waveform)
```

Blocks: LFOs and Math

Another way to create rich sounds is to vary parameters over time. The Note parameters that can be varied in this way are&nbsp;`bend`,&nbsp;`amplitude`, and&nbsp;`ring_amplitude`.

Furthermore, multiple Math and LFO blocks can be connected together.

An LFO has these settable properties:

- `waveform`
- `rate`
- `gain`
- `offset`
- `once`

It also has a&nbsp;`phase`&nbsp;accumulator and an output&nbsp;`value`. Here's how an LFO works:

- the&nbsp;`phase`&nbsp;advances over time, at the given&nbsp;`rate`. If&nbsp;`rate`&nbsp;is negative, then it "advances" towards smaller numbers.
- when the&nbsp;`phase`&nbsp;passes 1, it wraps around to 0. When going in reverse, values wrap from 0 back to 1.
- When&nbsp;`once`&nbsp;is&nbsp;`True`, the phase will stick at 0 or 1 rather than wrapping around.
- The&nbsp;`waveform`&nbsp;is indexed based on the&nbsp;`phase`. This value is multiplied by&nbsp;`gain`&nbsp;and then&nbsp;`offset`&nbsp;is added to create the final output value

The&nbsp;`waveform`&nbsp;lets you create different ramps, the same as for notes.

```auto
lfo = synthio.LFO(rate=0.6, scale=0.05, phase_offset=0.0, once=False)
```

For more details, check out the full `synthio` [documentation here](https://docs.circuitpython.org/en/latest/shared-bindings/synthio/index.html#).

Next, we'll get into the code examples.

# Audio Synthesis with CircuitPython synthio

## Simple synthio Examples

Let's get to some real-world examples! These are adapted from Tod Kurt's excellent [CircuitPython Synthio Tricks](https://github.com/todbot/circuitpython-synthio-tricks) page.

## Simple Note
![circuitpython_vco-square.png](https://cdn-learn.adafruit.com/assets/assets/000/124/269/medium640/circuitpython_vco-square.png?1694461677)

https://youtu.be/3pqXbFdUL08

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Synthio_Fundamentals/example_01_single_note.py

## Simple Chord
![circuitpython_vco-square.png](https://cdn-learn.adafruit.com/assets/assets/000/124/273/medium640/circuitpython_vco-square.png?1694461860)

![circuitpython_vco-square.png](https://cdn-learn.adafruit.com/assets/assets/000/124/274/medium640/circuitpython_vco-square.png?1694461874)

![circuitpython_vco-square.png](https://cdn-learn.adafruit.com/assets/assets/000/124/275/medium640/circuitpython_vco-square.png?1694461888)

https://youtu.be/s8j39mN4muk

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Synthio_Fundamentals/example_02_chord.py

## Simple Chord with Mixer
![circuitpython_cv-mixer.png](https://cdn-learn.adafruit.com/assets/assets/000/124/265/medium640/circuitpython_cv-mixer.png?1694461572)

https://youtu.be/tYwIBqPnj1Q

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Synthio_Fundamentals/example_03_chord_mixer.py

## Amplitude Envelope
![circuitpython_env-adsr.png](https://cdn-learn.adafruit.com/assets/assets/000/124/263/medium640/circuitpython_env-adsr.png?1694461441)

https://youtu.be/ZcoO6SdhHWg

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Synthio_Fundamentals/example_04_envelope.py

## Filters
![circuitpython_vcf-lowpass-res.png](https://cdn-learn.adafruit.com/assets/assets/000/124/270/medium640/circuitpython_vcf-lowpass-res.png?1694461729)

https://youtu.be/1nZNk-g_7mc

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Synthio_Fundamentals/example_05_filters.py

## MIDI Note Input
![circuitpython_keyboard-ctrl.png](https://cdn-learn.adafruit.com/assets/assets/000/124/276/medium640/circuitpython_keyboard-ctrl.png?1694461938)

https://youtu.be/g53IJJLGq4k

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Synthio_Fundamentals/example_06_MIDI_input.py

## MIDI CC Input
![circuitpython_touch-ctrl.png](https://cdn-learn.adafruit.com/assets/assets/000/124/277/medium640/circuitpython_touch-ctrl.png?1694461993)

https://youtu.be/OXGA7IUByOo

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Synthio_Fundamentals/example_07_MIDI_input_CC.py

## LFO Pitch Bend
![circuitpython_lfo-triangle.png](https://cdn-learn.adafruit.com/assets/assets/000/124/279/medium640/circuitpython_lfo-triangle.png?1694462031)

https://youtu.be/oFEmkE7tqIo

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Synthio_Fundamentals/example_08_LFO_pitch.py

## LFO Tremolo
## LFO Tremolo
![circuitpython_lfo-sine.png](https://cdn-learn.adafruit.com/assets/assets/000/124/280/medium640/circuitpython_lfo-sine.png?1694462094)

https://youtu.be/TBv9AnXxq4M

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Synthio_Fundamentals/example_09_LFO_tremolo.py

# Audio Synthesis with CircuitPython synthio

## Advanced synthio Examples

## Waveshapes

The default waveshape of a `Note`'s oscillator in **synthio** is a square wave. You can use any single-cycle waveshape imaginable, however, by creating a wave shape buffer with sample points in the shape of your wave.&nbsp;

These are then assigned to the `Note`'s `waveform` parameter.

![circuitpython_vco-sine.png](https://cdn-learn.adafruit.com/assets/assets/000/124/285/medium640/circuitpython_vco-sine.png?1694462320)

![circuitpython_vco-triangle.png](https://cdn-learn.adafruit.com/assets/assets/000/124/286/medium640/circuitpython_vco-triangle.png?1694462335)

![circuitpython_vco-saw.png](https://cdn-learn.adafruit.com/assets/assets/000/124/287/medium640/circuitpython_vco-saw.png?1694462354)

![circuitpython_vco-square.png](https://cdn-learn.adafruit.com/assets/assets/000/124/288/medium640/circuitpython_vco-square.png?1694462372)

https://youtu.be/PbC0tSYBPzU

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Synthio_Fundamentals/example_10_waveshapes.py

## Waveshape Morphing

DIY waveshapes are cool, but even cooler is the ability to morph between waveshapes in real time!

This is done by creating the Note object with an empty waveform buffer, and then instead of replacing that buffer, we copy the new wave into it with with `note.waveform[:] = new_wave`

![circuitpython_vco-wavetable.png](https://cdn-learn.adafruit.com/assets/assets/000/124/289/medium640/circuitpython_vco-wavetable.png?1694463365)

https://youtu.be/YLHWImjv7tc

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Synthio_Fundamentals/example_11_wavetable_morph.py

## Detuning Oscillators for Fatter Sound

Since we have fine-grained control over a note's frequency with&nbsp;`note.frequency`, this means we can do a common technique for getting a "fatter" sound. When a note is played at a specific pitch, a second note object is created with a slightly shifted pitch, which adds organic "movement" and a sort of chorusing effect to the notes.

We can stack up a bunch of these progressively further detuned notes to create a huge wall of synth awesomeness!

https://youtu.be/ya936IeAHvs

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Synthio_Fundamentals/example_12_detuned_oscs.py

## Wavetables
https://youtu.be/_tD35PgaRZQ

https://youtu.be/q4MBm8w-dTM

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Synthio_Fundamentals/example_13_wavetable_scanning.py

# Larger Examples
## Tyrell Desktop Synth

This synthio-based creation is an adaptation of Tod Kurt's [eighties\_dystopia](https://github.com/todbot/circuitpython-synthio-tricks/tree/main/examples/eighties_dystopia) synth. It combines many of the concepts we've covered, including:

- detuned oscillators
- LFO modulation of filter cutoff
- saw wave oscillators
- user pitch input

For more info, check out [the full Learn Guide](https://learn.adafruit.com/tyrell-desktop-synthesizer/overview).

![circuitpython_tyrell_desk_synth_beaut2k.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/291/medium640/circuitpython_tyrell_desk_synth_beaut2k.jpg?1694470388)

https://youtu.be/MXF9zLSvprM

### Circle of Fifths Euclidean Synth

&nbsp;

This synth by [Liz Clark](https://learn.adafruit.com/u/BlitzCityDIY) celebrates all things circular: the circle of fifths, Euclidean rhythms, and rotary encoders. Four synth voices play random notes in a triad to the beat of a determined Euclidean rhythm animated on the 8x8 matrix. You can scroll through the&nbsp;[circle of fifths](https://en.wikipedia.org/wiki/Circle_of_fifths)&nbsp;on each synth voice to change the triad for easy modulation between keys.

For more info, check out the [full Learn Guide](https://learn.adafruit.com/circle-of-fifths-euclidean-synth-with-synthio-and-circuitpython/overview).

![circuitpython_led_matrices_edited_P1400783.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/369/medium640/circuitpython_led_matrices_edited_P1400783.jpg?1694576292)

https://youtu.be/Exk-TGRGq00?feature=shared

### Computer Perfection Synthesizer

&nbsp;

This project takes the Computer Perfection and reuses its buttons and switches to trigger a polyphonic, multi-timbral wavetable synthesizer for all your spacey jam sessions. It includes ADSR envelopes and LFO modulation for a beautiful, other-worldly sound.

For more info, check out the [full Learn Guide](https://learn.adafruit.com/computer-perfection-synthesizer/overview).

![circuitpython_cp_thumb2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/370/medium640/circuitpython_cp_thumb2.jpg?1694576511)

https://youtu.be/PmIr5AsGhzI?feature=shared

## Monosynth

Another awesome Tod Kurt creation, this is a [monosynth created in synthio](https://github.com/todbot/circuitpython-synthio-tricks/blob/main/examples/monosynth1/code.py) that you can control with a MIDI keyboard.

You can plug it into your computer or other USB MIDI Host, or a keyboard via UART (classic DIN-5 or TRS MIDI).

![circuitpython_monosynth.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/292/medium640/circuitpython_monosynth.jpg?1694471048)

https://www.youtube.com/live/F0rGCFTweJY?feature=shared&t=2966

## Wavetable Polysynth

Tod's done it again. This is a [syntio-based polyphonic synth](https://github.com/todbot/circuitpython-synthio-tricks/blob/main/examples/wavetable_midisynth/code.py) that uses a Mutable Instruments Plaits wavetable for wave shape morphing source.

![circuitpython_wavetable_poly.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/293/medium640/circuitpython_wavetable_poly.jpg?1694471845)

https://youtu.be/CrxaB_AVQqM

## Mini Arpeggiator

This "todbot" character sure is prolific! Here's his self-contained arpeggiator synth (with controls for root note, BPM, pattern, and pattern octaves) called&nbsp; [eighties\_arp](https://github.com/todbot/circuitpython-synthio-tricks/blob/main/examples/eighties_arp/code.py)

![circuitpython_todarp.jpg](https://cdn-learn.adafruit.com/assets/assets/000/124/294/medium640/circuitpython_todarp.jpg?1694477384)

https://youtu.be/noj92Ae0IQI


## Featured Products

### Adafruit RP2040 Prop-Maker Feather with I2S Audio Amplifier

[Adafruit RP2040 Prop-Maker Feather with I2S Audio Amplifier](https://www.adafruit.com/product/5768)
The Adafruit Feather series gives you lots of options for a small, portable, rechargeable microcontroller board. By picking a feather and stacking on a FeatherWing you can create advanced projects quickly. One popular combo is our [Feather M4](https://www.adafruit.com/product/3857)...

In Stock
[Buy Now](https://www.adafruit.com/product/5768)
[Related Guides to the Product](https://learn.adafruit.com/products/5768/guides)
### Mono Enclosed Speaker with Plain Wires - 3W 4 Ohm

[Mono Enclosed Speaker with Plain Wires - 3W 4 Ohm](https://www.adafruit.com/product/4445)
Listen up! This single&nbsp; 2.8" x 1.2" speaker&nbsp;is&nbsp;the perfect addition to any audio project where you need 4 ohm impedance and 3W or less of power. We particularly like these speakers as they are small and enclosed for good audio volume and quality. This speaker _does..._

In Stock
[Buy Now](https://www.adafruit.com/product/4445)
[Related Guides to the Product](https://learn.adafruit.com/products/4445/guides)
### Adafruit QT Py RP2040

[Adafruit QT Py RP2040](https://www.adafruit.com/product/4900)
What a cutie pie! Or is it... a QT Py?&nbsp;This diminutive dev board comes with one of our new favorite chip, the RP2040. It's been made famous in the new [Raspberry Pi Pico](https://www.adafruit.com/pico) _and_ our [Feather...](http://www.adafruit.com/product/4884)

Out of Stock
[Buy Now](https://www.adafruit.com/product/4900)
[Related Guides to the Product](https://learn.adafruit.com/products/4900/guides)
### Adafruit Audio BFF Add-on for QT Py and Xiao

[Adafruit Audio BFF Add-on for QT Py and Xiao](https://www.adafruit.com/product/5769)
Our QT Py boards are a great way to make very small microcontroller projects that pack a ton of power - and now we have a way for you to turn many QT Py boards into powerful audio play projects that are super small!

This BFF comes with a MicroSD card slot that can address up to 64 GB of...

In Stock
[Buy Now](https://www.adafruit.com/product/5769)
[Related Guides to the Product](https://learn.adafruit.com/products/5769/guides)
### Adafruit I2S Amplifier BFF Add-On for QT Py and Xiao

[Adafruit I2S Amplifier BFF Add-On for QT Py and Xiao](https://www.adafruit.com/product/5770)
Our QT Py boards are a great way to make very small microcontroller projects that pack a ton of power - and now we have a way for you to add an I2S 3 Watt amplifier, for high quality audio playback,&nbsp;that can fit on the back of your miniature dev board. It uses just three GPIO pins that do...

In Stock
[Buy Now](https://www.adafruit.com/product/5770)
[Related Guides to the Product](https://learn.adafruit.com/products/5770/guides)
### Molex PicoBlade 2-pin Cable - 200mm

[Molex PicoBlade 2-pin Cable - 200mm](https://www.adafruit.com/product/3922)
When 0.1" is too big, and JST PH's too chunky, the ultra-slim "PicoBlade" is a reliable alternative. These are only 1.25mm pitch, but have a nice clicky connection.

This cable is nice and long, 200mm in fact. It's got both small form factor (won't take up a lot...

In Stock
[Buy Now](https://www.adafruit.com/product/3922)
[Related Guides to the Product](https://learn.adafruit.com/products/3922/guides)
### Short Male Header Kit for ItsyBitsy

[Short Male Header Kit for ItsyBitsy](https://www.adafruit.com/product/4173)
These three&nbsp; **Short** &nbsp; **Male&nbsp;Headers** &nbsp;alone are, well, lonely. But pair them with&nbsp;our [ItsyBitsy boards](https://www.adafruit.com/?q=itsybitsy), and you're in business!

These 2.54mm / 0.1" pitch headers are...

In Stock
[Buy Now](https://www.adafruit.com/product/4173)
[Related Guides to the Product](https://learn.adafruit.com/products/4173/guides)
### Short Female Header Kit for ItsyBitsy

[Short Female Header Kit for ItsyBitsy](https://www.adafruit.com/product/4174)
These three **Short** &nbsp; **Female&nbsp;Headers** &nbsp;alone are, well, lonely. But pair them with any of our&nbsp;[ItsyBitsy](https://www.adafruit.com/?q=itsybitsy)&nbsp;boards, and you're in business!

These headers are particularly cute and...

In Stock
[Buy Now](https://www.adafruit.com/product/4174)
[Related Guides to the Product](https://learn.adafruit.com/products/4174/guides)

## Related Guides

- [Adafruit QT Py RP2040](https://learn.adafruit.com/adafruit-qt-py-2040.md)
- [Adafruit RP2040 Prop-Maker Feather](https://learn.adafruit.com/adafruit-rp2040-prop-maker-feather.md)
- [Adafruit I2S Amplifier BFF](https://learn.adafruit.com/i2s-amplifier-bff.md)
- [Adafruit Audio BFF](https://learn.adafruit.com/adafruit-audio-bff.md)
- [3D Scans for Low Poly Statues](https://learn.adafruit.com/low-poly-3d-scans-for-3d-printing.md)
- [NeoKey Emoji Keyboard](https://learn.adafruit.com/neokey-emoji-keyboard.md)
- [Color Sensing Music Player](https://learn.adafruit.com/color-sensing-music-player.md)
- [Ahsoka Lightsaber Prop-Maker RP2040 retrofit](https://learn.adafruit.com/lightsaber-retrofit.md)
- [Split Ortho Keyboard with TCA8418 Matrix Expanders](https://learn.adafruit.com/split-ortho-keyboard.md)
- [Tyrell Desktop Synthesizer](https://learn.adafruit.com/tyrell-desktop-synthesizer.md)
- [USB Rotary Media Dial](https://learn.adafruit.com/usb-rotary-media-dial.md)
- [IBM PC Keyboard to USB HID with CircuitPython](https://learn.adafruit.com/ibm-pc-keyboard-to-usb-hid-with-circuitpython.md)
- [Prop-Maker Feather Talking Adabot Clock](https://learn.adafruit.com/prop-maker-feather-talking-adabot-clock.md)
- [How to Choose a Microcontroller](https://learn.adafruit.com/how-to-choose-a-microcontroller.md)
- [Make a Zelda Master Sword with the RP2040 Prop-Maker Feather](https://learn.adafruit.com/master-sword-rp2040.md)
- [Mario Magic Wand](https://learn.adafruit.com/mario-magic-wand.md)
- [Cartoon Character Clock](https://learn.adafruit.com/cartoon-character-clock.md)
- [An Introduction to RP2040 PIO with CircuitPython](https://learn.adafruit.com/intro-to-rp2040-pio-with-circuitpython.md)
- [Knobby Sequencer](https://learn.adafruit.com/knobby-sequencer.md)
