play_sine/
play_sine.rs

1use auxide::graph::{Graph, NodeType, PortId, Rate};
2use auxide::plan::Plan;
3use auxide::rt::Runtime;
4use auxide_io::stream_controller::StreamController;
5use std::thread;
6use std::time::Duration;
7
8fn main() -> anyhow::Result<()> {
9    // Build a simple sine wave graph
10    let mut graph = Graph::new();
11    let osc = graph.add_node(NodeType::SineOsc { freq: 440.0 });
12    let sink = graph.add_node(NodeType::OutputSink);
13    graph
14        .add_edge(auxide::graph::Edge {
15            from_node: osc,
16            from_port: PortId(0),
17            to_node: sink,
18            to_port: PortId(0),
19            rate: Rate::Audio,
20        })
21        .unwrap();
22
23    let plan = Plan::compile(&graph, 512).unwrap();
24    let runtime = Runtime::new(plan, &graph, 192000.0);
25
26    // Create and start the stream
27    let controller = StreamController::play(runtime)?;
28    controller.start()?;
29
30    println!("Playing 440Hz sine wave for 5 seconds...");
31    thread::sleep(Duration::from_secs(5));
32
33    controller.stop();
34    println!("Stopped.");
35
36    Ok(())
37}