pub struct PlanarPtrAdapterMut<'a, S, const MAX_CHANNELS: usize>where
S: Sample,{ /* private fields */ }Expand description
Adapter for creating mutable planar audio block views from raw pointers.
This adapter provides a safe interface to work with mutable 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 mut ch1 = vec![0.0f32, 1.0, 2.0, 3.0, 4.0];
let mut ch2 = vec![5.0f32, 6.0, 7.0, 8.0, 9.0];
// Create mutable pointers to the channel data
let mut ptrs = [ch1.as_mut_ptr(), ch2.as_mut_ptr()];
let data = ptrs.as_mut_ptr();
let num_channels = 2u16;
let num_frames = 5;
// Create an adapter from raw pointers to audio channel data
let mut adapter = unsafe { PlanarPtrAdapterMut::<f32, 16>::from_ptr(data, num_channels, num_frames) };
// Get a safe mutable view of the audio data
let mut block = adapter.planar_view_mut();
// Verify the data access works and can be modified
assert_eq!(block.sample(0, 2), 2.0);
assert_eq!(block.sample(1, 3), 8.0);
*block.sample_mut(0, 1) = 10.0; // Modify a sample§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 data is not accessed through other pointers during the adapter’s lifetime
- The channel count doesn’t exceed the adapter’s
MAX_CHANNELScapacity
Implementations§
Source§impl<'a, S, const MAX_CHANNELS: usize> PlanarPtrAdapterMut<'a, S, MAX_CHANNELS>where
S: Sample,
impl<'a, S, const MAX_CHANNELS: usize> PlanarPtrAdapterMut<'a, S, MAX_CHANNELS>where
S: Sample,
Sourcepub unsafe fn from_ptr(
ptrs: *mut *mut S,
num_channels: u16,
num_frames: usize,
) -> PlanarPtrAdapterMut<'a, S, MAX_CHANNELS>
pub unsafe fn from_ptr( ptrs: *mut *mut S, num_channels: u16, num_frames: usize, ) -> PlanarPtrAdapterMut<'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_mut(&mut self) -> &mut [&'a mut [S]]
pub fn data_slice_mut(&mut self) -> &mut [&'a mut [S]]
Returns a mutable slice of references to the initialized channel data buffers.
This method provides access to the underlying audio data as a slice of mutable slices, with each inner slice representing one audio channel.
Sourcepub fn planar_view_mut(&mut self) -> AudioBlockPlanarViewMut<'a, S, &mut [S]>
pub fn planar_view_mut(&mut self) -> AudioBlockPlanarViewMut<'a, S, &mut [S]>
Creates a safe AudioBlockPlanarViewMut for accessing the audio data.
This provides a convenient way to interact with the audio data through
the full AudioBlockMut interface, enabling operations like iterating
through channels or frames and modifying the underlying audio samples.
§Returns
An AudioBlockPlanarViewMut that provides safe, mutable access to the audio data.