Skip to main content

FunDspGenerator

Struct FunDspGenerator 

Source
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

Source

pub fn new<S: AsRef<str>, F>( synth_name: S, voice_factory: F, options: GeneratorPlaybackOptions, output_sample_rate: u32, ) -> Result<Self, Error>
where F: Fn(Shared, Shared, Shared, Shared) -> Box<dyn AudioUnit>,

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

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>
where F: Fn(Shared, Shared, Shared, Shared, &mut dyn FnMut(FourCC) -> Shared, &mut dyn FnMut(FourCC) -> SharedBuffer) -> Box<dyn AudioUnit>,

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

Source§

fn generator_name(&self) -> String

Name of the generator for display debugging purposes.
Source§

fn playback_id(&self) -> PlaybackId

A unique ID, which can be used to identify sources in PlaybackStatusEvents.
Source§

fn playback_options(&self) -> &GeneratorPlaybackOptions

The generator’s playback options
Source§

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

Channel to receive playback status from the generator.
Source§

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

Returns true when this generator gets removed after it received a Stop event.
Source§

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>

Optional parameter descriptors for the generator. Read more
Source§

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>

Optional modulation sources for this generator. By default none. Read more
Source§

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>

Set or update a modulation routing. Read more
Source§

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,

Convert the Generator impl into a boxed dyn Generator. Read more
Source§

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>

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

Source§

fn sample_rate(&self) -> u32

The source’s output sample rate.
Source§

fn channel_count(&self) -> usize

The source’s output channel count.
Source§

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

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

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

fn into_box(self) -> Box<dyn Source>
where Self: Sized,

Convert the Source impl into a boxed dyn Source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V