Skip to main content

audio_codec_bsd/
lib.rs

1//! A multi-format audio container decoder (FLAC / PCM / WAV).
2//!
3//! This crate decodes FLAC, PCM, and WAV containers into planar
4//! [`audio_core_bsd::AudioFrame`]s on a **worker thread**. It is deliberately
5//! **not** real-time safe: implementations are expected to perform file I/O
6//! and heap allocation freely. Decoded frames are handed to a lock-free ring
7//! buffer or similar channel so the RT audio thread never touches this crate.
8//!
9//! ## Supported formats
10//!
11//! - **FLAC** — lossless, decoded via [`SymphoniaDecoder`] (symphonia 0.6).
12//! - **WAV** — PCM/IEEE-float RIFF, decoded via [`WavDecoder`] (hound).
13//! - **PCM** — raw headerless little-endian samples (planned).
14//!
15//! Use [`open`] for magic-byte auto-detection, or construct a concrete
16//! decoder directly when the container is known ahead of time.
17//!
18//! ## Dependency licensing
19//!
20//! This crate depends on [`symphonia`] (**MPL-2.0**, pure Rust) and
21//! [`hound`] (**Apache-2.0/MIT**, pure Rust). MPL-2.0 permits static/dynamic
22//! linking from a BSD-2-Clause crate without copyleft contamination,
23//! provided that any *modified* symphonia source files are republished under
24//! MPL-2.0. Unmodified use (the default) imposes only a notice obligation.
25//! Because MPL-2.0 is file-level, any forked/modified symphonia files must
26//! carry the MPL header and be disclosed.
27//!
28//! [`symphonia`]: https://crates.io/crates/symphonia
29//! [`hound`]: https://crates.io/crates/hound
30//!
31//! # Example
32//!
33//! Open a container by magic-byte sniffing and drain it frame-by-frame into
34//! planar [`audio_core_bsd::AudioFrame`]s:
35//!
36//! ```rust,no_run
37//! use audio_codec_bsd::open;
38//! use std::path::Path;
39//!
40//! let mut dec = open(Path::new("song.flac"))?;
41//! let info = dec.open(Path::new("song.flac"))?;
42//! while let Some(_frame) = dec.next_frame()? {
43//!     // push _frame into a lock-free ring for the RT thread.
44//! }
45//! # let _ = info;
46//! # Ok::<(), audio_codec_bsd::CodecError>(())
47//! ```
48
49#![cfg_attr(docsrs, feature(doc_cfg))]
50#![warn(missing_docs)]
51#![warn(clippy::all, clippy::pedantic)]
52
53pub mod decoder;
54pub mod error;
55pub mod format;
56pub mod symphonia_impl;
57pub mod wav;
58
59pub use decoder::{ContainerDecoder, FormatKind, StreamInfo};
60pub use error::{CodecError, Result};
61pub use format::open;
62pub use symphonia_impl::SymphoniaDecoder;
63pub use wav::WavDecoder;