PlanarPtrAdapter

Struct PlanarPtrAdapter 

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

Implementations§

Source§

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

Source

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
  • 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(&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.

Source

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.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

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.