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: NodeIdImplementations§
Source§impl AudioGraph
impl AudioGraph
pub fn new(channel_count: u8) -> Self
Sourcepub(crate) fn add_node(&mut self, node: Box<dyn AudioNodeEngine>) -> NodeId
pub(crate) fn add_node(&mut self, node: Box<dyn AudioNodeEngine>) -> NodeId
Create a node, obtain its id
Sourcepub fn add_edge(&mut self, out: PortId<OutputPort>, inp: PortId<InputPort>)
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
Sourcepub fn disconnect_all_from(&mut self, node: NodeId)
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
Sourcepub fn disconnect_output(&mut self, out: PortId<OutputPort>)
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
Sourcepub fn disconnect_between(&mut self, from: NodeId, to: NodeId)
pub fn disconnect_between(&mut self, from: NodeId, to: NodeId)
Disconnect connections from a node to another node
https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-destinationnode
Sourcepub fn disconnect_output_between(&mut self, out: PortId<OutputPort>, to: NodeId)
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
Sourcepub fn disconnect_to(&mut self, node: NodeId, inp: PortId<InputPort>)
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
Sourcepub fn disconnect_output_between_to(
&mut self,
out: PortId<OutputPort>,
inp: PortId<InputPort>,
)
pub fn disconnect_output_between_to( &mut self, out: PortId<OutputPort>, inp: PortId<InputPort>, )
Disconnect all outgoing connections from a node’s output to another node’s input
https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-destinationnode-output-input https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-destinationparam-output
Sourcepub fn dest_id(&self) -> NodeId
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
Sourcepub fn add_extra_dest(&mut self, dest: NodeId)
pub fn add_extra_dest(&mut self, dest: NodeId)
Add additional terminator nodes
Sourcepub fn listener_id(&self) -> NodeId
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.
Sourcepub fn process(&mut self, info: &BlockInfo) -> Chunk
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
Sourcepub(crate) fn node_mut(
&self,
ix: NodeId,
) -> RefMut<'_, Box<dyn AudioNodeEngine>>
pub(crate) fn node_mut( &self, ix: NodeId, ) -> RefMut<'_, Box<dyn AudioNodeEngine>>
Obtain a mutable reference to a node
Sourcefn detect_nodes_in_cycles(&self) -> FxHashSet<NodeIndex<DefaultIx>>
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
- 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.
Sourcefn fill_node_cache_with_silence(
&self,
node_index: NodeIndex<DefaultIx>,
output_count: u32,
)
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§
impl Freeze for AudioGraph
impl !RefUnwindSafe for AudioGraph
impl Send for AudioGraph
impl !Sync for AudioGraph
impl Unpin for AudioGraph
impl UnsafeUnpin for AudioGraph
impl !UnwindSafe for AudioGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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