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
inputsfield and write their source data directly to theoutputbuffers. - Audio processors, effects or sinks may read from their
inputs, apply some custom processing and write the result to theiroutputbuffers.
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§
Sourcefn process(&mut self, inputs: &[Input], output: &mut [Buffer])
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.