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
impl Collector
Sourcepub fn initialize(&mut self, config: &ProcessorConfig) -> Result<(), AicError>
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)?;Sourcepub fn buffer_planar<V: AsRef<[f32]>>(
&mut self,
audio: &[V],
) -> Result<(), AicError>
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_framesfloats - 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 sizenum_frames, or ifallow_variable_frameswas enabled, less than the initialization value.
§Notes
- All channels are mixed to mono for buffering. To buffer channels
independently, create separate
Collectorinstances. - 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)?;Sourcepub fn buffer_interleaved(&mut self, audio: &[f32]) -> Result<(), AicError>
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_framesfloats - 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 sizenum_channels*num_frames, or ifallow_variable_frameswas 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)?;Sourcepub fn buffer_sequential(&mut self, audio: &[f32]) -> Result<(), AicError>
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_framesfloats - 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 sizenum_channels*num_frames, or ifallow_variable_frameswas 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§
Auto Trait Implementations§
impl Freeze for Collector
impl RefUnwindSafe for Collector
impl Unpin for Collector
impl UnsafeUnpin for Collector
impl UnwindSafe for Collector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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