Skip to main content

AudioGraph

Struct AudioGraph 

Source
pub struct AudioGraph {
    graph: StableGraph<Node, Edge>,
    dest_id: NodeId,
    dests: Vec<NodeId>,
    listener_id: NodeId,
}

Fields§

§graph: StableGraph<Node, Edge>§dest_id: NodeId§dests: Vec<NodeId>§listener_id: NodeId

Implementations§

Source§

impl AudioGraph

Source

pub fn new(channel_count: u8) -> Self

Source

pub(crate) fn add_node(&mut self, node: Box<dyn AudioNodeEngine>) -> NodeId

Create a node, obtain its id

Source

pub fn add_edge(&mut self, out: PortId<OutputPort>, inp: PortId<InputPort>)

Connect an output port to an input port

The edge goes from the output port to the input port, connecting two nodes

Source

pub fn disconnect_all_from(&mut self, node: NodeId)

Disconnect all outgoing connections from a node

https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect

Source

pub fn disconnect_output(&mut self, out: PortId<OutputPort>)

Disconnect all outgoing connections from a node’s output

https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-output

Source

pub fn disconnect_between(&mut self, from: NodeId, to: NodeId)

Source

pub fn disconnect_output_between(&mut self, out: PortId<OutputPort>, to: NodeId)

Disconnect all outgoing connections from a node’s output to another node

https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-destinationnode-output

Source

pub fn disconnect_to(&mut self, node: NodeId, inp: PortId<InputPort>)

Disconnect all outgoing connections from a node to another node’s input

Only used in WebAudio for disconnecting audio params

https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-destinationparam

Source

pub fn disconnect_output_between_to( &mut self, out: PortId<OutputPort>, inp: PortId<InputPort>, )

Source

pub fn dest_id(&self) -> NodeId

Get the id of the destination node in this graph

All graphs have a destination node, with one input port

Source

pub fn add_extra_dest(&mut self, dest: NodeId)

Add additional terminator nodes

Source

pub fn listener_id(&self) -> NodeId

Get the id of the AudioListener in this graph

All graphs have a single listener, with no ports (but nine AudioParams)

N.B. The listener actually has a single output port containing its position data for the block, however this should not be exposed to the DOM.

Source

pub fn process(&mut self, info: &BlockInfo) -> Chunk

For a given block, process all the data on this graph

This implements steps 4.2 and parts of 4.4 from https://webaudio.github.io/web-audio-api/#rendering-loop

Source

pub(crate) fn node_mut( &self, ix: NodeId, ) -> RefMut<'_, Box<dyn AudioNodeEngine>>

Obtain a mutable reference to a node

Source

fn detect_nodes_in_cycles(&self) -> FxHashSet<NodeIndex<DefaultIx>>

Detect cycles in this graph and return the indices of their nodes.

This covers the cycle-related part of step 4.2. Tarjan’s algorithm finds the cycles, and Self::process mutes the affected nodes as required by step 4.2.7.

The outer render-loop steps, including returning render_result, are outside this method because Self::process returns audio data.

https://webaudio.github.io/web-audio-api/#rendering-loop

  1. Process a render quantum. 2. Order the AudioNodes of the BaseAudioContext to be processed. 4. Let cycle breakers be an empty set of DelayNodes. It will contain all the DelayNodes that are part of a cycle. 5. For each AudioNode node in nodes: 1. If node is a DelayNode that is part of a cycle, add it to cycle breakers and remove it from nodes. 6. For each DelayNode delay in cycle breakers: 1. Let delayWriter and delayReader respectively be a DelayWriter and a DelayReader, for delay. Add delayWriter and delayReader to nodes. Disconnect delay from all its input and outputs. Note: This breaks the cycle: if a DelayNode is in a cycle, its two ends can be considered separately, because delay lines cannot be smaller than one render quantum when in a cycle. 7. If nodes contains cycles, mute all the AudioNodes that are part of this cycle, and remove them from nodes.

TODO: Implement steps 4.2.4–4.2.6 for cyclic DelayNodes by replacing each with a DelayWriter and DelayReader.

Source

fn fill_node_cache_with_silence( &self, node_index: NodeIndex<DefaultIx>, output_count: u32, )

https://webaudio.github.io/web-audio-api/#available-for-reading

Making a buffer available for reading from an AudioNode means putting it in a state where other AudioNodes connected to this AudioNode can safely read from it.

The specification does not require these buffers to be silent. This helper runs after AudioNodeEngine::mute_node, so it fills the caches with silence for downstream nodes.

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<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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T