A simple to use 4 polyphonic wavetable synthesizer library for Arduino.
A simple to use 4 polyphonic wavetable synthesizer library for Arduino.
theSynth is a compact, 20 kHz, four-voice wavetable synthesizer aimed at classic AVR-based Arduinos (Uno, Nano, Pro Mini, Mega, etc.). It produces audio through Timer2 PWM (pin-dependent) and exposes a lightweight API for setting waveforms, envelopes, modulation, and MIDI-triggered playback.
mTrigger, setupVoice, synthTick) plus direct frequency/time setters| MCU | Boards | CHA pin (OC2A) | CHB pin (OC2B) |
|---|---|---|---|
| ATmega328P/PB, 168, 88, 48 | Uno, Nano, Pro Mini, Duemilanove | D11 | D3 |
| ATmega1280/2560 | Mega family | D10 | D9 |
| ATmega644P/1284P | Mighty Core boards | D7 | D6 |
Note: Atmega32u4-based boards (Leonardo/Micro) lack Timer2 and are not currently supported. Non-AVR boards require a new driver backend.
library.properties and src/ sit at the root.arduino-cli lib install --git-url https://github.com/dzlonline/the_synth.git.examples/ folder and select a supported board/FQBN.Low-pass filter the PWM output before feeding an amplifier/headphones:
Timer2 pin ---[1 kΩ]---+----||----> Audio Out
| 10 µF
=== 10 nF
|
GNDDifferential mode doubles swing by driving both pins through identical filters into a floating load.
#include
synth edgar;
void setup() {
edgar.begin(CHA); // choose output mode
edgar.setupVoice(0, SINE, 60, ENVELOPE1, 90, 64); // voice, wave, MIDI, env, length, mod
edgar.setupVoice(1, SAW, 64, ENVELOPE2, 80, 64);
}
void loop() {
edgar.mTrigger(0, 60); // MIDI note on
edgar.setFrequency(1, 329.6f); // arbitrary Hz
edgar.trigger(1); // immediate trigger
delay(400);
}Key helpers:
begin(mode) – configure timers/PWM outputsetupVoice() – bulk voice configurationmTrigger() / trigger() – MIDI or raw triggersetWave, setPitch, setEnvelope, setLength, setMod – individual parameterssynthTick() – returns true every 4 audio frames for lightweight timingsuspend() / resume() – pause/resume the audio ISRsrc/, examples/, library.properties), making it IDE/CLI and Library Manager friendly.F_CPU is honored, so 8 MHz boards auto-scale the sample rate divisor.src/synth.cpp, preventing multiple-definition issues and keeping synth.h lean.SINE, CHA), but enums can be swapped in future releases without breaking sketches.Contributions and bug reports are welcome—please include board type, sketch, and any oscilloscope captures or MIDI logs when filing issues.
No open issues yet, or sync has not completed.