Cantrips audio DSP illustration

Cantrips

Built-in mixer DSP: sampler, fader, pan, meters, compressor.

Cantrips is the component that provides the small set of processors every mixer needs. It is part of Signals & Sorcery, a coherent set of Rust audio building blocks for audio apps, plugins, players and DAWs.

Repositorygithub.com/shiehn/cantrips-audio-dsp
LicenseMIT, free for commercial and closed-source use
StatusPlanned
LayerSound and devices (how the layers stack)
Crates (planned names)cantrips

What it is

A DAW doesn't need a huge DSP library to work. It needs a handful of units that are correct, cheap, click-free and predictable, on every track. Cantrips is that handful:

  • Sampler voice: plays a region of a sample with start offset, fades, looping and pitch, at sample-accurate positions.
  • Clip player: plays an audio clip with fades and a short ramp on mute and stop, so nothing clicks.
  • Fader: gain in decibels with smoothing, so automation never zippers.
  • Pan: a documented constant-power pan law for mono and stereo sources.
  • VCA and sum: gain groups and bus summing.
  • Meter: peak and RMS with defined ballistics, feeding Aethergate's shared-memory meters.
  • Latency: a delay line used by delay compensation.
  • Compressor: a simple, transparent channel compressor with threshold, ratio, attack, release, knee and makeup.

Each unit is a plain Rust type with prepare, process and parameter methods, and each can also be a node in Leyline's graph.

Usage example

Illustrative sketch

Planned, not final. Taken from the READMEopen in new window.

use cantrips::{Fader, Pan, PanLaw, Compressor};

let mut fader = Fader::new(48_000.0).smoothing_ms(10.0);
let mut pan = Pan::new(PanLaw::ConstantPower);
let mut comp = Compressor::new(48_000.0);
comp.set_threshold_db(-18.0);
comp.set_ratio(3.0);

// On the audio thread, per block:
fader.set_gain_db(-6.0);          // smoothed over the next few milliseconds
comp.process(&mut left, &mut right);
fader.process(&mut left, &mut right);
pan.process(0.25, &mut left, &mut right);

Used standalone, these are functions on buffers. Used through Leyline, they are built-in nodes the graph compiler places for you.

How it fits in the ecosystem

Cantrips is in the sound and devices row. Dependencies point down, never up.

Below it: only Runecraft (repoopen in new window), whose floating-point scopes keep denormals from costing a spike. The sampler and clip player read plain sample buffers, so they work with audio from Scriptorium (repoopen in new window) or anywhere else without depending on it.

Above it:

What it deliberately doesn't do: no synths, effects suites or creative DSP (that is what plugins through Summoner, and crates such as fundsp, are for), no time-stretch or pitch-shift engine, and no routing (where a signal goes is the graph's decision).

Extend and display
The engine
Musical structure
Signal flow
ComponentRepositoryRoleStatus
Runecraftrunecraft-audio-coreShared contracts, realtime safety, process isolation and realtime-safe logging: the floor every other component stands onIn preparation
Orreryorrery-musical-timeTempo and meter, transports, bar, beat and sample maths, timed MIDIIn preparation
Summonersummoner-plugin-hostOut-of-process VST3 and Audio Unit plugin hosting with crash isolationIn preparation
Aethergateaethergate-audio-platformAudio devices (cpal, CoreAudio, a fake device for tests) and shared-memory metersPlanned
Leylineleyline-audio-graphA realtime audio graph with delay compensation, and a compiler from an edit model to a graphPlanned
Cantripscantrips-audio-dspBuilt-in mixer DSP: sampler, fader, pan, meters, compressorPlanned
Scriptoriumscriptorium-audio-mediaDecode and encode, a sample store, streaming voices, crash-safe recordingPlanned
Tapestrytapestry-session-modelTracks, clips, lanes and scenes; edits with undo; a crash-safe project storePlanned
Processionprocession-timeline-engineWhat plays in each block: regions, notes, automation, launchesPlanned
Grimoiregrimoire-daw-engineThe assembled engine and its headless JSON-RPC protocolPlanned
Familiarfamiliar-plugin-sdkAn SDK for plugins and panels that extend a Signals & Sorcery enginePlanned
Glyphworkglyphwork-audio-uiAudio UI widgets: meters, knobs, faders, waveformsPlanned

Status

Planned. No code yet. The repositoryopen in new window holds the design.

Pure Rust: macOS, Windows and Linux. A WebAssembly build for Web Audio worklets is a later exploration that fits this crate well. Each unit has a short written spec that its tests check, and gives the same output bit for bit, live or offline.

Last Updated:
Contributors: shiehn