pub struct Synth { /* private fields */ }Expand description
Incremental, allocation-free rendering of a Score or FrameScore into
mono or stereo frames.
All memory is allocated by the constructors, including Synth::from_frames.
Synth::fill allocates nothing,
takes no lock and does not block, so it can run on an audio thread. The samples
do not depend on how the output is split into chunks, and are identical on every
platform: pitch and vibrato use the crate’s own polynomials, not sin or exp.
At the song’s end it continues from the loop point while loops remain. A note that sounds across the loop point restarts there on every repeat. After the last pass it renders the release of the sounding notes, then finishes.
Implementations§
Source§impl Synth
impl Synth
pub fn new( score: &Score, sample_rate: u32, options: &RenderOptions, ) -> Result<Self>
Sourcepub fn new_stereo(
score: &Score,
sample_rate: u32,
options: &RenderOptions,
) -> Result<Self>
pub fn new_stereo( score: &Score, sample_rate: u32, options: &RenderOptions, ) -> Result<Self>
Builds a stereo renderer, with interleaved output through fill and the
mixer’s Stream adapter. Preparation may allocate; fill/reset do not.
Sourcepub fn from_frames(
score: &FrameScore,
map: &TempoMap,
options: &RenderOptions,
) -> Result<Self>
pub fn from_frames( score: &FrameScore, map: &TempoMap, options: &RenderOptions, ) -> Result<Self>
Prepare absolute note frames for mono output, using existing instruments
and allocation-free fill. Unlike Score, the map supports fractional and
changing tempo. Preparation is bounded to 8 tracks, 256 instruments,
200000 notes and a 1200-second body. Map changes must be within that body.
Notes require on < off <= end_frame, ordered onsets, a valid instrument,
volume 0..=15 and velocity 0..=127. Invalid arguments return
InvalidArgument, resource limits LimitExceeded. Expand repetitions
before preparation; options.loops must be Some(0) on this path.
At each frame, onsets run first in track/input order, followed by gate-offs on the remaining held voices, as on Score. Single-voice replacement and pooled stealing retain their semantics. A tie is one extended FrameNote; it preserves oscillator/envelope/filter state across tempo boundaries.
Beat LFO phase integrates scheduled tempos continuously from frame zero; tick macros integrate it relative to note start. Other clocks retain their original units. Release tails drain after the exclusive body end; no leading latency, post-render retiming or automatic limiting is added.
Sourcepub fn from_frames_stereo(
score: &FrameScore,
map: &TempoMap,
options: &RenderOptions,
) -> Result<Self>
pub fn from_frames_stereo( score: &FrameScore, map: &TempoMap, options: &RenderOptions, ) -> Result<Self>
Stereo counterpart of Self::from_frames, including existing synthwave
spread/pan. Multiple prepared sources can use the existing mixer Stream
adapter, with a common map and a shared scheduled start.
Sourcepub fn prepare_controls(
&mut self,
events: &[ControlEvent],
capacity: usize,
) -> Result<()>
pub fn prepare_controls( &mut self, events: &[ControlEvent], capacity: usize, ) -> Result<()>
Prepare a replayable control plan before the first fill (or after reset). Events must be frame-ordered; equal frames follow input order after note onsets/gate-offs. Capacity includes retained history for reset, up to 65536 events/results. Zero capacity with no events disables controls. Preparation allocates; rejection preserves the current plan and renderer. Implicit loops must be disabled. Controls start before the body end and ramps end by it; held/releasing voices retain final values afterward.
Sourcepub fn schedule_control(&mut self, event: ControlEvent) -> Result<ControlId>
pub fn schedule_control(&mut self, event: ControlEvent) -> Result<ControlId>
Add/retarget future control under exclusive source ownership, between
fills. This is a control-thread operation: it may allocate and recompile
queued ramps. Past frames, unsupported/missing targets, invalid ranges or
exponential endpoints fail atomically. A full retained plan is
LimitExceeded. Same-frame ordering is submission order; IDs stay stable.
pub fn controls_len(&self) -> usize
pub fn controls_capacity(&self) -> usize
Sourcepub fn poll_control_event(&mut self) -> Option<ControlReport>
pub fn poll_control_event(&mut self) -> Option<ControlReport>
One result for every executed event. An authored note stolen/ended before its event reports TargetInactive without changing any other voice/lane.
Sourcepub fn control_value(
&self,
target: ControlTarget,
parameter: ControlParameter,
) -> Result<f64>
pub fn control_value( &self, target: ControlTarget, parameter: ControlParameter, ) -> Result<f64>
Applied controller value at the next source frame (frames_rendered),
before queued events at that frame execute. Note targets must be active.
Returns base values until their first event. Requires a prepared plan.
pub fn sample_rate(&self) -> u32
pub fn is_finished(&self) -> bool
Sourcepub fn frames_rendered(&self) -> u64
pub fn frames_rendered(&self) -> u64
Frames rendered since the start or the last Synth::reset.
Sourcepub fn max_frames(&self) -> Option<u64>
pub fn max_frames(&self) -> Option<u64>
An upper bound on the frames this synthesizer renders, or None if it loops forever.
Trait Implementations§
Source§impl Stream for Synth
Available on crate feature synth only.A synthesizer plays as a mono or stereo stream. It loops by itself when its
RenderOptions::loops is None; as a voice
loop it can only return to its start.
impl Stream for Synth
synth only.A synthesizer plays as a mono or stereo stream. It loops by itself when its
RenderOptions::loops is None; as a voice
loop it can only return to its start.