Runecraft audio core illustration

Runecraft

The realtime floor: shared contracts, realtime safety, process isolation and logging.

Runecraft is the component that holds the shared contracts and the realtime and cross-process primitives every other component builds on. It is part of Signals & Sorcery, a coherent set of Rust audio building blocks for audio apps, plugins, players and DAWs.

Repositorygithub.com/shiehn/runecraft-audio-core
LicenseMIT, free for commercial and closed-source use
StatusIn preparation
LayerThe floor (how the layers stack)
Crates (planned names)runecraft

What it is

Every audio component needs the same small, sharp set of tools: types that two crates (or two processes) agree on, a way to prove the audio thread never allocates, a way to hand data to and from that thread without locks, and a way to talk to a helper process without sharing its fate. Runecraft is that set, written once, with every unsafe block in one place and every safety contract written down.

It has four parts:

  1. Shared contracts. Plain data types and traits with no dependencies and no unsafe code: log records and levels (the enabled check is one relaxed atomic load, safe on the audio thread), a fixed 64-byte realtime event record, and a state digest trait. Audio buffers, channel layouts, timestamped events, parameter ids and the processor lifecycle are planned.
  2. Realtime safety. An allocation guard for debug and test builds (allocate inside a RealtimeScope and the process stops with a clear message), a wired arena of locked memory with a deferred free, loom-checked handoffs (a single-slot mailbox and SPSC rings), a one-word realtime lock, flush-to-zero floating-point scopes, thread priority and memory calls, a host clock, and a stderr writer that never panics on a closed pipe.
  3. Process isolation. Unlinked shared memory accessed only through bounds-checked atomics, a doorbell the audio thread rings without allocating, child processes with process groups and parent watch, a control channel split into owned send and receive halves that can pass descriptors, and peer credentials.
  4. Realtime-safe logging. Non-realtime code formats only after the level check and sends to a bounded queue that drops and counts when full. Realtime threads push fixed records into their own rings. One drainer writes rotating JSON Lines files.

Usage example

Most users meet Runecraft through a component above it. You use it directly when you write your own realtime code and want the same guarantees.

Illustrative sketch

This is the planned shape of the public API, taken from the READMEopen in new window. It is not final.

use runecraft::alloc_guard::{GuardedAlloc, RealtimeScope};
use runecraft::fpu::FzScope;
use runecraft::handoff::ring;

// Opt in to the allocation guard (it only checks in debug and test builds).
#[global_allocator]
static ALLOC: GuardedAlloc = GuardedAlloc;

// A ring from the control thread to the audio thread.
let (mut to_audio, mut from_control) = ring::<ParamChange>(4096);

// Control thread: push changes; a full ring is the caller's decision, never a wait.
to_audio.push(ParamChange { id, value })?;

// Audio callback:
fn callback(&mut self, out: &mut [f32]) {
    let _rt = RealtimeScope::enter();   // any allocation in here now stops the process in tests
    let _fz = FzScope::enter();         // denormals flush to zero, restored on return
    from_control.drain(|change| self.apply(change));
    self.render(out);
}

A supervisor of a helper process uses the isolation part:

use runecraft::ipc::{channel_pair, Mapping, spawn};

let (region, fd) = Mapping::create(region_len)?;        // unlinked shared memory
let (parent, child_end) = channel_pair()?;               // the control channel
let child = spawn(&program, &args, child_end)?;          // the child gets its end, nothing else
let (mut tx, mut rx) = parent.bind(child.pid())?;        // owned halves for two threads
tx.send(&hello_frame, &[&fd.into()])?;                   // hand the region to the child

How it fits in the ecosystem

Runecraft is the bottom row, the floor, next to Orrery. Dependencies point down, never up.

Below it: nothing. It depends on no other component. The realtime floor depends on libc (and windows-sys on Windows). The contracts depend on nothing.

Above it: everything else may depend on it.

Because unsafe code lives here and only here, the components above can be #![forbid(unsafe_code)].

What it deliberately doesn't do: no audio processing (not even a gain), no devices, files or projects, no async runtime, and no competing with good crates. Where rtrb, basedrop or assert_no_alloc does the job, use it; Runecraft's parts exist so the components share one set of rules.

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

In preparation. The parts described above exist and are tested, but they live in another repository today, under working crate names. Published names and some signatures may change before the first release.

PartmacOSLinuxWindows
Shared contractsyesyesyes
Realtime safetyyes, used daily on Apple siliconcode paths exist, compile-checkedcode paths exist
Process isolationyescompile-checked; the doorbell falls back to polling for nowplanned
Loggingyesnot yet testednot yet tested
Last Updated:
Contributors: shiehn