Skip to main content

Crate audioadapter_compat_ndarray

Crate audioadapter_compat_ndarray 

Source
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:

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§

ChannelsFrames
Axis order for arrays shaped (channels, frames) (channel-major).
FramesChannels
Axis order for arrays shaped (frames, channels) (frame-major).
NdarrayAdapter
A wrapper implementing the audioadapter traits for a two-dimensional ndarray array.

Traits§

AxisOrder
Axis-order marker describing how the two array axes map to channels and frames.