Skip to main content

ProcessorContext

Struct ProcessorContext 

Source
pub struct ProcessorContext { /* private fields */ }

Implementations§

Source§

impl ProcessorContext

Source

pub fn set_parameter( &self, parameter: ProcessorParameter, value: f32, ) -> Result<(), AicError>

Modifies a processor parameter.

All parameters can be changed during audio processing. This function can be called from any thread.

§Arguments
  • parameter - Parameter to modify
  • value - New parameter value. See parameter documentation for ranges
§Returns

Returns Ok(()) on success or an AicError if the parameter cannot be set.

§Example
proc_ctx.set_parameter(ProcessorParameter::EnhancementLevel, 0.8)?;
Source

pub fn parameter(&self, parameter: ProcessorParameter) -> Result<f32, AicError>

Retrieves the current value of a parameter.

This function can be called from any thread.

§Arguments
  • parameter - Parameter to query
§Returns

Returns Ok(value) containing the current parameter value, or an AicError if the query fails.

§Example
let enhancement_level = processor_context.parameter(ProcessorParameter::EnhancementLevel)?;
println!("Current enhancement level: {enhancement_level}");
Source

pub fn output_delay(&self) -> usize

Returns the total output delay in samples for the current audio configuration.

This function provides the complete end-to-end latency introduced by the processor, which includes both algorithmic processing delay and any buffering overhead. Use this value to synchronize enhanced audio with other streams or to implement delay compensation in your application.

Enhancement vs. VAD models:

  • For an enhancement model this is the latency of the enhanced audio: the number of samples by which the processed output lags behind the input.
  • For a dedicated VAD model, the audio buffer is input-only and passes through unchanged. This delay is the VAD prediction latency: how many samples a speech decision from VadContext::is_speech_detected lags behind the input it describes. Use this value to line up VAD decisions with the input timeline.

Delay behavior:

  • Before initialization: Returns the base processing delay using the model’s optimal frame size at its native sample rate
  • After initialization: Returns the actual delay for your specific configuration, including any additional buffering introduced by non-optimal frame sizes

Important: The delay value is always expressed in samples at the sample rate you configured during initialize. To convert to time units: delay_ms = (delay_samples * 1000) / sample_rate

Note: Using frame sizes different from the optimal value returned by optimal_num_frames will increase the delay beyond the model’s base latency.

§Returns

Returns the delay in samples.

§Example
let delay = processor_context.output_delay();
println!("Output delay: {} samples", delay);
Source

pub fn reset(&self) -> Result<(), AicError>

Clears all internal state and buffers. This also resets the VAD state associated with this processor.

Call this when the audio stream is interrupted or when seeking to prevent artifacts from previous audio content.

The processor stays initialized to the configured settings.

§Returns

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

§Real-time safety

Real-time safe. Can be called from audio processing threads.

§Example
processor_context.reset()?;
Source

pub fn update_bearer_token(&self, token: &str) -> Result<(), AicError>

Replaces the bearer token on the running processor.

Use this when your license key is a JWT and needs to be refreshed before it expires. Audio processing continues uninterrupted, the context handle stays valid, and the new token is used for all subsequent authentication against the ai-coustics backend.

In-place updates are only supported when both the originally configured key and the new token are JWTs. If either side is not, the call returns AicError::TokenUpdateUnsupported and the existing token stays in use.

§Arguments
  • token - The new JWT to install.
§Returns

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

§Real-time safety

This function is not real-time safe. It locks a mutex and allocates memory. Avoid calling it from audio threads.

§Example
let processor = Processor::new(&model, &license_key)?;
let processor_context = processor.processor_context();
let renewed_jwt = String::from("<JWT_BEARER_TOKEN>");
processor_context.update_bearer_token(&renewed_jwt)?;

Trait Implementations§

Source§

impl Drop for ProcessorContext

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 ProcessorContext

Source§

impl Sync for ProcessorContext

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.