StreamController

Struct StreamController 

Source
pub struct StreamController { /* private fields */ }

Implementations§

Source§

impl StreamController

Source

pub fn get_best_sample_rate(requested_rate: f32) -> Result<f32>

Get the best available sample rate for audio output

Source

pub fn play(runtime: Runtime) -> Result<Self>

Examples found in repository?
examples/play_sine.rs (line 27)
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}
More examples
Hide additional examples
examples/play_tone.rs (line 26)
7fn main() -> anyhow::Result<()> {
8    // Build 440Hz sine
9    let mut graph = Graph::new();
10    let osc = graph.add_node(NodeType::SineOsc { freq: 440.0 });
11    let sink = graph.add_node(NodeType::OutputSink);
12    graph
13        .add_edge(auxide::graph::Edge {
14            from_node: osc,
15            from_port: PortId(0),
16            to_node: sink,
17            to_port: PortId(0),
18            rate: Rate::Audio,
19        })
20        .unwrap();
21
22    let plan = Plan::compile(&graph, 512).unwrap();
23    let runtime = Runtime::new(plan, &graph, 192000.0);
24
25    // Play it
26    let controller = StreamController::play(runtime)?;
27    controller.start()?;
28
29    println!("Playing 440Hz tone. Press Enter to stop...");
30    let mut input = String::new();
31    std::io::stdin().read_line(&mut input)?;
32
33    controller.stop();
34    println!("Stopped.");
35
36    Ok(())
37}
examples/audio_mixer.rs (line 65)
15fn main() -> anyhow::Result<()> {
16    println!("Auxide Mixer Demo");
17    println!("Playing a chord: 440Hz (A) + 554Hz (C#)...");
18
19    // Create graph: two oscillators + mixer + output
20    let mut graph = Graph::new();
21
22    // Oscillator 1: 440Hz (A note)
23    let osc1 = graph.add_node(NodeType::SineOsc { freq: 440.0 });
24
25    // Oscillator 2: 554Hz (C# note) - creates a major sixth interval
26    let osc2 = graph.add_node(NodeType::SineOsc { freq: 554.0 });
27
28    // Mixer to combine the two oscillators
29    let mix = graph.add_node(NodeType::Mix);
30
31    // Output sink
32    let sink = graph.add_node(NodeType::OutputSink);
33
34    // Connect: osc1 -> mix (input 0)
35    graph.add_edge(auxide::graph::Edge {
36        from_node: osc1,
37        from_port: PortId(0),
38        to_node: mix,
39        to_port: PortId(0),
40        rate: Rate::Audio,
41    }).unwrap();
42
43    // Connect: osc2 -> mix (input 1)
44    graph.add_edge(auxide::graph::Edge {
45        from_node: osc2,
46        from_port: PortId(0),
47        to_node: mix,
48        to_port: PortId(1),
49        rate: Rate::Audio,
50    }).unwrap();
51
52    // Connect: mix -> output
53    graph.add_edge(auxide::graph::Edge {
54        from_node: mix,
55        from_port: PortId(0),
56        to_node: sink,
57        to_port: PortId(0),
58        rate: Rate::Audio,
59    }).unwrap();
60
61    let plan = Plan::compile(&graph, 512).unwrap();
62    let runtime = Runtime::new(plan, &graph, 44100.0);
63
64    // Play the mixed oscillators
65    let controller = StreamController::play(runtime)?;
66    controller.start()?;
67
68    println!("Playing for 10 seconds...");
69    thread::sleep(Duration::from_secs(10));
70
71    controller.stop();
72    println!("Mixer demo complete!");
73
74    Ok(())
75}
Source

pub fn start(&self) -> Result<()>

