1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! Public resampling interface — the RT-safe processing boundary of this crate.
//!
//! This module defines [`Resampler`], the only processing trait that may be
//! called directly from the real-time (RT) audio thread. See the crate-level
//! docs and the [`Resampler`] trait docs for the full RT-safety boundary.
use crateResampleError;
/// Public contract for audio sample-rate conversion (resampling).
///
/// This trait is the **only processing interface that may be called directly
/// from the RT (real-time) thread**. The rubato-backed implementation
/// ([`crate::RubatoResampler`]) is provided as the standard reference.
///
/// # Data layout — planar flat
///
/// `input`/`output` are flat buffers in **planar** layout:
/// `[ch0_frames..., ch1_frames...]`. This matches the layout of
/// [`audio_core_bsd::AudioFrame::samples`]. The channel count is fixed when the
/// implementation is constructed (e.g. `RubatoResampler::new(in, out, channels,
/// chunk)`).
///
/// # Real-time safety — CRITICAL
///
/// [`Resampler::process_into_buffer`] is invoked on the RT thread. The
/// following are forbidden (same principle as the `audio-core-bsd` `AudioNode`
/// RT contract):
///
/// - **No heap allocation** — every buffer must be pre-allocated at
/// construction.
/// - **No locking** — only wait-free primitives are permitted.
/// - **No panicking** — no `unwrap`/`expect`/`assert`/out-of-bounds indexing.
/// Degrade gracefully (e.g. emit silence) instead.
/// - **No system calls / I/O**.
///
/// # `set_rate` is NOT real-time safe
///
/// [`Resampler::set_rate`] rebuilds the inner resampler to change the ratio and
/// **therefore allocates**. It must be called only from a configuration/worker
/// thread — never the RT thread, and only between audio cycles. The RT-alloc=0
/// guarantee applies only to `process_into_buffer` (the fixed-ratio path).