pub struct Engine { /* private fields */ }Expand description
The runtime mixer: owns patch resources and their live instances, and serves
their mixed-down stereo through AudioSource::fill.
use tono_core::prelude::*;
use tono_core::dsl::Node;
let doc = SoundDoc::new("blip", Node::Sine { freq: 880.0.into() });
let mut engine = Engine::new(48_000);
let blip = engine.load(&doc); // a reusable resource…
let _voice = engine.play(blip); // …spawning independent instances
let mut out = vec![0.0f32; 512]; // interleaved stereo L,R,L,R…
engine.fill(&mut out);
assert!(out.iter().any(|s| s.abs() > 0.0), "the blip is sounding");§Threading
Mutating calls (play, set_param,
stop, …) render the whole document synchronously —
O(duration), with allocations — so they must never run on an audio
callback thread. Real-time hosts use split to render on a
pump thread joined to the callback by a wait-free ring. Note that
set_param re-renders the whole doc per call with no coalescing —
rate-limit parameter automation on the control side.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn set_max_voices(&mut self, max: usize)
pub fn set_max_voices(&mut self, max: usize)
Sourcepub fn max_voices(&self) -> Option<usize>
pub fn max_voices(&self) -> Option<usize>
The current polyphony budget, or None if unlimited.
Sourcepub fn sample_rate(&self) -> u32
pub fn sample_rate(&self) -> u32
The engine’s sample rate.
Sourcepub fn load(&mut self, doc: &SoundDoc) -> PatchId
pub fn load(&mut self, doc: &SoundDoc) -> PatchId
Load a bare document as a patch resource (no named parameters).
Sourcepub fn load_patch(&mut self, patch: &Patch) -> PatchId
pub fn load_patch(&mut self, patch: &Patch) -> PatchId
Load a parametric Patch as a resource; its named params become
ParamIds via Engine::param.
Sourcepub fn param(&self, patch: PatchId, name: &str) -> Option<ParamId>
pub fn param(&self, patch: PatchId, name: &str) -> Option<ParamId>
Resolve a named parameter of a patch to a typed handle (once, off the hot
path). None if the patch has no such param.
Sourcepub fn layer(&self, patch: PatchId, name: &str) -> Option<LayerId>
pub fn layer(&self, patch: PatchId, name: &str) -> Option<LayerId>
Resolve a named mixer layer (a tracks entry) to a typed handle. None
if the patch’s graph has no track with that id.
Sourcepub fn play(&mut self, patch: PatchId) -> InstanceHandle
pub fn play(&mut self, patch: PatchId) -> InstanceHandle
Spawn a one-shot instance of a patch (plays once, then culls itself) at
Priority::NORMAL.
Sourcepub fn play_looping(&mut self, patch: PatchId) -> InstanceHandle
pub fn play_looping(&mut self, patch: PatchId) -> InstanceHandle
Spawn a looping instance of a patch (plays until stopped)
at Priority::NORMAL.
Sourcepub fn play_prioritized(
&mut self,
patch: PatchId,
priority: Priority,
) -> InstanceHandle
pub fn play_prioritized( &mut self, patch: PatchId, priority: Priority, ) -> InstanceHandle
Sourcepub fn play_looping_prioritized(
&mut self,
patch: PatchId,
priority: Priority,
) -> InstanceHandle
pub fn play_looping_prioritized( &mut self, patch: PatchId, priority: Priority, ) -> InstanceHandle
Spawn a looping instance with an explicit Priority — e.g. music at
Priority::CRITICAL so it is never stolen by lower one-shots.
Sourcepub fn set_priority(&mut self, h: InstanceHandle, priority: Priority)
pub fn set_priority(&mut self, h: InstanceHandle, priority: Priority)
Change a live instance’s Priority (no-op for an unknown handle).
Sourcepub fn set_gain(&mut self, h: InstanceHandle, gain: f32, tw: Tween)
pub fn set_gain(&mut self, h: InstanceHandle, gain: f32, tw: Tween)
Set an instance’s linear gain, smoothed over tw (no-op if finished).
Sourcepub fn set_pan(&mut self, h: InstanceHandle, pan: f32, tw: Tween)
pub fn set_pan(&mut self, h: InstanceHandle, pan: f32, tw: Tween)
Set an instance’s stereo balance (−1 left … +1 right), smoothed over tw.
Sourcepub fn set_param(
&mut self,
h: InstanceHandle,
param: ParamId,
value: f32,
tw: Tween,
)
pub fn set_param( &mut self, h: InstanceHandle, param: ParamId, value: f32, tw: Tween, )
Set a named parameter on a live instance, crossfading over tw for a
click-free swap. param must come from the same patch the instance plays.
Sourcepub fn set_layer_gain(
&mut self,
h: InstanceHandle,
layer: LayerId,
gain: f32,
tw: Tween,
)
pub fn set_layer_gain( &mut self, h: InstanceHandle, layer: LayerId, gain: f32, tw: Tween, )
Set a named layer’s gain on a live instance, crossfading over tw.
Sourcepub fn stop(&mut self, h: InstanceHandle, fade: Tween)
pub fn stop(&mut self, h: InstanceHandle, fade: Tween)
Stop an instance with a declick fade-out; it is culled once silent. A
zero-length fade is bumped to a short default so stops never click.
Sourcepub fn is_active(&self, h: InstanceHandle) -> bool
pub fn is_active(&self, h: InstanceHandle) -> bool
Whether a handle still refers to a live instance.
Source§impl Engine
impl Engine
Sourcepub fn split(self, ring_frames: usize) -> (Controller, Renderer)
pub fn split(self, ring_frames: usize) -> (Controller, Renderer)
Split into a Controller (control thread) and a Renderer (audio
thread) joined by a wait-free ring ring_frames deep. Pump the controller
off the audio thread; the renderer drains it in the callback.
Trait Implementations§
Source§impl AudioSource for Engine
impl AudioSource for Engine
Source§fn fill(&mut self, out: &mut [f32]) -> usize
fn fill(&mut self, out: &mut [f32]) -> usize
out with the next block of interleaved-stereo audio.Source§fn reset(&mut self)
fn reset(&mut self)
AdaptiveMusic::reset
calls this on each layer.