pub struct FunDspGenerator { /* private fields */ }Available on crate feature
fundsp only.Expand description
A polyphonic generator using FunDSP audio units created from a factory function.
The factory function receives shared variables for gate, frequency, volume, panning
and optional user defined shared parameters to control playback, and returns a FunDSP audio
unit that uses these as variables.
§Example
use phonic::{GeneratorPlaybackOptions, generators::FunDspGenerator};
use phonic::fundsp::prelude32::*;
// Simple fundsp generator without additional parameters
let generator = FunDspGenerator::new(
"example_synth",
|gate: Shared, freq: Shared, vol: Shared, pan: Shared| {
// Simple saw wave with envelope and panning
let envelope = var(&gate) >> follow(0.01);
let sound = var(&freq) >> saw();
Box::new((envelope * sound * var(&vol) | var(&pan)) >> panner())
},
GeneratorPlaybackOptions::default(), // default playback options
44100, // voice and source's sample rate
);Implementations§
Source§impl FunDspGenerator
impl FunDspGenerator
Sourcepub fn new<S: AsRef<str>, F>(
synth_name: S,
voice_factory: F,
options: GeneratorPlaybackOptions,
output_sample_rate: u32,
) -> Result<Self, Error>
pub fn new<S: AsRef<str>, F>( synth_name: S, voice_factory: F, options: GeneratorPlaybackOptions, output_sample_rate: u32, ) -> Result<Self, Error>
Create a new FunDSP-based generator with the given voice count.
§Arguments
synth_name- A name for the synth (for playback status tracking and debugging).voice_factory- Function that creates a voice unit with given (frequency, volume, gate, panning) shared variables.options- Generic generator playback options.sample_rate- Output sample rate.
Sourcepub fn with_parameters<S: AsRef<str>, F>(
synth_name: S,
parameters: &[&dyn Parameter],
parameter_state: Option<&[(FourCC, ParameterValueUpdate)]>,
modulation_config: ModulationConfig,
voice_factory: F,
options: GeneratorPlaybackOptions,
output_sample_rate: u32,
) -> Result<Self, Error>
pub fn with_parameters<S: AsRef<str>, F>( synth_name: S, parameters: &[&dyn Parameter], parameter_state: Option<&[(FourCC, ParameterValueUpdate)]>, modulation_config: ModulationConfig, voice_factory: F, options: GeneratorPlaybackOptions, output_sample_rate: u32, ) -> Result<Self, Error>
Create a new FunDSP-based generator with shared parameters and optional modulation.
§Arguments
synth_name- A name for the synth (for playback status tracking and debugging).parameters- A slice of parameters which will be passed to the factory.parameter_state- Optional parameter values that should be applied initially.modulation_config- Configuration for modulation sources and targets.voice_factory- Function that creates a voice unit with given shared variables, parameter accessor, and modulation buffer accessor.options- Generic generator playback options.sample_rate- Output sample rate.
Trait Implementations§
Source§impl Generator for FunDspGenerator
impl Generator for FunDspGenerator
Source§fn generator_name(&self) -> String
fn generator_name(&self) -> String
Name of the generator for display debugging purposes.
Source§fn playback_id(&self) -> PlaybackId
fn playback_id(&self) -> PlaybackId
A unique ID, which can be used to identify sources in
PlaybackStatusEvents.Source§fn playback_options(&self) -> &GeneratorPlaybackOptions
fn playback_options(&self) -> &GeneratorPlaybackOptions
The generator’s playback options
Source§fn playback_message_queue(&self) -> Arc<ArrayQueue<GeneratorPlaybackMessage>> ⓘ
fn playback_message_queue(&self) -> Arc<ArrayQueue<GeneratorPlaybackMessage>> ⓘ
Get the playback message queue for this generator.
Source§fn playback_status_sender(&self) -> Option<SyncSender<PlaybackStatusEvent>>
fn playback_status_sender(&self) -> Option<SyncSender<PlaybackStatusEvent>>
Channel to receive playback status from the generator.
Source§fn set_playback_status_sender(
&mut self,
sender: Option<SyncSender<PlaybackStatusEvent>>,
)
fn set_playback_status_sender( &mut self, sender: Option<SyncSender<PlaybackStatusEvent>>, )
Set the playback status sender for this generator.
Source§fn is_transient(&self) -> bool
fn is_transient(&self) -> bool
Returns true when this generator gets removed after it received a
Stop event.
Source§fn set_is_transient(&mut self, is_transient: bool)
fn set_is_transient(&mut self, is_transient: bool)
Maintained by the player: mark generator as transient or fixed (not transient).
Source§fn parameters(&self) -> Vec<&dyn Parameter>
fn parameters(&self) -> Vec<&dyn Parameter>
Optional parameter descriptors for the generator. Read more
Source§fn process_parameter_update(
&mut self,
id: FourCC,
value: &ParameterValueUpdate,
) -> Result<(), Error>
fn process_parameter_update( &mut self, id: FourCC, value: &ParameterValueUpdate, ) -> Result<(), Error>
Process a parameter update for this generator in the audio thread.
Source§fn modulation_sources(&self) -> Vec<ModulationSource>
fn modulation_sources(&self) -> Vec<ModulationSource>
Optional modulation sources for this generator. By default none. Read more
Source§fn modulation_targets(&self) -> Vec<ModulationTarget>
fn modulation_targets(&self) -> Vec<ModulationTarget>
Returns parameters that can receive modulation. By default none. Read more
Source§fn set_modulation(
&mut self,
source: FourCC,
target: FourCC,
amount: f32,
bipolar: bool,
) -> Result<(), Error>
fn set_modulation( &mut self, source: FourCC, target: FourCC, amount: f32, bipolar: bool, ) -> Result<(), Error>
Set or update a modulation routing. Read more
Source§fn clear_modulation(
&mut self,
source: FourCC,
target: FourCC,
) -> Result<(), Error>
fn clear_modulation( &mut self, source: FourCC, target: FourCC, ) -> Result<(), Error>
Remove a modulation routing.
Source§fn into_box(self) -> Box<dyn Generator>where
Self: Sized,
fn into_box(self) -> Box<dyn Generator>where
Self: Sized,
Convert the Generator impl into a boxed
dyn Generator. Read moreSource§fn process_parameter_updates(
&mut self,
values: &[(FourCC, ParameterValueUpdate)],
) -> Result<(), Error>
fn process_parameter_updates( &mut self, values: &[(FourCC, ParameterValueUpdate)], ) -> Result<(), Error>
Process multiple parameter updates in a batch in the audio thread. Read more
Source§fn process_message(
&mut self,
_message: &GeneratorMessagePayload,
) -> Result<(), Error>
fn process_message( &mut self, _message: &GeneratorMessagePayload, ) -> Result<(), Error>
Handles optional generator-specific messages in the real-time thread. This can be used to
pass payloads to the generator, which can or should not be expressed as a parameter change. Read more
Source§impl Source for FunDspGenerator
impl Source for FunDspGenerator
Source§fn sample_rate(&self) -> u32
fn sample_rate(&self) -> u32
The source’s output sample rate.
Source§fn channel_count(&self) -> usize
fn channel_count(&self) -> usize
The source’s output channel count.
Source§fn is_exhausted(&self) -> bool
fn is_exhausted(&self) -> bool
Returns whether the source finished playback. Exhausted sources should only return 0
on
write and may be removed from a source render graph.Source§fn weight(&self) -> usize
fn weight(&self) -> usize
Return a rough estimate of the processing costs for this source in range
~1..10,
where 1 means pretty lightweight and 10 very CPU intensive. This is used in parallel
processing to distribute work loads evenly before or without actual CPU measurements.Source§fn write(&mut self, output: &mut [f32], time: &SourceTime) -> usize
fn write(&mut self, output: &mut [f32], time: &SourceTime) -> usize
Write at most
output.len() samples into the interleaved output
The given SourceTime parameter specifies which absolute time this buffer in the
final output stream refers to. It can be used to schedule and apply real-time events.
Returns the number of written samples (not frames).Auto Trait Implementations§
impl !RefUnwindSafe for FunDspGenerator
impl !UnwindSafe for FunDspGenerator
impl Freeze for FunDspGenerator
impl Send for FunDspGenerator
impl Sync for FunDspGenerator
impl Unpin for FunDspGenerator
impl UnsafeUnpin for FunDspGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more