conformal_poly

Trait Voice

Source
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§

Source

type SharedData<'a>: Clone

Data that is shared across all voices. This could include things like low frequency oscillators that are used by multiple voices.

Required Methods§

Source

fn new(max_samples_per_process_call: usize, sampling_rate: f32) -> Self

Creates a new voice.

Source

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.

Source

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.

Source

fn quiescent(&self) -> bool

Returns whether this voice is currently outputng audio.

When this returns true, process will not be called for this voice again until a new note is started. This can improve performance by allowing voices to skip processing.

Source

fn reset(&mut self)

Resets the voice to its initial state.

Provided Methods§

Source

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.

Implementors§