Skip to main content

GainNode

Struct GainNode 

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

A node that adjusts the volume (gain) of the input signal.

Supports dynamic gain updates via ControlMessage::SetParameter.

§Example

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

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

let mut gain_id = None;
let dest_id = ctx.build_graph(|builder| {
    let gain = builder.add_node(NodeType::Gain(GainNode::new(0.5)));
    gain_id = Some(gain);
    gain
});

// Dynamically change the gain to 1.0 (full volume)
ctx.control_sender().send(
    rust_audio_api::graph::ControlMessage::SetParameter(
        gain_id.unwrap(),
        NodeParameter::Gain(1.0)
    )
).unwrap();

Implementations§

Source§

impl GainNode

Source

pub fn new(gain: f32) -> Self

Creates a new GainNode with the specified gain factor.

§Parameters
  • gain: The multiplier for the audio signal (e.g., 1.0 for unity gain, 0.5 for half volume).
Source

pub fn set_gain(&mut self, gain: f32)

Sets the gain factor for this node.

Source

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

GainNode is a passive node; it requires input to function. It doesn’t manage a ringbuf; it simply applies gain to each incoming frame.

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