PlanarPtrAdapterMut

Struct PlanarPtrAdapterMut 

Source
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_CHANNELS capacity

Implementations§

Source§

impl<'a, S, const MAX_CHANNELS: usize> PlanarPtrAdapterMut<'a, S, MAX_CHANNELS>
where S: Sample,

Source

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
  • ptr must be a valid pointer to an array of pointers
  • The array must contain at least num_channels valid pointers
  • Each pointer in the array must point to a valid array of samples with num_frames length
  • 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
Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'a, S, const MAX_CHANNELS: usize> Freeze for PlanarPtrAdapterMut<'a, S, MAX_CHANNELS>

§

impl<'a, S, const MAX_CHANNELS: usize> RefUnwindSafe for PlanarPtrAdapterMut<'a, S, MAX_CHANNELS>
where S: RefUnwindSafe,

§

impl<'a, S, const MAX_CHANNELS: usize> Send for PlanarPtrAdapterMut<'a, S, MAX_CHANNELS>
where S: Send,

§

impl<'a, S, const MAX_CHANNELS: usize> Sync for PlanarPtrAdapterMut<'a, S, MAX_CHANNELS>
where S: Sync,

§

impl<'a, S, const MAX_CHANNELS: usize> Unpin for PlanarPtrAdapterMut<'a, S, MAX_CHANNELS>

§

impl<'a, S, const MAX_CHANNELS: usize> !UnwindSafe for PlanarPtrAdapterMut<'a, S, MAX_CHANNELS>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.