weirdnet_audio_engine/lib.rs
1//! The audio output boundary of the engine.
2//!
3//! * [`AudioSink`]: starts a stream and calls a render function from the device's audio thread. Everything above the sink is platform-free;
4//! a device backend is one implementation of this trait.
5//! * [`ManualSink`]: a sink with no device, driven by the caller (`render_block`). It makes engine code deterministic to test.
6//! * `CpalSink` (feature `cpal`): the real device.
7//! * [`AudioSource`], [`ManualSource`] and `CpalSource` (feature `cpal`): the input boundary, a capture function called from the device's input thread.
8//! * [`talkback`]: voices between people on a bus of their own: the mic switch (starts muted), a level gate, a speaker mixer with jitter
9//! buffers, volume and mute, and a ducker for the music.
10//! * [`Scene`], [`SceneRenderer`], [`render_offline`]: sounds and sorted events in frames, and the one mixer that plays them: block by block from
11//! a device callback, or offline for an export that matches live playback sample for sample.
12//! * [`router`]: named endpoints (sources, inputs fed from other threads, buses, taps and the device) wired by routes and mixed
13//! in a fixed order, with mute, solo and limiters; with the `route` feature, the local executor of a weirdnet-audio-route graph.
14//! * [`WaveformPlayer`]: renders one [`weirdnet_media::waveform::Waveform`] with play, pause, seek, loop and gain, as the simplest source to play and the
15//! reference for what any other source should do.
16//!
17//! ```
18//! use weirdnet_audio_engine::{AudioSink, ManualSink, SinkConfig, WaveformPlayer};
19//! use weirdnet_media::waveform::Waveform;
20//!
21//! let config = SinkConfig::new(48_000, 1);
22//! let (player, control) = WaveformPlayer::new(Waveform::tone(48_000, 440.0, 480, 0.5)?, &config)?;
23//! let mut sink = ManualSink::new();
24//! let _running = sink.start(config, player.into_render())?;
25//! control.play();
26//! let block = sink.render_block(480).expect("the sink is running");
27//! assert!(block.iter().any(|s| s.abs() > 0.1));
28//! # Ok::<(), Box<dyn std::error::Error>>(())
29//! ```
30//!
31//! The render function runs on the audio thread: it must not block, lock, or allocate. [`WaveformPlayer`] follows that rule and its tests
32//! check what can be checked (the callback only reads shared atomics and the sample buffer it owns).
33
34mod engine;
35mod input;
36mod manual;
37mod player;
38#[cfg(feature = "route")]
39mod route_exec;
40pub mod router;
41mod scene;
42mod sink;
43pub mod talkback;
44
45#[cfg(feature = "cpal")]
46mod cpal_sink;
47
48pub use engine::{Command, Engine, EngineAudio, EngineError, EngineOptions, Event, Timing, engine};
49pub use input::{AudioSource, CaptureFn, ManualSource};
50pub use manual::ManualSink;
51pub use player::{PlayerControl, PlayerError, WaveformPlayer};
52pub use scene::{MAX_VOICES, NO_TAG, Scene, SceneError, SceneEvent, SceneRenderer, render_offline, render_to_end};
53pub use sink::{AudioSink, RenderFn, SinkConfig, SinkError, SinkHandle, SinkStats};
54
55#[cfg(feature = "cpal")]
56pub use cpal_sink::CpalSink;
57#[cfg(feature = "cpal")]
58pub use input::CpalSource;