Skip to content
aarushvanPublic

About

C++20 WAV renderer and browser AudioWorklet synthesizer with shared patches and MIDI input.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

slewbox

CI Live Synth Studio

A C++20 WAV renderer and zero-build browser synthesizer. Both use 48 kHz stereo audio, 16 voices, and the same JSON patches and sequence timing.

Play the live Web AudioWorklet synth studio

flowchart LR
    In["JSON Patch + Sequence / Web MIDI"] --> Core["16-Voice Engine (saw / granular / fm / sub)"]
    Core --> Filter["2x Oversampled Chamberlin SVF"]
    Filter --> Env["ADSR Envelope + tanh Drive"]
    Env --> OutWeb["Web AudioWorklet (48 kHz live + WAV export)"]
    Env --> OutCli["C++20 CLI (PCM16 stereo RIFF WAV)"]
Loading

Quickstart

Requires clang++ with a C++20 standard library and Make. Build on macOS or Linux.

make build
./build/slewbox version
./build/slewbox render --patch fm --seq '60:0:0.4,64:0:0.4,67:0.4:0.8' --out melody.wav --json

render requires --patch and --out. A patch can be saw, granular, fm, sub, or a JSON file. Without a sequence, the default is MIDI note 60 in a two-second WAV. The note gate is 0.75 seconds or 75% of the render length, whichever is shorter.

Each sequence entry is pitch:start:duration in MIDI note numbers and seconds. Give several entries the same start time to play a chord. In sequence mode the default output ends after the last note's release, up to the 600-second limit. An explicit --seconds sets the exact rounded frame count and can truncate notes or tails. --json prints a summary with sampleRate, channels, frames, and peak. WAV files use signed little-endian 16-bit stereo PCM. Sequence text is the native melody input.

Browser studio

Serve web/ over localhost or HTTPS. For example, with Python's built-in server:

python3 -m http.server 8000 --bind 127.0.0.1 --directory web

Open localhost:8000 in a browser with AudioWorklet support. Select Start audio to play the screen keyboard or the labeled QWERTY keys. Use Enable MIDI in a browser with Web MIDI support to play an external controller. The browser may prompt for device permission.

JSON patches can be imported or exported in either studio or CLI. Download WAV renders the entered sequence and current patch in an offline worklet. You can download a render before starting live audio.

Patch and DSP

The patch is a flat JSON object with unique field names. Missing fields use the saw defaults. To start from a different preset's settings, export the complete preset. Distinct presets share the shape below.

Key Allowed values
engine saw, granular, fm, sub
cutoffHz 20 to 12000 Hz
resonance 0 to 0.98
attackSec, decaySec 0 to 5 s
sustain 0 to 1
releaseSec 0 to 10 s
detuneCents 0 to 100 cents
fmRatio 0.125 to 16
fmIndex 0 to 20
grainSizeMs 8 to 200 ms
grainDensity 1 to 100 grains/s per voice
drive 0.1 to 12
gain 0 to 1

The saw engine uses two PolyBLEP oscillators and a sine sub. Granular uses a 2048-sample waveform, Hann windows, seeded grain offsets and panning, and a fixed pool per voice. FM uses a sine carrier with a sine modulator and a decaying modulation index. Sub combines a half-frequency sine with a quiet PolyBLEP saw.

Every voice runs through a stereo, 2x oversampled Chamberlin low-pass filter, ADSR, and tanh drive. The mix is soft-limited below full scale. Notes overlap independently, including repeated pitches, and the oldest voice is stolen when all 16 slots are occupied. Live ADSR time edits apply to stages that begin after the edit.

The native sample loop and worklet process() use bounded, preallocated DSP state and acquire no locks. The worklet handles the standard 128-frame render quantum and iterates over the actual buffer length. Offline note events use absolute sample positions. Live note messages enter at browser scheduling boundaries. The two implementations use the same algorithms and seed, with possible floating-point differences across C++ and JavaScript math libraries.

Tests and benchmark

Run make test test-web with Node.js 20+ for native DSP tests and worklet parity checks against the CLI. The parity suite runs the processor directly without a browser.

Run make -B bench to build and time 240,000 frames per engine with all 16 voices held. This measures the native DSP loop in memory. Results below are from an Apple M5 with Apple Clang 21.0.0 and -O2.

Engine Frames/s Real-time multiple
Saw 2,738,100 57.0438×
Granular 2,409,450 50.1968×
FM 2,857,010 59.5211×
Sub 4,624,750 96.3489×

Releases and license

GitHub Actions builds and tests on macOS arm64 and Linux x86_64. A pushed v* tag publishes slewbox-darwin-arm64, slewbox-linux-x86_64, and SHA256SUMS. Downloaded binaries may need executable permissions restored with chmod +x.

Dual licensed under MIT or Apache-2.0, at your option.

About

C++20 WAV renderer and browser AudioWorklet synthesizer with shared patches and MIDI input.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages