Skip to main content

Collector

Struct Collector 

Source
pub struct Collector { /* private fields */ }
Expand description

Buffers audio for later analysis.

The collector is designed to be placed in the audio thread, buffering audio chunks for the Analyzer to analyze later.

Implementations§

Source§

impl Collector

Source

pub fn initialize(&mut self, config: &ProcessorConfig) -> Result<(), AicError>

Configures the collector for specific audio settings.

This function must be called before buffering any audio. For the lowest delay use the sample rate and frame size returned by Model::optimal_sample_rate and Model::optimal_num_frames.

§Arguments
  • config - Audio buffering configuration
§Returns

Returns Ok(()) on success or an AicError if initialization fails.

§Warning

Do not call from audio processing threads as this allocates memory.

§Note

All channels are mixed to mono for buffering. To buffer channels independently, create separate Collector instances.

§Example
let config = ProcessorConfig::optimal(&model);
collector.initialize(&config)?;
Source

pub fn buffer_planar<V: AsRef<[f32]>>( &mut self, audio: &[V], ) -> Result<(), AicError>

Buffers audio with separate buffers for each channel (planar layout).

Memory Layout:

  • Separate buffer for each channel
  • Each buffer contains num_frames floats
  • Maximum of 16 channels supported
  • Example for 2 channels, 4 frames:
    audio[0] -> [ch0_f0, ch0_f1, ch0_f2, ch0_f3]
    audio[1] -> [ch1_f0, ch1_f1, ch1_f2, ch1_f3]

The function accepts any type of collection of f32 values that implements as_mut, e.g.:

  • [vec![0.0; 128]; 2]
  • [[0.0; 128]; 2]
  • [&mut ch1, &mut ch2]
§Arguments
  • audio - Array of mutable channel buffer slices to be buffered. Each channel buffer must be exactly of size num_frames, or if allow_variable_frames was enabled, less than the initialization value.
§Notes
  • All channels are mixed to mono for buffering. To buffer channels independently, create separate Collector instances.
  • Maximum supported number of channels is 16. Exceeding this will return an error.
§Returns

Returns Ok(()) on success or an AicError if buffering fails.

§Example
let config = ProcessorConfig::optimal(&model).with_num_channels(2);
collector.initialize(&config)?;
let audio = vec![vec![0.0f32; config.num_frames]; config.num_channels as usize];
collector.buffer_planar(&audio)?;
Source

pub fn buffer_interleaved(&mut self, audio: &[f32]) -> Result<(), AicError>

Buffers audio with interleaved channel data.

Memory Layout:

  • Single contiguous buffer with samples alternating between channels
  • Buffer size: num_channels * num_frames floats
  • Example for 2 channels, 4 frames:
    audio -> [ch0_f0, ch1_f0, ch0_f1, ch1_f1, ch0_f2, ch1_f2, ch0_f3, ch1_f3]
§Arguments
  • audio - Interleaved audio buffer to be buffered. Must be exactly of size num_channels * num_frames, or if allow_variable_frames was enabled, less than the initialization value per channel.
§Note

All channels are mixed to mono for buffering. To buffer channels independently, create separate Collector instances.

§Returns

Returns Ok(()) on success or an AicError if buffering fails.

§Example
let config = ProcessorConfig::optimal(&model).with_num_channels(2);
collector.initialize(&config)?;
let audio = vec![0.0f32; config.num_channels as usize * config.num_frames];
collector.buffer_interleaved(&audio)?;
Source

pub fn buffer_sequential(&mut self, audio: &[f32]) -> Result<(), AicError>

Buffers audio with sequential channel data.

Memory Layout:

  • Single contiguous buffer with all samples for each channel stored sequentially
  • Buffer size: num_channels * num_frames floats
  • Example for 2 channels, 4 frames:
    audio -> [ch0_f0, ch0_f1, ch0_f2, ch0_f3, ch1_f0, ch1_f1, ch1_f2, ch1_f3]
§Arguments
  • audio - Sequential audio buffer to be buffered. Must be exactly of size num_channels * num_frames, or if allow_variable_frames was enabled, less than the initialization value per channel.
§Note

All channels are mixed to mono for buffering. To buffer channels independently, create separate Collector instances.

§Returns

Returns Ok(()) on success or an AicError if buffering fails.

§Example
let config = ProcessorConfig::optimal(&model).with_num_channels(2);
collector.initialize(&config)?;
let audio = vec![0.0f32; config.num_channels as usize * config.num_frames];
collector.buffer_sequential(&audio)?;

Trait Implementations§

Source§

impl Drop for Collector

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Collector

Source§

impl Sync for Collector

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.