Module oxcable::graph [] [src]

A container for audio devices in an acyclic graph.

A graph can be used when many audio devices need to connect in complex topologies. It can connect each output channel of a device to any input channel, provided that connection does not create a cycle.

A graph is initialized by adding each device as a node in the graph, and then specifying the edges between devices. The graph will automatically process the devices in order of their dependencies.

Example

The following example creates a graph with two different branches into a stereo output. It feeds the micropgone to the left channel, and a low-passed oscillator into the right channel.

use oxcable::filters::first_order::{Filter, LowPass};
use oxcable::graph::{DeviceGraph, Tick};
use oxcable::io::audio::AudioEngine;
use oxcable::oscillator::*;

let engine = AudioEngine::with_buffer_size(256).unwrap();
let mut graph = DeviceGraph::new();

// Add nodes to graph
let microphone = graph.add_node(engine.default_input(1).unwrap());
let oscillator = graph.add_node(Oscillator::new(Sine).freq(440.0));
let filter = graph.add_node(Filter::new(LowPass(8000f32), 1));
let speaker = graph.add_node(engine.default_output(2).unwrap());

// Connect devices together
graph.add_edge(microphone, 0, speaker, 0);
graph.add_edge(oscillator, 0, filter, 0);
graph.add_edge(filter, 0, speaker, 1);

// Play audio ad nauseam.
graph.tick_forever();

Reexports

pub use tick::Tick;

Structs

AudioNodeIdx

An identifier used to refer back to a node in the graph.

DeviceGraph

An acyclic graph for audio devices.