Skip to main content

audio_resample_bsd/
lib.rs

1//! RT-safe audio resampling (rubato-based).
2//!
3//! This crate defines the resampling layer — the [`Resampler`] trait is the
4//! **only processing interface that may be called directly from the real-time
5//! (RT) audio thread**. Codecs, DSP primitives, and graph nodes all perform
6//! sample-rate conversion through this trait.
7//!
8//! # Data layout — planar flat
9//!
10//! Input and output are flat `&[f32]` buffers in **planar** layout:
11//! `[ch0_frames..., ch1_frames...]`. This matches the layout of
12//! [`audio_core_bsd::AudioFrame::samples`], so an `AudioFrame` can be passed to
13//! a `Resampler` directly with no extra copy or rearrangement. The channel
14//! count is fixed when the implementation is constructed.
15//!
16//! # Real-time safety boundary — CRITICAL
17//!
18//! Only [`Resampler::process_into_buffer`] may be called from the RT thread. On
19//! this path, heap allocation / locking / panicking / system calls are all
20//! forbidden (same principle as the `audio-core-bsd` `AudioNode` RT contract).
21//! Every buffer must be pre-allocated when the implementation is constructed.
22//!
23//! [`Resampler::set_rate`] rebuilds the inner resampler to change the ratio and
24//! **therefore allocates**. It must be called only from a configuration/worker
25//! thread — never the RT thread, and only between audio cycles. The RT-alloc=0
26//! guarantee applies only to `process_into_buffer` (the fixed-ratio path).
27//!
28//! # Implementation status (0.2.0)
29//!
30//! This crate provides the public API ([`Resampler`] trait / [`ResampleError`])
31//! and the rubato 4.0-backed standard implementation [`RubatoResampler`].
32//! [`RubatoResampler`] implements a zero-copy, allocation-free RT processing
33//! path at a fixed input ratio (`FixedSync::Input`).
34
35#![cfg_attr(docsrs, feature(doc_cfg))]
36#![warn(missing_docs)]
37#![warn(clippy::all, clippy::pedantic)]
38
39pub mod error;
40pub mod resampler;
41pub mod rubato_impl;
42
43pub use error::{ResampleError, Result};
44pub use resampler::Resampler;
45pub use rubato_impl::RubatoResampler;