Skip to main content

DelayNode

Struct DelayNode 

Source
pub struct DelayNode { /* private fields */ }
Expand description

A node that delays the input signal by a specified number of audio blocks.

Each audio block (AudioUnit) contains AUDIO_UNIT_SIZE samples.

Supports dynamic delay updates via ControlMessage::SetParameter.

§Example

use rust_audio_api::nodes::{DelayNode, NodeType};
use rust_audio_api::{AudioContext, NodeParameter};

let mut ctx = AudioContext::new().unwrap();
let sample_rate = ctx.sample_rate();

let mut delay_id = None;
let dest_id = ctx.build_graph(|builder| {
    // Max delay 2 seconds, initial delay 0.5 seconds
    let max_units = (sample_rate as usize * 2) / rust_audio_api::types::AUDIO_UNIT_SIZE;
    let initial_units = (sample_rate as f32 * 0.5) as usize / rust_audio_api::types::AUDIO_UNIT_SIZE;
     
    let delay = builder.add_node(NodeType::Delay(DelayNode::new(max_units, initial_units)));
    delay_id = Some(delay);
    delay
});

// Dynamically change the delay to 1.0 seconds
let new_units = (sample_rate as f32 * 1.0) as usize / rust_audio_api::types::AUDIO_UNIT_SIZE;
ctx.control_sender().send(
    rust_audio_api::graph::ControlMessage::SetParameter(
        delay_id.unwrap(),
        NodeParameter::DelayUnits(new_units)
    )
).unwrap();

Implementations§

Source§

impl DelayNode

Source

pub fn new(max_delay_units: usize, default_delay_units: usize) -> Self

Creates a new DelayNode.

§Parameters
  • max_delay_units: The maximum delay buffer size in units.
  • default_delay_units: The initial delay in units.
Source

pub fn set_delay_units(&mut self, units: usize)

Dynamically updates the delay time.

If the new delay is larger than the current one, silent blocks are inserted. If it is smaller, old blocks are discarded.

Source

pub fn process(&mut self, input: Option<&AudioUnit>, output: &mut AudioUnit)

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<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, 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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,