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//! * [`Scene`], [`SceneRenderer`], [`render_offline`]: sounds and sorted events in frames, and the one mixer that plays them: block by block from
8//! a device callback, or offline for an export that matches live playback sample for sample.
9//! * [`WaveformPlayer`]: renders one [`weirdnet_media::waveform::Waveform`] with play, pause, seek, loop and gain, as the simplest source to play and the
10//! reference for what any other source should do.
11//!
12//! ```
13//! use weirdnet_audio_engine::{AudioSink, ManualSink, SinkConfig, WaveformPlayer};
14//! use weirdnet_media::waveform::Waveform;
15//!
16//! let config = SinkConfig::new(48_000, 1);
17//! let (player, control) = WaveformPlayer::new(Waveform::tone(48_000, 440.0, 480, 0.5)?, &config)?;
18//! let mut sink = ManualSink::new();
19//! let _running = sink.start(config, player.into_render())?;
20//! control.play();
21//! let block = sink.render_block(480).expect("the sink is running");
22//! assert!(block.iter().any(|s| s.abs() > 0.1));
23//! # Ok::<(), Box<dyn std::error::Error>>(())
24//! ```
25//!
26//! The render function runs on the audio thread: it must not block, lock, or allocate. [`WaveformPlayer`] follows that rule and its tests
27//! check what can be checked (the callback only reads shared atomics and the sample buffer it owns).
28
29mod manual;
30mod player;
31mod scene;
32mod sink;
33
34#[cfg(feature = "cpal")]
35mod cpal_sink;
36
37pub use manual::ManualSink;
38pub use player::{PlayerControl, PlayerError, WaveformPlayer};
39pub use scene::{MAX_VOICES, Scene, SceneError, SceneEvent, SceneRenderer, render_offline, render_to_end};
40pub use sink::{AudioSink, RenderFn, SinkConfig, SinkError, SinkHandle, SinkStats};
41
42#[cfg(feature = "cpal")]
43pub use cpal_sink::CpalSink;