Examples found in repository?
examples/play_sine.rs (line 28)
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}
More examples
Hide additional examples
examples/play_tone.rs (line 27)
7fn main() -> anyhow::Result<()> {
8    // Build 440Hz sine
9    let mut graph = Graph::new();
10    let osc = graph.add_node(NodeType::SineOsc { freq: 440.0 });
11    let sink = graph.add_node(NodeType::OutputSink);
12    graph
13        .add_edge(auxide::graph::Edge {
14            from_node: osc,
15            from_port: PortId(0),
16            to_node: sink,
17            to_port: PortId(0),
18            rate: Rate::Audio,
19        })
20        .unwrap();
21
22    let plan = Plan::compile(&graph, 512).unwrap();
23    let runtime = Runtime::new(plan, &graph, 192000.0);
24
25    // Play it
26    let controller = StreamController::play(runtime)?;
27    controller.start()?;
28
29    println!("Playing 440Hz tone. Press Enter to stop...");
30    let mut input = String::new();
31    std::io::stdin().read_line(&mut input)?;
32
33    controller.stop();
34    println!("Stopped.");
35
36    Ok(())
37}
examples/audio_mixer.rs (line 66)
15fn main() -> anyhow::Result<()> {
16    println!("Auxide Mixer Demo");
17    println!("Playing a chord: 440Hz (A) + 554Hz (C#)...");
18
19    // Create graph: two oscillators + mixer + output
20    let mut graph = Graph::new();
21
22    // Oscillator 1: 440Hz (A note)
23    let osc1 = graph.add_node(NodeType::SineOsc { freq: 440.0 });
24
25    // Oscillator 2: 554Hz (C# note) - creates a major sixth interval
26    let osc2 = graph.add_node(NodeType::SineOsc { freq: 554.0 });
27
28    // Mixer to combine the two oscillators
29    let mix = graph.add_node(NodeType::Mix);
30
31    // Output sink
32    let sink = graph.add_node(NodeType::OutputSink);
33
34    // Connect: osc1 -> mix (input 0)
35    graph.add_edge(auxide::graph::Edge {
36        from_node: osc1,
37        from_port: PortId(0),
38        to_node: mix,
39        to_port: PortId(0),
40        rate: Rate::Audio,
41    }).unwrap();
42
43    // Connect: osc2 -> mix (input 1)
44    graph.add_edge(auxide::graph::Edge {
45        from_node: osc2,
46        from_port: PortId(0),
47        to_node: mix,
48        to_port: PortId(1),
49        rate: Rate::Audio,
50    }).unwrap();
51
52    // Connect: mix -> output
53    graph.add_edge(auxide::graph::Edge {
54        from_node: mix,
55        from_port: PortId(0),
56        to_node: sink,
57        to_port: PortId(0),
58        rate: Rate::Audio,
59    }).unwrap();
60
61    let plan = Plan::compile(&graph, 512).unwrap();
62    let runtime = Runtime::new(plan, &graph, 44100.0);
63
64    // Play the mixed oscillators
65    let controller = StreamController::play(runtime)?;
66    controller.start()?;
67
68    println!("Playing for 10 seconds...");
69    thread::sleep(Duration::from_secs(10));
70
71    controller.stop();
72    println!("Mixer demo complete!");
73
74    Ok(())
75}
Source

pub fn stop(&self)

Examples found in repository?
examples/play_sine.rs (line 33)
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}
More examples
Hide additional examples
examples/play_tone.rs (line 33)
7fn main() -> anyhow::Result<()> {
8    // Build 440Hz sine
9    let mut graph = Graph::new();
10    let osc = graph.add_node(NodeType::SineOsc { freq: 440.0 });
11    let sink = graph.add_node(NodeType::OutputSink);
12    graph
13        .add_edge(auxide::graph::Edge {
14            from_node: osc,
15            from_port: PortId(0),
16            to_node: sink,
17            to_port: PortId(0),
18            rate: Rate::Audio,
19        })
20        .unwrap();
21
22    let plan = Plan::compile(&graph, 512).unwrap();
23    let runtime = Runtime::new(plan, &graph, 192000.0);
24
25    // Play it
26    let controller = StreamController::play(runtime)?;
27    controller.start()?;
28
29    println!("Playing 440Hz tone. Press Enter to stop...");
30    let mut input = String::new();
31    std::io::stdin().read_line(&mut input)?;
32
33    controller.stop();
34    println!("Stopped.");
35
36    Ok(())
37}
examples/audio_mixer.rs (line 71)
15fn main() -> anyhow::Result<()> {
16    println!("Auxide Mixer Demo");
17    println!("Playing a chord: 440Hz (A) + 554Hz (C#)...");
18
19    // Create graph: two oscillators + mixer + output
20    let mut graph = Graph::new();
21
22    // Oscillator 1: 440Hz (A note)
23    let osc1 = graph.add_node(NodeType::SineOsc { freq: 440.0 });
24
25    // Oscillator 2: 554Hz (C# note) - creates a major sixth interval
26    let osc2 = graph.add_node(NodeType::SineOsc { freq: 554.0 });
27
28    // Mixer to combine the two oscillators
29    let mix = graph.add_node(NodeType::Mix);
30
31    // Output sink
32    let sink = graph.add_node(NodeType::OutputSink);
33
34    // Connect: osc1 -> mix (input 0)
35    graph.add_edge(auxide::graph::Edge {
36        from_node: osc1,
37        from_port: PortId(0),
38        to_node: mix,
39        to_port: PortId(0),
40        rate: Rate::Audio,
41    }).unwrap();
42
43    // Connect: osc2 -> mix (input 1)
44    graph.add_edge(auxide::graph::Edge {
45        from_node: osc2,
46        from_port: PortId(0),
47        to_node: mix,
48        to_port: PortId(1),
49        rate: Rate::Audio,
50    }).unwrap();
51
52    // Connect: mix -> output
53    graph.add_edge(auxide::graph::Edge {
54        from_node: mix,
55        from_port: PortId(0),
56        to_node: sink,
57        to_port: PortId(0),
58        rate: Rate::Audio,
59    }).unwrap();
60
61    let plan = Plan::compile(&graph, 512).unwrap();
62    let runtime = Runtime::new(plan, &graph, 44100.0);
63
64    // Play the mixed oscillators
65    let controller = StreamController::play(runtime)?;
66    controller.start()?;
67
68    println!("Playing for 10 seconds...");
69    thread::sleep(Duration::from_secs(10));
70
71    controller.stop();
72    println!("Mixer demo complete!");
73
74    Ok(())
75}
Source

pub fn has_error(&self) -> bool

Source

pub fn clear_error(&self)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,