Expand description
§ndarray crate compatibility
This module implements the audioadapter traits for two-dimensional
ndarray arrays (ArrayBase<_, Ix2>,
which includes Array2<T> and array views).
Because both channel-major and frame-major storage are common, the axis order is selected explicitly when the adapter is created:
NdarrayAdapter::new_channels_framesfor arrays shaped(channels, frames).NdarrayAdapter::new_frames_channelsfor arrays shaped(frames, channels).
Sample access uses ndarray indexing, so it is correct for any memory layout. The bulk copy helpers take a fast path that copies directly from a contiguous slice when the relevant axis is contiguous (the common standard-layout case), and fall back to element-wise access otherwise.
use ndarray::array;
use audioadapter::Adapter;
use audioadapter_compat_ndarray::NdarrayAdapter;
// Two channels, three frames, stored channel-major.
let data = array![[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]];
let adapter = NdarrayAdapter::new_channels_frames(data.view());
assert_eq!(adapter.channels(), 2);
assert_eq!(adapter.frames(), 3);
assert_eq!(adapter.read_sample(1, 2), Some(6.0));Structs§
- Channels
Frames - Axis order for arrays shaped
(channels, frames)(channel-major). - Frames
Channels - Axis order for arrays shaped
(frames, channels)(frame-major). - Ndarray
Adapter - A wrapper implementing the
audioadaptertraits for a two-dimensional ndarray array.
Traits§
- Axis
Order - Axis-order marker describing how the two array axes map to channels and frames.