Skip to main content

RawBufferScratch

Struct RawBufferScratch 

Source
pub struct RawBufferScratch<S: Sample = f32> {
    pub input_slices: Vec<&'static [S]>,
    pub output_slices: Vec<&'static mut [S]>,
    /* private fields */
}
Expand description

Scratch space for RawBufferScratch::build.

Callers allocate this on the stack and pass it to build. The buffer borrows the slices stored here, so this struct must outlive the returned AudioBuffer.

Generic over the plugin’s sample type S. When the host buffer matches S, slices point into host memory (zero-copy). When the host buffer is a different precision, the input is widened/narrowed into per-channel scratch; the output is rendered into scratch and the wrapper copies + casts it back to the host buffer at the end of the block via Self::finish_widening_f32.

Fields§

§input_slices: Vec<&'static [S]>§output_slices: Vec<&'static mut [S]>

Implementations§

Source§

impl<S: Sample> RawBufferScratch<S>

Source

pub unsafe fn build( &mut self, inputs: *const *const f32, outputs: *mut *mut f32, num_in: u32, num_out: u32, num_frames: u32, supports_in_place: bool, ) -> AudioBuffer<'_, S>

Build an AudioBuffer<S> from raw f32 host pointers - the common case (CLAP, LV2, AAX always; VST3/VST2/AU 32-bit mode).

When S = f32, slices point directly into host memory (modulo in-place input copying). When S = f64, every channel is widened into per-channel scratch and the wrapper must call Self::finish_widening_f32 at the end of the block to copy the rendered samples back to the host’s f32 output pointers.

§Safety
  • inputs must point to num_in valid *const f32 pointers (each non-null pointer must address at least num_frames readable samples; null is allowed and yields an empty slice).
  • outputs must point to num_out valid *mut f32 pointers (each non-null pointer must address at least num_frames writable samples; null is allowed and yields an empty slice).
  • The pointed-to memory must remain valid for the lifetime of the returned AudioBuffer.
Source

pub unsafe fn finish_widening_f32( &self, outputs: *mut *mut f32, num_out: u32, num_frames: u32, )

Copy + narrow the rendered S output back to the host’s f32 output pointers. No-op when S = f32 (the slices the plugin wrote already point directly at host memory).

§Safety

outputs and num_out / num_frames must match the values passed to the prior Self::build call on this scratch.

Source

pub fn ensure_capacity( &mut self, num_in: usize, num_out: usize, max_frames: usize, )

Pre-allocate the per-channel scratch vectors so build runs allocation-free for buses up to num_in × num_out channels and blocks up to max_frames. Idempotent and growth-only.

Trait Implementations§

Source§

impl<S: Sample> Default for RawBufferScratch<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S> Freeze for RawBufferScratch<S>

§

impl<S> RefUnwindSafe for RawBufferScratch<S>
where S: RefUnwindSafe,

§

impl<S> Send for RawBufferScratch<S>

§

impl<S> Sync for RawBufferScratch<S>

§

impl<S> Unpin for RawBufferScratch<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for RawBufferScratch<S>

§

impl<S = f32> !UnwindSafe for RawBufferScratch<S>

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<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.