百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

the_synth

> 编程语言
开源

一个易于使用的 4 声多音波表合成器库,适用于 Arduino。

357 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个易于使用的 4 声多音波表合成器库,适用于 Arduino。

theSynth – 4-Voice Wavetable Engine for AVR Arduinos

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.

Features

  • 20 kHz interrupt-driven audio engine (Timer1) with ~45% CPU usage on Uno-class boards
  • Four independent voices with selectable waveforms, envelopes, length, modulation, and MIDI/frequency helpers
  • Multiple output modes: PIN11 (CHA), PIN3 (CHB), or differential (both) on Timer2 pins per MCU
  • MIDI-friendly helpers (mTrigger, setupVoice, synthTick) plus direct frequency/time setters
  • Suspend/resume hooks to free CPU time temporarily
  • Examples covering arbitrary frequency control, modulation, MIDI parsing, pin modes, sequencing, and power management

Supported Boards

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.

Installation

  1. Copy/clone the repository so that library.properties and src/ sit at the root.
  2. Restart the Arduino IDE or run arduino-cli lib install --git-url https://github.com/dzlonline/the_synth.git.
  3. Open an example from the examples/ folder and select a supported board/FQBN.

Wiring Cheat-Sheet

Low-pass filter the PWM output before feeding an amplifier/headphones:

Timer2 pin ---[1 kΩ]---+----||----> Audio Out
                       |   10 µF
                       === 10 nF
                       |
                      GND

Differential mode doubles swing by driving both pins through identical filters into a floating load.

Basic Usage

cpp
#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 output
  • setupVoice() – bulk voice configuration
  • mTrigger() / trigger() – MIDI or raw trigger
  • setWave, setPitch, setEnvelope, setLength, setMod – individual parameters
  • synthTick() – returns true every 4 audio frames for lightweight timing
  • suspend() / resume() – pause/resume the audio ISR

Modernization Notes

  • Library now follows the standard Arduino layout (src/, examples/, library.properties), making it IDE/CLI and Library Manager friendly.
  • Timer/pin configuration is abstracted per AVR family; F_CPU is honored, so 8 MHz boards auto-scale the sample rate divisor.
  • ISR and global state live in src/synth.cpp, preventing multiple-definition issues and keeping synth.h lean.
  • Constants remain compatible (e.g., SINE, CHA), but enums can be swapped in future releases without breaking sketches.
  • README, keywords, and license files have been refreshed to reflect current capabilities.

Roadmap

  1. Add automated builds (GitHub Actions + arduino-cli) for Uno, Nano, Mega, and MightyCore boards.
  2. Offer pluggable output drivers so non-Timer2 MCUs (e.g., ATmega32u4, modern ARM boards) can contribute custom backends.
  3. Provide additional envelope and wavetable generation scripts plus documentation on crafting custom tables.

Contributions and bug reports are welcome—please include board type, sketch, and any oscilloscope captures or MIDI logs when filing issues.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言