Skip to main content

MixerNode

Struct MixerNode 

Source
pub struct MixerNode {
    pub clipping: bool,
    /* private fields */
}
Expand description

A node that combines multiple audio signals into a single output.

It applies a gain factor to the mixed signal and performs hard clipping to ensure the output remains within the [-1.0, 1.0] range.

Supports dynamic gain updates via ControlMessage::SetParameter.

§Example

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

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

let mut mixer_id = None;
let dest_id = ctx.build_graph(|builder| {
    let mixer = builder.add_node(NodeType::Mixer(MixerNode::with_gain(1.0)));
    mixer_id = Some(mixer);
    mixer
});

// Dynamically reduce the master mix volume
ctx.control_sender().send(
    rust_audio_api::graph::ControlMessage::SetParameter(
        mixer_id.unwrap(),
        NodeParameter::Gain(0.5)
    )
).unwrap();

Fields§

§clipping: bool

Implementations§

Source§

impl MixerNode

Source

pub fn new() -> Self

Creates a new MixerNode with unity gain (1.0) and clipping enabled.

Source

pub fn with_gain(gain: f32) -> Self

Creates a new MixerNode with the specified gain factor and clipping enabled by default.

Source

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

Sets the gain factor for the mixed output.

Source

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

MixerNode is a passive node that receives the aggregated input (the mixed result) from the graph, then applies Gain and optionally performing Clipping/Limiting to ensure the final output doesn’t distort.

Trait Implementations§

Source§

impl Default for MixerNode

Source§

fn default() -> Self

Returns the “default value” for a type. 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<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>,