Trait Node

Source
pub trait Node {
    // Required method
    fn process(&mut self, inputs: &[Input], output: &mut [Buffer]);
}
Expand description

The Node type used within a dasp graph must implement this trait.

The implementation describes how audio is processed from its inputs to outputs.

  • Audio sources or inputs may simply ignore the inputs field and write their source data directly to the output buffers.
  • Audio processors, effects or sinks may read from their inputs, apply some custom processing and write the result to their output buffers.

Multiple Node implementations are provided and can be enabled or disabled via their associated features.

§Example

The following demonstrates how to implement a simple node that sums each of its inputs onto the output.

use dasp_graph::{Buffer, Input, Node};

// Our new `Node` type.
pub struct Sum;

// Implement the `Node` trait for our new type.
impl Node for Sum {
    fn process(&mut self, inputs: &[Input], output: &mut [Buffer]) {
        // Fill the output with silence.
        for out_buffer in output.iter_mut() {
            out_buffer.silence();
        }
        // Sum the inputs onto the output.
        for (channel, out_buffer) in output.iter_mut().enumerate() {
            for input in inputs {
                let in_buffers = input.buffers();
                if let Some(in_buffer) = in_buffers.get(channel) {
                    dasp_slice::add_in_place(out_buffer, in_buffer);
                }
            }
        }
    }
}

Required Methods§

Source

fn process(&mut self, inputs: &[Input], output: &mut [Buffer])

Process some audio given a list of the node’s inputs and write the result to the output buffers.

inputs represents a list of all nodes with direct edges toward this node. Each Input within the list can providee a reference to the output buffers of their corresponding node.

The inputs may be ignored if the implementation is for a source node. Alternatively, if the Node only supports a specific number of inputs, it is up to the user to decide how they wish to enforce this or provide feedback at the time of graph and edge creation.

This process method is called by the Processor as it traverses the graph during audio rendering.

Implementations on Foreign Types§

Source§

impl Node for fn(&[Input], &mut [Buffer])

Source§

fn process(&mut self, inputs: &[Input], output: &mut [Buffer])

Source§

impl Node for dyn Fn(&[Input], &mut [Buffer])

Source§

fn process(&mut self, inputs: &[Input], output: &mut [Buffer])

Source§

impl Node for dyn FnMut(&[Input], &mut [Buffer])

Source§

fn process(&mut self, inputs: &[Input], output: &mut [Buffer])

Source§

impl<'a, T> Node for &'a mut T
where T: Node,

Source§

fn process(&mut self, inputs: &[Input], output: &mut [Buffer])

Source§

impl<F> Node for dyn Signal<Frame = F>
where F: Frame<Sample = f32>,

Source§

fn process(&mut self, _inputs: &[Input], output: &mut [Buffer])

Source§

impl<T> Node for Box<T>
where T: Node,

Source§

fn process(&mut self, inputs: &[Input], output: &mut [Buffer])

Implementors§

Source§

impl Node for BoxedNode

Source§

impl Node for BoxedNodeSend

Source§

impl Node for Pass

Source§

impl Node for Sum

Source§

impl Node for SumBuffers

Source§

impl<G, T> Node for GraphNode<G, T>
where G: Data<NodeWeight = NodeData<T>> + DataMapMut + Visitable, for<'a> &'a G: GraphBase<NodeId = G::NodeId> + IntoNeighborsDirected, T: Node,

Source§

impl<S> Node for Delay<S>
where S: SliceMut<Element = f32>,