Struct Processor

Source
pub struct Processor<G>
where G: Visitable,
{ /* private fields */ }
Expand description

State related to the processing of an audio graph of type G.

The Processor allows for the re-use of resources related to traversal and requesting audio from the graph. This makes it easier to avoid dynamic allocation within a high-priority audio context.

§Example

use dasp_graph::{Node, NodeData};
use petgraph;

// Chose a type of graph for audio processing.
type Graph = petgraph::graph::DiGraph<NodeData<MyNode>, (), u32>;
// Create a short-hand for our processor type.
type Processor = dasp_graph::Processor<Graph>;

fn main() {
    // Create a graph and a processor with some suitable capacity to avoid dynamic allocation.
    let max_nodes = 1024;
    let max_edges = 1024;
    let mut g = Graph::with_capacity(max_nodes, max_edges);
    let mut p = Processor::with_capacity(max_nodes);

    // Add some nodes and edges...

    // Process all nodes within the graph that output to the node at `n_id`.
    p.process(&mut g, n_id);
}

Implementations§

Source§

impl<G> Processor<G>
where G: Visitable,

Source

pub fn with_capacity(max_nodes: usize) -> Self
where G::Map: Default,

Construct a new graph processor from the given maximum anticipated node count.

As long as this node count is not exceeded, the Processor should never require dynamic allocation following construction.

Source

pub fn process<T>(&mut self, graph: &mut G, node: G::NodeId)
where G: Data<NodeWeight = NodeData<T>> + DataMapMut, for<'a> &'a G: GraphBase<NodeId = G::NodeId> + IntoNeighborsDirected, T: Node,

Process audio through the subgraph ending at the node with the given ID.

Specifically, this traverses nodes in depth-first-search post order where the edges of the graph are reversed. This is equivalent to the topological order of all nodes that are connected to the inputs of the given node. This ensures that all inputs of each node are visited before the node itself.

The Node::process method is called on each node as they are visited in the traversal.

Upon returning, the buffers of each visited node will contain the audio processed by their respective nodes.

Supports all graphs that implement the necessary petgraph traits and whose nodes are of type NodeData<T> where T implements the Node trait.

Panics if there is no node for the given index.

Auto Trait Implementations§

§

impl<G> Freeze for Processor<G>
where <G as Visitable>::Map: Freeze,

§

impl<G> RefUnwindSafe for Processor<G>

§

impl<G> Send for Processor<G>
where <G as Visitable>::Map: Send, <G as GraphBase>::NodeId: Send,

§

impl<G> !Sync for Processor<G>

§

impl<G> Unpin for Processor<G>
where <G as Visitable>::Map: Unpin, <G as GraphBase>::NodeId: Unpin,

§

impl<G> UnwindSafe for Processor<G>

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