### Lowpass Filter Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/filters.md Demonstrates creating a lowpass filter. The first example uses fixed frequency and Q, while the second shows how to use separate inputs for frequency and Q. ```rust use fundsp::prelude64::*; sine_hz(440.0) >> lowpass_hz(5000.0, 1.0) // 440 Hz sine, 5 kHz cutoff, Q=1 // Parametric with separate inputs (sine_hz(440.0) | dc(5000.0) | dc(1.0)) >> lowpass() ``` -------------------------------- ### Setting Usage Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/types.md Shows how to apply a Setting to control a filter's parameters in real-time. ```rust use fundsp::prelude64::*; let mut filter = lowpass_hz(1000.0, 1.0); filter.set(Setting::center_q(2000.0, 2.0)); ``` -------------------------------- ### 64-bit Precision Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/configuration.md An example demonstrating the use of 64-bit precision for creating an audio filter. Coefficients are based on f64 internal state for higher accuracy. ```rust use fundsp::prelude64::*; let filter = lowpass_hz(5000.0, 1.0); // f64-based coefficients ``` -------------------------------- ### Create Stereo BufferArray Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/types.md Example demonstrating how to create a stereo BufferArray with a fixed channel count using Fundsp. ```rust use fundsp::prelude64::*; let mut buffer = BufferArray::::new(); // Stereo buffer (64 samples per channel) ``` -------------------------------- ### 32-bit Precision Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/configuration.md An example showing the creation of an audio filter using 32-bit precision. This is suitable for real-time applications where performance is prioritized over maximum audio fidelity. ```rust use fundsp::prelude32::*; let filter = lowpass_hz(5000.0, 1.0); // f32-based coefficients ``` -------------------------------- ### Sine Calculation Example in Rust Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/math-functions.md Shows how to calculate the sine of an angle given in radians. ```rust use fundsp::prelude64::*; // Sine with angle in radians sin(std::f32::consts::PI / 4.0) // Returns ~0.707 ``` -------------------------------- ### Stack Function Example Source: https://github.com/samiperttu/fundsp/blob/master/README.md Shows the functional equivalent of the stack operator using the stack() function. ```fundsp stack(A, B) ``` -------------------------------- ### Simple Delay Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/effects-patterns.md Creates a simple delay effect. Use for basic echo or reverb tails. Requires the `fundsp::prelude64::*` import. ```rust use fundsp::prelude64::*; // 500 ms delay sine_hz(440.0) >> delay(0.5) // Stereo delay (left and right channels) (sine_hz(440.0) | sine_hz(880.0)) >> (delay(0.3) | delay(0.5)) ``` -------------------------------- ### Create Dynamic Channel BufferVec Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/types.md Example showing how to create a BufferVec with a dynamic number of channels using Fundsp. ```rust use fundsp::prelude64::*; let mut buffer = BufferVec::new(2); // 2 channels, 64 samples per channel ``` -------------------------------- ### Shelving Filter Examples Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/filters.md Illustrates the use of shelving filters for boosting or cutting frequencies above (high shelf) or below (low shelf) a transition frequency. Examples show bass boost and treble cut. ```rust use fundsp::prelude64::*; // Bass boost: raise everything below 200 Hz by 6 dB audio >> lowshelf_hz(200.0, 1.0, db_amp(6.0)) // Treble cut: reduce everything above 10 kHz by 3 dB audio >> highshelf_hz(10000.0, 1.0, db_amp(-3.0)) ``` -------------------------------- ### Control Parameter with Shared Variable Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/types.md Example demonstrating how to use a Shared variable for real-time parameter updates in Fundsp, including setting and getting values. ```rust use fundsp::prelude64::*; let amp = shared(1.0); amp.set_value(0.5); let current = amp.get(); ``` -------------------------------- ### Meter Usage Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/types.md Demonstrates how to use the Meter enum with the monitor function to track signal levels. ```rust use fundsp::prelude64::*; let rms_tracker = shared(0.0); monitor(&rms_tracker, Meter::Rms(0.1)); ``` -------------------------------- ### Peaking (Bell) Filter Examples Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/filters.md Provides examples for the peaking (bell) filter, showing how to boost or cut frequencies around a center frequency. The `bell` filter includes gain control, while `peak` is unity gain. ```rust use fundsp::prelude64::*; // Parametric EQ: boost 1 kHz by 6 dB audio >> bell_hz(1000.0, 1.0, db_amp(6.0)) // Cut 5 kHz by 3 dB audio >> bell_hz(5000.0, 1.0, db_amp(-3.0)) ``` -------------------------------- ### Pipe Function Example Source: https://github.com/samiperttu/fundsp/blob/master/README.md Shows the functional equivalent of the pipe operator using the pipe() function. ```fundsp pipe(A, B) ``` -------------------------------- ### Rust Pipe Operator Examples Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/graph-operators.md Demonstrates chaining audio processing nodes using the pipe operator (>>). Ensure necessary imports like `fundsp::prelude64::*` are included. ```rust use fundsp::prelude64::*; // Basic filter chain: sine → lowpass → highpass sine_hz(440.0) >> lowpass_hz(5000.0, 1.0) >> highpass_hz(100.0, 1.0) ``` ```rust // Nested chains (sine_hz(440.0) | sine_hz(880.0)) >> (lowpass_hz(5000.0, 1.0) | lowpass_hz(5000.0, 1.0)) ``` ```rust // Delay → feedback delay(1.0) >> mul(0.5) ``` -------------------------------- ### Frequency Sweep Example in Rust Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/math-functions.md Illustrates generating an exponential frequency sweep using exp and xerp. ```rust use fundsp::prelude64::*; // Frequency sweep (exponential) let min_freq = 100.0; let max_freq = 10000.0; let sweep = lfo(|t| xerp(min_freq, max_freq, t.min(1.0))); ``` -------------------------------- ### An Audio Node Wrapper Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/types.md Shows how to use the An type alias to wrap an AudioNode, such as a sine wave oscillator. ```rust use fundsp::prelude64::*; let osc: An<_> = sine_hz(440.0); // An> ``` -------------------------------- ### Branch Function Example Source: https://github.com/samiperttu/fundsp/blob/master/README.md Shows the functional equivalent of the branch operator using the branch() function. ```fundsp branch(A, B) ``` -------------------------------- ### Parametric Filter Setup Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/INDEX.md Configures a parametric lowpass filter with a specific frequency and Q value. Input signals are prepared using `dc()` nodes before being piped to the filter. ```rust use fundsp::prelude64::*; (sine_hz(440.0) | dc(5000.0) | dc(1.0)) >> lowpass() ``` -------------------------------- ### Example Usage of Moog Filter Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/filters.md Demonstrates applying a Moog filter to a sawtooth wave. Ensure fundsp::prelude64 is imported. ```rust use fundsp::prelude64::* saw_hz(440.0) >> moog_hz(1000.0, 3.0) // Resonant saw ``` -------------------------------- ### Bus Function Example Source: https://github.com/samiperttu/fundsp/blob/master/README.md Shows the functional equivalent of the bus operator using the bus() function. ```fundsp bus(A, B) ``` -------------------------------- ### Listen to a Lowpass Filter Node Source: https://github.com/samiperttu/fundsp/blob/master/README.md Example of setting up a listener for a `lowpass_hz` node. This allows for dynamic control over filter parameters. ```rust use fundsp::prelude64::*; let (sender, node) = listen(lowpass_hz(1000.0, 1.0)); ``` -------------------------------- ### Exponential Decay Envelope Example in Rust Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/math-functions.md Demonstrates creating an exponential decay envelope using the exp function. ```rust use fundsp::prelude64::*; // Exponential decay envelope envelope(|t| exp(-t)) // Decays from 1.0 to 0 ``` -------------------------------- ### Tanh Saturation Example in Rust Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/math-functions.md Demonstrates using the tanh function for soft clipping audio signals. ```rust use fundsp::prelude64::*; // Tanh saturation for soft clipping shape(|x| tanh(x)) ``` -------------------------------- ### Stack Operator Examples Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/graph-operators.md Demonstrates layering nodes in parallel using the stack operator '|'. Inputs and outputs are concatenated. ```rust use fundsp::prelude64::*; // Stereo noise: two independent noise generators noise() | noise() // Triple sine oscillator (3 outputs) sine_hz(220.0) | sine_hz(440.0) | sine_hz(880.0) // Stereo filter: separate filters for left and right (lowpass_hz(5000.0, 1.0) | lowpass_hz(5000.0, 1.0)) // Mix generators with control parameter sine_hz(440.0) | dc(1.0) // sine + frequency parameter ``` -------------------------------- ### Example Usage of Dirty Biquad Lowpass Filter Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/filters.md Demonstrates how to apply a Dirty Biquad lowpass filter with specified frequency and Q factor. Ensure fundsp::prelude64 is imported. ```rust use fundsp::prelude64::* audio >> dlowpass_hz(Shape::Tanh(1.0), 5000.0, 1.0) ``` -------------------------------- ### playwave / playwave_at Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/effects-patterns.md Loads and plays audio files. `playwave()` plays from the beginning of the specified channel, while `playwave_at()` allows specifying a starting position. ```APIDOC ## playwave / playwave_at ### Description Loads and plays audio files. `playwave()` plays from the beginning of the specified channel, while `playwave_at()` allows specifying a starting position. ### Signatures ```rust pub fn playwave(wave: &Wave, channel: usize) -> An> pub fn playwave_at(wave: &Wave, channel: usize, position: T) -> An> ``` ### Parameters * **wave** (&Wave) - A reference to the loaded Wave data. * **channel** (usize) - The channel number to play from the Wave file. * **position** (T) - Optional: The starting playback position in seconds for `playwave_at()`. ### Example ```rust use fundsp::prelude64::* let sample = Wave::load("kick.wav").expect("Could not load"); playwave(&sample, 0) // Play channel 0 ``` ``` -------------------------------- ### Branch Operator Example Source: https://github.com/samiperttu/fundsp/blob/master/README.md Illustrates the branch operator (^) for splitting a signal into parallel branches. Both components receive the same input, and their outputs are disjoint. ```fundsp A ^ B ``` -------------------------------- ### Frame Type Alias Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/types.md Demonstrates the usage of the Frame type alias for creating stereo audio sample pairs. ```rust use fundsp::prelude64::*; let frame: Frame = Frame::from([0.5, -0.3]); // Stereo sample pair ``` -------------------------------- ### Branch Operator Examples Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/graph-operators.md Illustrates splitting an input signal into parallel processing branches using the branch operator '^'. Outputs are concatenated. ```rust use fundsp::prelude64::*; // Parallel lowpass and highpass (crossover split) lowpass_hz(1000.0, 1.0) ^ highpass_hz(1000.0, 1.0) // Multi-band filter bank (3 bands) bandpass_hz(100.0, 1.0) ^ bandpass_hz(1000.0, 1.0) ^ bandpass_hz(10000.0, 1.0) // Mono input to two parallel filters pass() >> (lowpass_hz(5000.0, 1.0) ^ highpass_hz(1000.0, 1.0)) ``` -------------------------------- ### Complex Operator Precedence Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/graph-operators.md Illustrates the order of operations in Fundsp, showing how a complex expression is parsed based on operator precedence rules. ```rust use fundsp::prelude64::*; // Parsed as: ((a * b) >> (c + d)) & (e | f) a * b >> c + d & e | f ``` -------------------------------- ### Bandpass Filter Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/filters.md Illustrates the use of a bandpass filter to isolate frequencies around a center frequency. The bandwidth is determined by the Q factor. ```rust use fundsp::prelude64::*; white() >> bandpass_hz(1000.0, 10.0) // Narrow band around 1 kHz ``` -------------------------------- ### Notch Filter Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/filters.md Demonstrates how to use a notch filter to remove specific frequencies, such as hum or feedback. The filter creates a null at the specified center frequency. ```rust use fundsp::prelude64::*; audio >> notch_hz(60.0, 10.0) // Remove 60 Hz hum ``` -------------------------------- ### Pipe Operator Example Source: https://github.com/samiperttu/fundsp/blob/master/README.md Demonstrates the pipe operator (>>) for serial processing, equivalent to function composition. The output arity of the first component must match the input arity of the second. ```fundsp A >> B ``` -------------------------------- ### Smooth Parameter Changes with Follow Filter Source: https://github.com/samiperttu/fundsp/blob/master/README.md Pipe a shared variable through a `follow` filter to smooth parameter changes. This example uses a 0.1 second response time. ```rust let amp_controlled = noise() * (var(&) >> follow(0.1)); ``` -------------------------------- ### Multitap Delay Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/effects-patterns.md Creates a multitap delay effect with multiple, independently timed echoes. Useful for complex rhythmic delays. Requires `fundsp::prelude64::*`. ```rust use fundsp::prelude64::*; // Two-tap delay (sine_hz(440.0) | dc(0.3) | dc(0.6)) >> multitap() // Left: 300ms, Right: 600ms ``` -------------------------------- ### Set Initial Phase for Sine Wave Oscillator Source: https://github.com/samiperttu/fundsp/blob/master/README.md Initialize a sine wave oscillator with a specific phase using the `phase` builder method. The oscillator will start at the specified phase value (0.0 to 1.0). ```rust let mut A = sine_hz(220.0).phase(0.0) ``` -------------------------------- ### Simple Frequency Modulation (FM) Synthesis Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/effects-patterns.md Generates harmonic richness through frequency modulation. This example demonstrates a basic FM setup using sine waves for carrier and modulator. ```rust use fundsp::prelude64::* // Simple FM: sin(t + mod_amount * sin(mod_freq * t)) let carrier = 440.0; let modulator = 100.0; let mod_amount = 100.0; sine_hz(carrier) * mod_amount * sine_hz(modulator) + carrier >> sine() ``` -------------------------------- ### Create a Dynamic Graph Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/README.md Demonstrates building a dynamic audio processing graph using the `Net` structure, adding nodes, and piping signals between them. ```rust use fundsp::prelude64::*; let mut net = Net::new(0, 1); let osc_id = net.push(Box::new(sine_hz(440.0))); let filter_id = net.push(Box::new(lowpass_hz(5000.0, 1.0))); net.pipe(osc_id, filter_id); net.pipe_output(filter_id); ``` -------------------------------- ### Initialize 12-Band Parametric Equalizer Source: https://github.com/samiperttu/fundsp/blob/master/README.md Initializes a 12-band parametric equalizer using peaking bell filters. Bands are spaced at 1 kHz increments starting from 1 kHz, with Q values of 1.0 and gains of 0 dB. ```rust use fundsp::prelude64::*; let mut equalizer = pipei::(|i| bell_hz(1000.0 + 1000.0 * i as f32, 1.0, db_amp(0.0))); ``` -------------------------------- ### Create a Net Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/net-sequencer.md Initializes an empty Net with a specified number of inputs and outputs. Use this to set up the basic structure of your audio graph. ```rust use fundsp::prelude64::* let mut net = Net::new(0, 1); // 0 inputs, 1 output (generator) ``` -------------------------------- ### Parametric EQ Stack Design Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/filters.md Creates a stack of parametric EQ (bell) filters. This example uses a loop to generate multiple bell filters with frequencies spaced logarithmically. ```rust use fundsp::prelude64::*; pipei::(|i| bell_hz(100.0 * 10.0_f32.powi(i as i32), 1.0, db_amp(0.0))) ``` -------------------------------- ### Low Frequency Oscillator (LFO) Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/oscillators-generators.md An LFO is a synonym for the generic envelope function, useful for creating periodic control signals. This example shows an LFO modulating the cutoff frequency of a lowpass filter. ```rust use fundsp::prelude64::*; // LFO modulating filter cutoff sine_hz(440.0) >> lowpass_hz((lfo(|t| xerp(1000.0, 5000.0, 0.5 * (1.0 + sin_hz(0.5, t)))), 1.0)) ``` -------------------------------- ### Import 64-bit Precision Prelude Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/configuration.md Imports the 64-bit precision prelude for high-quality audio processing. This is best for audio mastering, production, and scenarios requiring maximum fidelity, at the cost of approximately double the CPU usage compared to 32-bit. ```rust use fundsp::prelude64::*; // f64 internal state ``` -------------------------------- ### Dynamically Build a Simple Audio Graph with Net Source: https://github.com/samiperttu/fundsp/blob/master/README.md Use Net to instantiate a graph with a specified number of inputs and outputs, add nodes, and connect them. This is useful when the graph structure is not known at compile time. ```rust use fundsp::prelude64::* // Instantiate network with 0 inputs and 1 output. let mut net = Net::new(0, 1); // Add nodes, obtaining their IDs. let dc_id = net.push(Box::new(dc(220.0))); let sine_id = net.push(Box::new(sine())); // Connect nodes. net.pipe_all(dc_id, sine_id); net.pipe_output(sine_id); ``` -------------------------------- ### Absolute Value and Signum Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/math-functions.md Provides functions to get the absolute value and the sign of a number. ```APIDOC ## Absolute Value and Signum ### `abs(x: f32) -> f32` **Description**: Returns the absolute value of `x`. ### `signum(x: f32) -> f32` **Description**: Returns the sign of `x` (-1.0 if negative, 1.0 if positive, 0.0 if zero). ``` -------------------------------- ### Net::new Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/net-sequencer.md Creates a new Net with a specified number of inputs and outputs. This is the entry point for building an audio graph. ```APIDOC ## Net::new ### Description Creates an empty `Net` with the specified number of network inputs and outputs. ### Method `Net::new(inputs: usize, outputs: usize) -> Self` ### Parameters #### Path Parameters - **inputs** (`usize`) - Required - Number of network inputs. - **outputs** (`usize`) - Required - Number of network outputs. ### Response Returns an empty `Net` with the specified connectivity. ``` -------------------------------- ### Oscillator Builder Methods Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/oscillators-generators.md Demonstrates setting the initial phase and pseudorandom seed for an oscillator using builder methods. Call `.build()` to finalize the oscillator configuration. ```rust oscillator .phase(0.0) // Set initial phase (0...1) .seed(42) // Set pseudorandom seed .build() ``` -------------------------------- ### Generate a Sine Wave Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/README.md Demonstrates how to create a sine wave oscillator and retrieve a single audio sample. ```rust use fundsp::prelude64::*; let mut oscillator = sine_hz(440.0); let sample = oscillator.get_mono(); ``` -------------------------------- ### Real-Time Parameter Setting with Listen/Set Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/effects-patterns.md Shows how to change parameters of an audio node (here, a low-pass filter) in real-time from a separate thread using `listen` and `setter`. Requires `fundsp::prelude64`. ```rust use fundsp::prelude64::*; let mut filter = lowpass_hz(1000.0, 1.0); let (setter, listening_node) = listen(filter); // Change parameters from any thread setter.try_send(Setting::center_q(2000.0, 2.0)).ok(); ``` -------------------------------- ### Shape Usage Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/types.md Demonstrates using a Shape variant, Tanh, with a filter to apply saturation. ```rust use fundsp::prelude64::*; let filter = dlowpass_hz(Shape::Tanh(1.0), 5000.0, 1.0); ``` -------------------------------- ### Triangle Wave Approximation using Wrap and Mirror Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/math-functions.md Demonstrates creating a triangle wave approximation by applying mirror and wrap utility functions to a phase ramp. Requires importing prelude64. ```rust use fundsp::prelude64::*; // Triangle wave using wrap and mirror let phase = ramp_hz(440.0); triangle_approx(mirror(phase)) ``` -------------------------------- ### get_mono Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/audionode.md Convenience method to get a single sample from a generator (0 inputs, 1+ outputs). ```APIDOC ## get_mono ### Description Convenience method to get a single sample from a generator (0 inputs, 1+ outputs). ### Method Signature `get_mono(self: &mut Self) -> f32` ### Parameters None ### Returns - `f32` - A single sample from the generator. ``` -------------------------------- ### Create a New Sequencer Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/net-sequencer.md Initializes a new Sequencer with specified input and output channels and a replay mode. Use `ReplayMode::None` for typical event sequencing. ```rust pub fn new(inputs: usize, outputs: usize, mode: ReplayMode) -> Self ``` ```rust use fundsp::prelude64::*; let mut seq = Sequencer::new(0, 2, ReplayMode::None); ``` -------------------------------- ### Apply Settings to a Node Source: https://github.com/samiperttu/fundsp/blob/master/README.md Demonstrates how to directly apply settings to a node using the `set` method. This is useful for parameters without dedicated inputs. ```rust use fundsp::prelude64::*; let mut node = afollow(0.1, 1.0); node.set(Setting::attack_release(0.2, 2.0)); ``` -------------------------------- ### get_stereo Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/audionode.md Convenience method to get a stereo sample pair from a generator (0 inputs, 2+ outputs). ```APIDOC ## get_stereo ### Description Convenience method to get a stereo sample pair from a generator (0 inputs, 2+ outputs). ### Method Signature `get_stereo(self: &mut Self) -> (f32, f32)` ### Parameters None ### Returns - `(f32, f32)` - A stereo sample pair (left, right) from the generator. ``` -------------------------------- ### Import 32-bit Precision Prelude Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/configuration.md Imports the 32-bit precision prelude for performance-critical applications like real-time game audio or mobile platforms. This offers faster processing at a slight reduction in audio quality. ```rust use fundsp::prelude32::*; // f32 internal state ``` -------------------------------- ### Checking Frequency Consonance with Dissonance Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/math-functions.md Example of using the `dissonance` function to determine if two frequencies are relatively consonant. ```rust use fundsp::prelude64::*; // Check if frequencies are consonant if dissonance(440.0, 550.0) < 0.5 { println!("Frequencies are relatively consonant"); } ``` -------------------------------- ### Initialize Manual SIMD Data Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/configuration.md Demonstrates initializing an array of SIMD lanes for manual SIMD operations. Requires 8 SIMD lanes for 64 samples. ```rust use fundsp::prelude64::*; use fundsp::F32x; let simd_data: [F32x; SIMD_LEN] = ...; // 8 SIMD lanes (64 samples) ``` -------------------------------- ### Fundsp Dependency for Desktop (High-Quality) Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/configuration.md Specifies the fundsp dependency for desktop builds, using all default features for high-quality audio processing. Recommends the 64-bit prelude and enabling FFT convolution. ```toml [dependencies] fundsp = { version = "0.23.0" } # Use all defaults ``` -------------------------------- ### Numeric Type Aliases Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/types.md Illustrates the re-export of typenum unsigned integer types for compile-time arity specification. ```rust use fundsp::prelude64::*; // Used by: Generic parameters in node definitions (e.g., Stack) ``` -------------------------------- ### Import Generic Prelude Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/configuration.md Imports the generic prelude, which automatically matches the audio processing precision to the usage context. This is the recommended approach for most use cases. ```rust use fundsp::prelude::*; // Type inferred from usage ``` -------------------------------- ### Inverse Interpolation Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/math-functions.md Calculates the interpolation factor 't' given the start, end, and a value within the interpolated range. ```APIDOC ## delerp(x0: f32, x1: f32, x: f32) -> f32 ### Description Calculates the interpolation factor 't' such that `x = lerp(x0, x1, t)`. Returns the position of `x` within the range defined by `x0` and `x1`. ### Parameters - **x0** (f32) - The starting value of the range. - **x1** (f32) - The ending value of the range. - **x** (f32) - The value for which to find the interpolation factor. ## delerp11(x0: f32, x1: f32, x: f32) -> f32 ### Description Calculates the centered interpolation factor 't' such that `x = lerp11(x0, x1, t)`. Assumes x0 and x1 are in [-1, 1]. ### Parameters - **x0** (f32) - The value at t = -1. - **x1** (f32) - The value at t = 1. - **x** (f32) - The value for which to find the interpolation factor. ## dexerp(x0: f32, x1: f32, x: f32) -> f32 ### Description Calculates the exponential interpolation factor 't' such that `x = xerp(x0, x1, t)`. ### Parameters - **x0** (f32) - The starting value of the range. - **x1** (f32) - The ending value of the range. - **x** (f32) - The value for which to find the interpolation factor. ## dexerp11(x0: f32, x1: f32, x: f32) -> f32 ### Description Calculates the centered exponential interpolation factor 't' such that `x = xerp11(x0, x1, t)`. Assumes x0 and x1 are in [-1, 1]. ### Parameters - **x0** (f32) - The value at t = -1. - **x1** (f32) - The value at t = 1. - **x** (f32) - The value for which to find the interpolation factor. ``` -------------------------------- ### Initialize Sequencer with Replay All Mode Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/net-sequencer.md Initializes a sequencer that will replay all its events after a reset. Requires importing the prelude. ```rust use fundsp::prelude64::*; // Sequencer that replays after reset let mut seq = Sequencer::new(0, 1, ReplayMode::All); ``` -------------------------------- ### Configure AudioContext with Sample Rate Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/configuration.md Illustrates setting the sample rate for an entire audio processing context. All nodes added to this context will inherit the specified sample rate. ```rust use fundsp::prelude64::*; struct AudioContext { sample_rate: f64, nodes: Vec>, } impl AudioContext { fn new(sample_rate: f64) -> Self { AudioContext { sample_rate, nodes: Vec::new(), } } fn add_node(&mut self, mut node: Box) { node.set_sample_rate(self.sample_rate); self.nodes.push(node); } } ``` -------------------------------- ### Block Processing with BufferArray and BufferVec Source: https://github.com/samiperttu/fundsp/blob/master/README.md Demonstrates creating and processing audio data using stack-allocated (BufferArray) and heap-allocated (BufferVec) buffers. Shows how to declare nodes, process samples, and apply filters. ```rust use fundsp::prelude64::*; // Create a stereo buffer on the stack. let mut buffer = BufferArray::::new(); // Declare stereo noise. let mut node = noise() | noise(); // Process 50 samples into the buffer. There are no inputs, so we can borrow an empty buffer. node.process(50, &BufferRef::empty(), &mut buffer.buffer_mut()); // Create another stereo buffer, this one on the heap. let mut filtered = BufferVec::new(2); // Declare stereo filter. let mut filter = lowpole_hz(3000.0) | lowpole_hz(3000.0); // Filter the 50 noise samples. filter.process(50, &buffer.buffer_ref(), &mut filtered.buffer_mut()); ``` -------------------------------- ### Get Mono Sample from Generator Source: https://github.com/samiperttu/fundsp/blob/master/README.md Retrieves the next mono sample from a generator node with no inputs and one or two outputs. ```rust let out_sample = node.get_mono(); ``` -------------------------------- ### Create a Stereo Sequencer Source: https://github.com/samiperttu/fundsp/blob/master/README.md Initializes a new stereo sequencer. The `ReplayMode` can be set to `ReplayMode::All` to replay events after a reset. ```rust use fundsp::prelude64::*; // Create stereo sequencer. // The third argument should be set to `ReplayMode::All` if we want to replay events after `reset`. let mut sequencer = Sequencer::new(0, 2, ReplayMode::None); ``` -------------------------------- ### Set Equalizer Sample Rate Source: https://github.com/samiperttu/fundsp/blob/master/README.md Sets the sample rate for the equalizer. The default is 44.1 kHz, but this example changes it to 48 kHz. ```rust equalizer.set_sample_rate(48_000.0); ``` -------------------------------- ### Sequencer::new Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/net-sequencer.md Creates a new Sequencer instance with specified input and output channels and a replay mode. The Sequencer is initialized empty. ```APIDOC ## Sequencer::new ### Description Creates a new Sequencer instance with specified input and output channels and a replay mode. The Sequencer is initialized empty. ### Method `new(inputs: usize, outputs: usize, mode: ReplayMode) -> Self` ### Parameters #### Path Parameters - **inputs** (usize) - Required - Number of inputs - **outputs** (usize) - Required - Number of outputs - **mode** (ReplayMode) - Required - `All` replays after reset, `None` does not ### Returns - Empty `Sequencer` ### Example ```rust use fundsp::prelude64::* let mut seq = Sequencer::new(0, 2, ReplayMode::None); ``` ``` -------------------------------- ### Get Stereo Samples from Generator Source: https://github.com/samiperttu/fundsp/blob/master/README.md Retrieves the next stereo sample pair from a generator node with no inputs and one or two outputs. ```rust let (out_left_sample, out_right_sample) = node.get_stereo(); ``` -------------------------------- ### playwave_at Source: https://github.com/samiperttu/fundsp/blob/master/README.md Plays back a channel of an Arc between specified start and end indices. An optional loop point can be set for looping. ```APIDOC ## playwave_at(&wave, channel, start, end, loop) ### Description Play back a channel of `Arc` between indices `start` (inclusive) and `end` (exclusive), with optional `loop` index to jump to at the end. ### Parameters #### Path Parameters - **wave** (Arc) - Required - The wave data to play. - **channel** (integer) - Required - The channel index to play. - **start** (integer) - Required - The starting index (inclusive). - **end** (integer) - Required - The ending index (exclusive). - **loop** (integer) - Optional - The index to jump to at the end for looping. ``` -------------------------------- ### Parallel Processing with Parameters Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/graph-operators.md Demonstrates parallel processing by splitting a signal path and applying different operations, including using parameters for frequency and control inputs. ```rust use fundsp::prelude64::*; // Sine with frequency parameter: 1 frequency input, 1 audio output (pass() | dc(220.0)) >> sine() // Lowpass with audio and control inputs (pass() | dc(5000.0) | dc(1.0)) >> lowpass() ``` -------------------------------- ### Inverse Interpolation Functions Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/math-functions.md Calculates the interpolation factor 't' given the start, end, and intermediate values for linear and exponential interpolation. ```rust pub fn delerp(x0: f32, x1: f32, x: f32) -> f32 // Returns t where x = lerp(x0, x1, t) pub fn delerp11(x0: f32, x1: f32, x: f32) -> f32 pub fn dexerp(x0: f32, x1: f32, x: f32) -> f32 pub fn dexerp11(x0: f32, x1: f32, x: f32) -> f32 ``` ```rust use fundsp::prelude64::* let t = delerp(100.0, 10000.0, 1000.0); // Returns ~0.3125 ``` -------------------------------- ### Vibrato Effect Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/effects-patterns.md Applies a vibrato effect by modulating the pitch of the audio signal. This example creates a ±100 cent vibrato at 5 Hz. ```rust use fundsp::prelude64::*; // Vibrato on sine: ±100 cents at 5 Hz let freq = 440.0; sine_hz(freq * semitone_ratio(lfo(|t| 2.0 * sin_hz(5.0, t)))) ``` -------------------------------- ### Net Graph Syntax Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/net-sequencer.md Demonstrates how to build and manipulate dynamic graphs using the Net type, including piping nodes and using static graph composition. ```APIDOC ## Graph Syntax with Net ### Description Networks can use the same graph syntax as static nodes. This section shows how to build dynamic graphs using `Net` and its associated methods. ### Method Signature ```rust let mut net = Net::new(1, 1); let input = net.push(Box::new(pass())); let filter = net.push(Box::new(lowpass_hz(5000.0, 1.0))); net.pipe(input, filter); net.pipe_output(filter); // Alternatively, build statically first let graph: An<_> = pass() >> lowpass_hz(5000.0, 1.0); let mut net2 = Net::wrap(Box::new(graph)); ``` ### Parameters None for the general syntax description. ### Request Example See Method Signature for examples of building and piping nodes within a `Net`. ### Response None explicitly defined for the syntax itself, but operations modify the `Net` object. ``` -------------------------------- ### Project File Structure Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/README.md This outlines the directory structure for documentation files within the project, categorizing different aspects of the API and configuration. ```text /workspace/home/output/ ├── README.md # This file ├── INDEX.md # Master navigation and reference ├── types.md # Type definitions ├── configuration.md # Build and configuration options └── api-reference/ ├── audionode.md # Core trait ├── graph-operators.md # Graph composition ├── oscillators-generators.md # Signal sources ├── filters.md # Filtering and EQ ├── net-sequencer.md # Dynamic graphs ├── math-functions.md # Utility functions └── effects-patterns.md # Audio effects ``` -------------------------------- ### Highpass Filter Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/filters.md Shows how to use the highpass filter to remove frequencies below a specified cutoff. This is useful for eliminating low-frequency noise or rumble. ```rust use fundsp::prelude64::*; white() >> highpass_hz(100.0, 1.0) // Remove sub-bass ``` -------------------------------- ### Semitone Ratio Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/math-functions.md Calculates the frequency ratio corresponding to a given number of semitones. This ratio can be multiplied by a base frequency to get the new frequency. ```APIDOC ## Semitone Ratio ### Description Calculates the frequency ratio for a given number of semitones. This ratio can be multiplied by a base frequency to determine the new frequency. ### Function - `semitone_ratio(semitones: f32) -> f32`: Calculates the frequency ratio for a given number of semitones. - `semitones` (f32) - Number of semitones (can be fractional). ### Returns Frequency ratio (multiply with base frequency). ### Example ```rust use fundsp::prelude64::* let base = 440.0; sine_hz(base * semitone_ratio(12.0)) // One octave higher (2.0x) sine_hz(base * semitone_ratio(7.0)) // Perfect fifth higher (~1.498x) ``` ``` -------------------------------- ### Build a Processing Chain Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/README.md Illustrates creating a complex audio processing chain by combining multiple nodes using the `>>` operator. ```rust use fundsp::prelude64::*; let processor = sine_hz(440.0) >> lowpass_hz(5000.0, 1.0) >> (pass() & 0.2 * reverb_stereo(20.0, 2.0, 1.0)); ``` -------------------------------- ### Override Oscillator Phase and Seed Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/oscillators-generators.md Use `phase()` to set the starting phase and `seed()` to provide a specific seed for reproducible randomness in generators. ```rust use fundsp::prelude64::*; sine_hz(440.0).phase(0.0) // Start at zero crossing white().seed(42) // Specific seed for reproducible randomness ``` -------------------------------- ### Bus Operator for Effect Mix Source: https://github.com/samiperttu/fundsp/blob/master/README.md Demonstrates using the bus operator (&) to control effect mix. The example adds 20% chorus to a mono signal. ```fundsp pass() & 0.2 * chorus(0, 0.0, 0.01, 0.3) ``` -------------------------------- ### Interactive Frequency Response Analysis with evcxr Source: https://github.com/samiperttu/fundsp/blob/master/README.md Use evcxr to interactively load fundsp and analyze the frequency response of a bell filter. This snippet demonstrates setting up the environment and printing the display output. ```rust C:\rust>evcxr Welcome to evcxr. For help, type :help >> :dep fundsp >> use fundsp::prelude64::*; >> print!("{}", bell_hz(1000.0, 1.0, db_amp(50.0)).display()) 60 dB ------------------------------------------------ 60 dB 50 dB -------------------------.---------------------- 50 dB * 40 dB -------------------------*---------------------- 40 dB ** 30 dB -----------------------.***--------------------- 30 dB ******. 20 dB -------------------..*********.----------------- 20 dB ..**************. 10 dB -------------..********************..----------- 10 dB ..*****************************... 0 dB ....***************************************..... 0 dB | | | | | | | | | | 10 50 100 200 500 1k 2k 5k 10k 20k Hz Peak Magnitude : 50.00 dB (1000 Hz) Inputs : 1 Outputs : 1 Latency : 0.0 samples Footprint : 96 bytes >> ``` -------------------------------- ### Follow Smoothing Filter Example Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/filters.md Smooths an amplitude envelope with a fast attack and slow release. This is useful for creating gradual changes in audio signals. ```rust use fundsp::prelude64::*; // Smooth amplitude envelope with fast attack, slow release envelope(|t| if t < 1.0 { t } else { 1.0 }) >> afollow(0.01, 0.5) ``` -------------------------------- ### Net::backend Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/net-sequencer.md Returns a real-time safe backend for the Net, allowing audio processing on a separate thread while the frontend handles changes. ```APIDOC ## Net::backend ### Description Returns a real-time safe backend for the `Net`. This allows changes to be made to the audio graph on a frontend thread while audio is rendered on a backend thread without allocations. ### Method `backend(&mut self) -> NetBackend` ### Response Returns a `NetBackend` instance that can be used for real-time audio processing. ``` -------------------------------- ### De-click/De-pop for Note Start Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/effects-patterns.md Applies a fade-in to audio signals to prevent clicks or pops at the beginning of notes. Offers default or custom fade-in times. ```rust pub fn declick() -> An> pub fn declick_s(time: T) -> An> ``` ```rust use fundsp::prelude64::*; // Default 10 ms fade-in sine_hz(440.0) >> declick() // Custom 50 ms fade-in sine_hz(440.0) >> declick_s(0.05) ``` -------------------------------- ### Manage Dynamic Audio Network with Frontend/Backend and Updates Source: https://github.com/samiperttu/fundsp/blob/master/README.md Separate a dynamic network into a frontend for modifications and a real-time safe backend for audio rendering. This allows for safe updates to the audio graph, including node replacement and crossfading. ```rust use fundsp::prelude64::* let mut net = Net::new(0, 1); let noise_id = net.chain(Box::new(pink())); // Create the backend. let mut backend = net.backend(); // The backend is now ready to be sent into an audio thread. // We can make changes to the frontend and then commit them to the backend. net.replace(noise_id, Box::new(brown())); net.commit(); // We can also use the graph syntax to make changes, as long as connectivity // is maintained at commit time. net = net >> peak_hz(1000.0, 1.0); net.commit(); /// Nodes can be replaced smoothly with a crossfade to avoid clicks. net.crossfade(noise_id, Fade::Smooth, 1.0, Box::new(white())); net.commit(); ``` -------------------------------- ### Wavetable Morphing with Filter Sweep Source: https://github.com/samiperttu/fundsp/blob/master/_autodocs/api-reference/effects-patterns.md Smoothly transitions between waveforms using a morphing effect. This example shows a morph filter sweeping from a lowpass to a highpass configuration. ```rust use fundsp::prelude64::* // Morph filter: sweep from lowpass to highpass (pass() | dc(1000.0) | dc(1.0) | lfo(|t| 0.5 + 0.5 * sin_hz(1.0, t))) >> morph() ```