weirdnet-audio-engine 0.2.0

Audio engine pieces for Weirdnet: the AudioSink trait, a manual sink for tests, a cpal device sink (feature `cpal`) and a waveform player.
Documentation
//! The audio output boundary of the engine.
//!
//! * [`AudioSink`]: starts a stream and calls a render function from the device's audio thread. Everything above the sink is platform-free;
//!   a device backend is one implementation of this trait.
//! * [`ManualSink`]: a sink with no device, driven by the caller (`render_block`). It makes engine code deterministic to test.
//! * `CpalSink` (feature `cpal`): the real device.
//! * [`Scene`], [`SceneRenderer`], [`render_offline`]: sounds and sorted events in frames, and the one mixer that plays them: block by block from
//!   a device callback, or offline for an export that matches live playback sample for sample.
//! * [`WaveformPlayer`]: renders one [`weirdnet_media::waveform::Waveform`] with play, pause, seek, loop and gain, as the simplest source to play and the
//!   reference for what any other source should do.
//!
//! ```
//! use weirdnet_audio_engine::{AudioSink, ManualSink, SinkConfig, WaveformPlayer};
//! use weirdnet_media::waveform::Waveform;
//!
//! let config = SinkConfig::new(48_000, 1);
//! let (player, control) = WaveformPlayer::new(Waveform::tone(48_000, 440.0, 480, 0.5)?, &config)?;
//! let mut sink = ManualSink::new();
//! let _running = sink.start(config, player.into_render())?;
//! control.play();
//! let block = sink.render_block(480).expect("the sink is running");
//! assert!(block.iter().any(|s| s.abs() > 0.1));
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! The render function runs on the audio thread: it must not block, lock, or allocate. [`WaveformPlayer`] follows that rule and its tests
//! check what can be checked (the callback only reads shared atomics and the sample buffer it owns).

mod manual;
mod player;
mod scene;
mod sink;

#[cfg(feature = "cpal")]
mod cpal_sink;

pub use manual::ManualSink;
pub use player::{PlayerControl, PlayerError, WaveformPlayer};
pub use scene::{MAX_VOICES, Scene, SceneError, SceneEvent, SceneRenderer, render_offline, render_to_end};
pub use sink::{AudioSink, RenderFn, SinkConfig, SinkError, SinkHandle, SinkStats};

#[cfg(feature = "cpal")]
pub use cpal_sink::CpalSink;