Skip to main content

awedio/
lib.rs

1#![warn(missing_docs)]
2#![forbid(unsafe_code)]
3#![cfg_attr(any(feature = "cpal", not(doctest)), doc = include_str!("../README.md"))]
4
5pub mod backends;
6pub mod manager;
7pub mod sounds;
8pub mod utils;
9
10mod error;
11mod sound;
12#[cfg(test)]
13mod tests;
14
15pub use error::Error;
16pub use sound::NextSample;
17pub use sound::Sound;
18
19/// Start outputting audio with the default backend, device, and configs.
20///
21/// Currently if an error occurs, it is printed to stderr but not handled in any
22/// other way. This should be improved in the future.
23/// For more control, create the [CpalBackend][backends::CpalBackend]
24/// explicitly.
25#[cfg(feature = "cpal")]
26pub fn start() -> Result<(manager::Manager, backends::CpalBackend), backends::CpalBackendError> {
27    let mut backend =
28        backends::CpalBackend::with_defaults().ok_or(backends::CpalBackendError::NoDevice)?;
29    let manager = backend.start(|error| eprintln!("error with cpal output stream: {}", error))?;
30    Ok((manager, backend))
31}