SPB Git

Repository Public

0004-real-time-engine.md 2.1 KB

# ADR 0004 — Real-time engine rules

Status: accepted (2026-11-24).

  • One processor, two clocks. Real-time playback and offline rendering run the same Processor; it renders in chunks of at most 64 frames cut on its own grid and at every note and automation boundary, so the result does not depend on the host's block size. Tests check that renders with blocks of 32 to 1024 frames and one giant block are bit-identical.
  • Nothing blocking in process. No allocation, lock, file, network, log or compilation. Everything a program needs is allocated by PreparedProgram::prepare off the audio thread. Tests run the processor under a counting allocator (zero allocations over 1500 callbacks with commands and hot swaps).
  • Control by queues and atomics. Transport, mixer, notes and program swaps go through a single-producer single-consumer ring; meters, position and scope rings are atomics read wait-free by the UI. Retired programs come back through a second ring and are freed off the audio thread.
  • Hot swap. A new program replaces the current one at a chunk boundary with a 30 ms equal-power crossfade; position and live mixer settings are kept; notes sounding at the position are restarted in the new program. A compilation that fails changes nothing.
  • Safety. Non-finite output of a component is replaced by silence and counted; the master has a look-ahead limiter (sample peak) on by default at −1 dBFS; the device output is clamped to ±1; the monitor level starts at −6 dB and is never part of a render; a panic in the engine turns the output to silence instead of noise.
  • Pan law. Constant power, −3.01 dB at centre, on tracks and buses; no pan on the master.
  • Timing. Musical time is exact rationals; seconds come from the tempo map; samples are floor(seconds × rate + 0.5) in one function used by every component.
  • Single audio thread in this version. Not using the other cores is a known limit, measured in Benchmarks/.
Files main
Menu

Theme