Skip to main content

Crate audiograph

Crate audiograph 

Source
Expand description

Audiograph - a realtime audio processing graph library for Rust.

Audiograph provides abstractions for audio processors, audio buffers and channel routing, and enables the construction and management of directed signal processing graphs.

§Building blocks

DspGraph represents the main graph structure. It contains audio processing nodes and typed edges that describe the signal flow between nodes. The major building blocks for constructing and using a DspGraph are:

  • Processor: Trait representing an audio processing unit. Processors are the core of a graph node. Conceptually, a graph node consists of a processor and its associated output buffer.
  • AudioBuffer: Trait representing a buffer of audio samples organized by channels. Multiple implementations are provided, including MultiChannelBuffer (owning) and MultiChannelBufferView (non-owning).
  • ChannelSelection: Struct describing the active channels of a connection between nodes. Graph edges can carry an optional channel selection to indicate which channels of a node’s output buffer are processed by connected successor nodes.
  • ProcessingContext: Struct providing context for audio processing, including input and output buffer references, the channel selection, and the number of frames to process.

§Graph structure

A DspGraph is a directed graph where nodes represent audio processors and edges represent the signal flow between processors. It is possible for a node to have multiple incoming edges, in which case the inputs are summed before being passed to the processor. Similarly, a node can have multiple outgoing edges, allowing its output to be routed to multiple successor nodes.

Edges of the graph are typed edges carrying additional information about the connection between nodes, allowing complex routing scenarios such as channel selection and remapping.

A graph can be designed and modified using the provided API, most notably using the following construction methods:

  • DspGraph::add_processor: Adds a new processor node to the graph along with its associated output buffer.
  • DspGraph::connect: Connects two nodes in the graph with an edge, optionally specifying a channel selection.

Additional methods are provided for more advanced operations, such as enabling and disabling edges and removing connections.

For channel rewiring support, see RewireDspGraph, which extends the base graph with the ability to remap channels on existing connections.

Graph nodes and edges are identified using the NodeIndex and EdgeIndex types from the petgraph crate, which provides the underlying directed graph implementation.

Input and output nodes: These are special nodes that serve as the entry and exit points of the graph. Input and output nodes do not process any audio data and do not have dedicated buffers within the graph structure. The corresponding buffers are passed to the DspGraph::process method instead. See also GraphNode and DspGraph::connect.

§Realtime safety

Realtime safety is guaranteed for all BasicDspGraph operations, including processing and modifying the graph structure. RewireDspGraph additionally supports channel rewiring, which is not realtime-safe and is documented as such.

Adding a node to the graph requires the node’s audio buffer to be allocated. It is the caller’s responsibility to ensure this allocation is performed safely and not on the high-priority audio thread.

Graph-internal memory allocations are performed upfront during graph initialization. Adding nodes or edges within the specified graph capacity limits does not allocate.

Re-exports§

pub use petgraph::graph::EdgeIndex;
pub use petgraph::graph::NodeIndex;
pub use crate::buffer::*;
pub use crate::channel::*;
pub use crate::processor::*;
pub use crate::sample::*;

Modules§

buffer
channel
processor
sample

Structs§

DspGraph
Directed graph structure for audio processing

Enums§

GraphNode
Identifier for a graph node

Type Aliases§

AudioGraphError
BasicDspGraph
Type alias for a basic graph without rewiring support
RewireDspGraph
Type alias for a graph with rewiring support