pub trait Voice {
type SharedData<'a>: Clone;
// Required methods
fn new(max_samples_per_process_call: usize, sampling_rate: f32) -> Self;
fn handle_event(&mut self, event: &EventData);
fn process(
&mut self,
events: impl IntoIterator<Item = Event>,
params: &impl BufferStates,
note_expressions: NoteExpressionCurve<impl Iterator<Item = NoteExpressionPoint> + Clone>,
data: Self::SharedData<'_>,
output: &mut [f32],
);
fn quiescent(&self) -> bool;
fn reset(&mut self);
// Provided method
fn skip_samples(&mut self, _num_samples: usize) { ... }
}
Expand description
A single voice in a polyphonic synth.
Required Associated Types§
Data that is shared across all voices. This could include things like low frequency oscillators that are used by multiple voices.
Required Methods§
Sourcefn handle_event(&mut self, event: &EventData)
fn handle_event(&mut self, event: &EventData)
Handles a single event outside of audio processing.
Note that events sent during a process
call must be handled there.
Sourcefn process(
&mut self,
events: impl IntoIterator<Item = Event>,
params: &impl BufferStates,
note_expressions: NoteExpressionCurve<impl Iterator<Item = NoteExpressionPoint> + Clone>,
data: Self::SharedData<'_>,
output: &mut [f32],
)
fn process( &mut self, events: impl IntoIterator<Item = Event>, params: &impl BufferStates, note_expressions: NoteExpressionCurve<impl Iterator<Item = NoteExpressionPoint> + Clone>, data: Self::SharedData<'_>, output: &mut [f32], )
Renders audio for this voice.
Audio for the voice will be written into the output
buffer, which will
start out filled with silence.
Provided Methods§
Sourcefn skip_samples(&mut self, _num_samples: usize)
fn skip_samples(&mut self, _num_samples: usize)
Called in lieu of process
when the voice is quiescent.
Voices can use this call to update internal state such as oscillator
phase, to simulate the effect we’d get if we had processed num_samples
of audio.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.