pub struct PlanarPtrAdapter<'a, S, const MAX_CHANNELS: usize>where
S: Sample,{ /* private fields */ }Expand description
Adapter for creating planar audio block views from raw pointers.
This adapter provides a safe interface to work with audio data stored in external buffers, which is common when interfacing with audio APIs or hardware.
§Example
use audio_blocks::*;
// Create sample data for two channels with five frames each
let ch1 = vec![0.0f32, 1.0, 2.0, 3.0, 4.0];
let ch2 = vec![5.0f32, 6.0, 7.0, 8.0, 9.0];
// Create pointers to the channel data
let ptrs = [ch1.as_ptr(), ch2.as_ptr()];
let data = ptrs.as_ptr();
let num_channels = 2u16;
let num_frames = 5;
// Create an adapter from raw pointers to audio channel data
let adapter = unsafe { PlanarPtrAdapter::<f32, 16>::from_ptr(data, num_channels, num_frames) };
// Get a safe view of the audio data
let block = adapter.planar_view();
// Verify the data access works
assert_eq!(block.sample(0, 2), 2.0);
assert_eq!(block.sample(1, 3), 8.0);§Safety
When creating an adapter from raw pointers, you must ensure that:
- The pointers are valid and properly aligned
- The memory they point to remains valid for the lifetime of the adapter
- The channel count doesn’t exceed the adapter’s
MAX_CHANNELScapacity
Implementations§
Source§impl<'a, S, const MAX_CHANNELS: usize> PlanarPtrAdapter<'a, S, MAX_CHANNELS>where
S: Sample,
impl<'a, S, const MAX_CHANNELS: usize> PlanarPtrAdapter<'a, S, MAX_CHANNELS>where
S: Sample,
Sourcepub unsafe fn from_ptr(
ptr: *const *const S,
num_channels: u16,
num_frames: usize,
) -> PlanarPtrAdapter<'a, S, MAX_CHANNELS>
pub unsafe fn from_ptr( ptr: *const *const S, num_channels: u16, num_frames: usize, ) -> PlanarPtrAdapter<'a, S, MAX_CHANNELS>
Creates new pointer adapter to create an audio block from raw pointers.
§Safety
ptrmust be a valid pointer to an array of pointers- The array must contain at least
num_channelsvalid pointers - Each pointer in the array must point to a valid array of samples with
num_frameslength - The pointed memory must remain valid for the lifetime of the returned adapter
- The data must not be modified through other pointers for the lifetime of the returned adapter
Sourcepub fn data_slice(&self) -> &[&'a [S]]
pub fn data_slice(&self) -> &[&'a [S]]
Returns a slice of references to the initialized channel data buffers.
This method provides access to the underlying audio data as a slice of slices, with each inner slice representing one audio channel.
Sourcepub fn planar_view(&self) -> AudioBlockPlanarView<'a, S, &[S]>
pub fn planar_view(&self) -> AudioBlockPlanarView<'a, S, &[S]>
Creates a safe AudioBlockPlanarView for accessing the audio data.
This provides a convenient way to interact with the audio data through
the full AudioBlock interface, enabling operations like iterating
through channels or frames.
§Returns
A AudioBlockPlanarView that provides safe, immutable access to the audio data.