Struct rsynth::synth::Synth [−][src]
pub struct Synth<T> where
T: Renderable, { pub voices: Vec<Voice<T>>, pub steal_mode: StealMode, pub pan_raw: (f32, f32), pub sample_counter: f64, // some fields omitted }
The base structure for handling voices, sounds, and processing
T
- a struct we create that implements theRenderable
trait, and contains all of our DSP code.
Fields
voices: Vec<Voice<T>>
A vector containing multiple objects implementing the Voice
trait
steal_mode: StealMode
What method the synth should use to steal voices (if any)
pan_raw: (f32, f32)
The raw amp values for panning
This can be used in tandem with a state object to set the global
panning values every block render, without having to perform
an expensive panning formula every time. For instance, we can
calculate constant_power_pan
in a callback every time the pan knob is moved
and assign that value to a tuple.
Then, before calling the render_next
method on our synth, we can set the
pan_raw
field to our aforementioned tuple.
Note that although the framework supports any number of outputs,
panning is currently only supported with stereo.
sample_counter: f64
The number of samples passed since the plugin started. Can represent 24372 centuries of samples at 48kHz, so wrapping shouldn't be a problem.
Methods
impl<T> Synth<T> where
T: Renderable,
[src]
impl<T> Synth<T> where
T: Renderable,
pub fn new() -> Self
[src]
pub fn new() -> Self
Constructor for the Synthesizer utilizing a builder pattern
pub fn voices(self, voices: Vec<Voice<T>>) -> Self
[src]
pub fn voices(self, voices: Vec<Voice<T>>) -> Self
Set voices using the builder
voices
- A vector containing any number ofVoice
structures. If our instrument is polyphonic, the number of voices will determine the maximum amount of notes it can play at once.
pub fn sample_rate(self, sample_rate: f64) -> Self
[src]
pub fn sample_rate(self, sample_rate: f64) -> Self
Set the sample rate using the builder. This is also useful after the Synth
is finalized
if the host sample rate is changed, or a voice is added during execution with default
filling
in the sample rate.
sample_rate
- set the sample rate of our instrument
pub fn steal_mode(self, steal_mode: StealMode) -> Self
[src]
pub fn steal_mode(self, steal_mode: StealMode) -> Self
Set the note steal mode using the builder
steal_mode
- this determines how "voice stealing" will be implemented, if at all.
pub fn finalize(self) -> Self
[src]
pub fn finalize(self) -> Self
Finalize the builder and return an immutable Synth
pub fn set_pan(&mut self, amount: f32)
[src]
pub fn set_pan(&mut self, amount: f32)
Set the panning for the entire instrument
This is done via a function instead of directly setting the field
as the formula is potentially costly and should only be calculated
when needed. For instance, do not use this function in a loop for
every sample. Instead, update the value only when parameters change.
If you need to set the panning every block render, consider accessing
the pan_raw
field directly.
amount
- a float value between -1 and 1 where 0 is center and 1 is to the right. Values not within this range will be
pub fn render_next<'a, F: Float + AsPrim>(
&mut self,
buffer: &mut AudioBuffer<'a, F>
)
[src]
pub fn render_next<'a, F: Float + AsPrim>(
&mut self,
buffer: &mut AudioBuffer<'a, F>
)
Modify an audio buffer with rendered audio from the voice
buffer
- the audio buffer to modify
pub fn process_events(&mut self, events: &Events)
[src]
pub fn process_events(&mut self, events: &Events)
Process events from the plugin host. This is useful if you are responding to MIDI notes and data.
events
- a reference to anEvents
structure from thevst::api::Events
module.
Trait Implementations
impl<T> Default for Synth<T> where
T: Renderable,
[src]
impl<T> Default for Synth<T> where
T: Renderable,
Get default values
This is only really useful with our internal builder methods.
If we try something like let s = { sample_rate: 48_000, .. Synthesizer::default() };
the compiler will complain that some fields are private.