pub struct ProcessorContext { /* private fields */ }Expand description
Thread-safe control handle for a Processor.
Create one with Processor::context. Every method on this type maps to an SDK
function that can be called from any thread, so a context can be moved to another thread to
read and write parameters, query the audio delay, or reset the processor while audio is being
processed elsewhere.
Dropping the context does not destroy the processor it came from, and multiple contexts can be created from the same processor.
Implementations§
Source§impl ProcessorContext
impl ProcessorContext
Sourcepub fn set_parameter(
&self,
parameter: ProcessorParameter,
value: f32,
) -> Result<(), AicError>
pub fn set_parameter( &self, parameter: ProcessorParameter, value: f32, ) -> Result<(), AicError>
Modifies an enhancement parameter.
All parameters can be changed during audio processing. This function can be called from any thread.
This operates on the processor associated with this context handle.
§Arguments
parameter- Parameter to modifyvalue- 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)?;Sourcepub fn parameter(&self, parameter: ProcessorParameter) -> Result<f32, AicError>
pub fn parameter(&self, parameter: ProcessorParameter) -> Result<f32, AicError>
Retrieves the current value of a parameter.
This function can be called from any thread.
This queries the processor associated with this context handle.
§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}");Sourcepub fn audio_delay(&self) -> usize
pub fn audio_delay(&self) -> usize
Returns the delay applied to the audio 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.
The processed audio leaves Processor::process this many samples behind its input.
Use this value to synchronize enhanced audio with other streams or to implement
delay compensation in your application.
Delay behavior:
- Before initialization: Returns the base processing delay using the model’s optimal block size at its native sample rate
- After initialization: Returns the actual delay for your specific configuration, including any additional buffering introduced by a non-optimal block size
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 a block size different from the optimal value returned by
optimal_block_size will increase the delay beyond the model’s base latency.
§Returns
Returns the delay in samples.
§Example
let delay = processor_context.audio_delay();
println!("Audio delay: {} samples", delay);Sourcepub fn reset(&self) -> Result<(), AicError>
pub fn reset(&self) -> Result<(), AicError>
Clears all internal state and buffers.
Call this when the audio stream is interrupted or when seeking to prevent artifacts from previous audio content.
This operates on the processor associated with this context handle.
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()?;Sourcepub fn update_bearer_token(&self, token: &str) -> Result<(), AicError>
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. Calling this with a renewed token lets you stay authenticated without tearing down and recreating the processor: 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. Other license types cannot be swapped in this way.
On any error the call is a no-op: the previously active token stays in use and the telemetry session is unaffected (no backoff, no interruption to processing).
On success the swap is applied immediately and is not gated on backend acceptance. The token is validated locally for format only; if the backend later rejects it (e.g. expired or revoked), the SDK retries it under backoff rather than rolling back to the prior token, and audio processing is eventually disabled if no accepted token arrives in time. Supplying a known-good token via this call during that window recovers the session.
Safe to call concurrently with Processor::process on the originating processor.
§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.context();
let renewed_jwt = String::from("<JWT_BEARER_TOKEN>");
processor_context.update_bearer_token(&renewed_jwt)?;Trait Implementations§
Source§impl Drop for ProcessorContext
impl Drop for ProcessorContext
impl Send for ProcessorContext
impl Sync for ProcessorContext
Auto Trait Implementations§
impl Freeze for ProcessorContext
impl RefUnwindSafe for ProcessorContext
impl Unpin for ProcessorContext
impl UnsafeUnpin for ProcessorContext
impl UnwindSafe for ProcessorContext
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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