rill_core/traits/buffer_view.rs
1//! # BufferView — backend-specific accessor for I/O ring buffers
2//!
3//! A `BufferView` encapsulates per-backend rules (interleave/deinterleave,
4//! stride, alignment) for reading input samples from and writing output
5//! samples to cross-thread ring buffers or DMA windows.
6//!
7//! Used internally by `rill-io` backends (`DirectView`, `DeinterleavedView`).
8//! Graph nodes access I/O through `IoCapture::read_input()` and
9//! `IoPlayback::write_output()` — they do not use `BufferView` directly.
10
11/// Backend-specific accessor for I/O ring buffers.
12///
13/// Encapsulates per-backend rules (interleave/deinterleave) for reading
14/// input samples from and writing output samples to cross-thread ring buffers.
15/// Each backend provides its own implementation.
16pub trait BufferView: Send + Sync {
17 /// Number of input (capture) channels.
18 fn num_input_channels(&self) -> usize;
19
20 /// Number of output (playback) channels.
21 fn num_output_channels(&self) -> usize;
22
23 /// Read available input samples for one channel into `dst`.
24 ///
25 /// Returns the number of samples actually read (may be less than `dst.len()`
26 /// if insufficient data is available).
27 fn read_input(&self, channel: usize, dst: &mut [f32]) -> usize;
28
29 /// Write output samples for one channel from `src`.
30 ///
31 /// Returns the number of samples actually written (may be less than `src.len()`
32 /// if insufficient space is available).
33 fn write_output(&self, channel: usize, src: &[f32]) -> usize;
34}