wavegraph-dsp
wavegraph-dsp runs compiled audio patches on caller-owned buffers without a heap.
It re-exports Event, Op, Port, Process, and ProcessContext from
wavegraph-core. Instrument crates depend on that interface directly.
An application supplies instances and selects the sample format and DSP
implementation.
Rendering a compiled patch
The following program plays the waveform monosynth through a half-gain stage. The note starts at frame 2. Its state carries over to the next block.
use ;
use ;
use I24;
const TUNING: Tuning = new.unwrap;
let mut voice = new;
let program = ;
let mut objects: = ;
let schedule = decode.unwrap;
let mut patch = schedule.bind.unwrap;
let notes = ;
let mut buses = ;
patch.render.unwrap;
assert_eq!;
assert!;
The bytecode module specifies the wire format. Load a plan outside
the audio callback. Each call to render executes it once per block. Control
events retain their frame offsets and ties retain their order. A second program can be
decoded while the first plays. At a block boundary, Patch::replace validates
its object layouts and buffer requirements and switches the schedule. The
instances retain their state.
Awaiting a program change
Enable the async feature and split a wavegraph_dsp::control::EditQueue between
the editor and the render host. The editor calls control.commit(&next).await
with a predecoded program. At a block boundary, the host calls
host.begin_block(|plan| patch.replace(plan, buses.len())) and keeps the
returned revision with the block. When the output accepts it, the host calls
host.submitted(revision, first_frame). The editor receives that revision and
frame, or the error from a rejected replacement. A missed block leaves the
edit pending. Frame numbers come from the host's render timeline.
The queue holds one edit in caller-owned storage. The render callback stays
synchronous. Only the slot and waiter are accessed inside a critical section.
Choose a backend and task waker that fit the audio deadline. On the FM-1 both
endpoints run on CPU0, where the critical section masks interrupts. For desktop
tests, critical-section/std uses a process-wide mutex.
The held-note test exercises a route change during playback.
A host can delegate rendering to another core through two
wavegraph_dsp::mailbox::Mailbox instances in coherent memory. Send a tagged,
exclusively borrowed buffer through one mailbox and receive it back through
the other. The worker keeps its patch and scratch buffers between blocks.
If a deadline passes, ownership stays with the worker until it returns the
buffer. Only a current block accepted by the output earns an edit receipt.
The mailbox test exercises this exchange on two threads.
Platform DSP
dsp::Software provides gain and saturating mix for f32 and signed 24-bit
PCM (I24). A board adapter can depend on wavegraph-core alone and implement
wavegraph_core::Dsp. Pass it to
render to select optimized block operations. Instruments can supply native
processors through the same object table. The application owns the audio
peripheral and its refill timing.
For the FM-1, use the BSP's rational FRAME_RATE for tuning and render
BLOCK_FRAMES at a time. Write I24::inner() into the left and right words
of the stereo output block and submit it with Stream::try_write. Retain the
rendered block on WouldBlock so a retry does not advance the synth twice.
See the FM-1 audio driver.
License
Licensed under either of
at your option.
Contribution
Unless you explicitly state otherwise, you license any contribution you intentionally submit for inclusion in this work (as defined in the Apache-2.0 license) under both licenses above, without additional terms or conditions.