Skip to main content

ProcessingConfig

Struct ProcessingConfig 

Source
#[non_exhaustive]
pub struct ProcessingConfig { pub echo_cancellation: bool, pub noise_suppression: Option<NoiseSuppressionStrength>, pub gain_control: bool, pub high_pass: bool, pub capture_stage: Option<Box<dyn CaptureStage>>, pub stage_fallback_noise_suppression: Option<NoiseSuppressionStrength>, pub stage_grace: Duration, pub stage_clock: StageClock, pub stage_starvation_cutoff: Duration, }
Expand description

Which processing runs on the capture path.

#[non_exhaustive]: start from ProcessingConfig::default or ProcessingConfig::off, then set fields or use the with_ methods.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§echo_cancellation: bool

Acoustic echo cancellation (AEC3) against the playback mix.

§noise_suppression: Option<NoiseSuppressionStrength>

Noise suppression, or None for off. Turn it off when a capture_stage removes noise: two suppressors in a row add artefacts for no gain. The engine doesn’t decide that for you.

§gain_control: bool

Automatic gain control (AGC2 adaptive digital, plus its limiter).

§high_pass: bool

The high-pass filter (removes DC and rumble below about 100 Hz). Echo cancellation turns it on regardless.

§capture_stage: Option<Box<dyn CaptureStage>>

The caller’s own processing, after the high-pass filter, echo cancellation and noise suppression (if set) and before gain control. See CaptureStage for the rules, the time budget and the bypass. Levels, VAD and DTX read the signal after the stage and gain control.

None (the default) runs exactly what 0.1 ran. With a stage, echo cancellation and gain control run in two sonora instances with the stage between them.

§stage_fallback_noise_suppression: Option<NoiseSuppressionStrength>

The step-down floor: sonora’s noise suppression at this strength stands in while the capture stage is bypassed (over budget or a fault), and stops again when a retry brings the stage back. The switch crossfades over one 10 ms block and keeps the stage’s timing. Default Some(Moderate), as 0.1 runs it.

It only applies with a stage set and noise_suppression None (otherwise noise suppression already runs before the stage). The suppressor runs on every block in its own sonora instance, so it is converged the moment it is needed; it allocates nothing per block, and costs its band split and merge on top of the suppression 0.1 ran: about 0.5% of a core (50–54 µs per 10 ms block, measured on x86-64). Its own delay (334 samples, 7 ms) is taken out of the stage’s latency, so the timing holds for a stage with at least that much latency (a shorter one: the suppressed signal is that much later). None turns the floor off: a bypassed stage leaves no suppression.

Known behaviour: the phone backend’s raw mode (PhoneMode::Raw, iOS and Android) never runs this floor, whatever it is set to, as it runs no noise suppression at all. A capture stage on raw capture that is bypassed leaves the signal unsuppressed until its retry. That only matters for a stage that removes noise on raw capture.

§stage_grace: Duration

The capture stage’s grace window: for this long (in capture, rounded up to 10 ms blocks) after a TransientEvent (crate::AudioEngine::transient_event), the stage’s start or a capture stream (re)start, slow calls don’t count toward a strike; they are still timed and reported (see CaptureStage). Default DEFAULT_STAGE_GRACE (1.5 s); at most crate::MAX_STAGE_GRACE (10 s), or crate::AudioEngine::start refuses the config. Duration::ZERO turns the grace off: the budget applies from the first call, as in 0.2.1. Only applies with a stage set.

§stage_clock: StageClock

What times the capture stage’s calls for its time budget (see StageClock). Default StageClock::default: the processing thread’s CPU time (StageClock::ThreadCpu) where the platform supports it (macOS, iOS, Linux and Android), else the wall clock. StageClock::Wall times as 0.2.2 and earlier did. Only applies with a stage set.

§stage_starvation_cutoff: Duration

With StageClock::ThreadCpu: a call that takes this long or longer on the wall clock counts as slow toward the 2-in-a-row rule whatever its CPU time, so a thread that really is starved is still caught (counted in CaptureStageStats::starved). Default DEFAULT_STAGE_STARVATION_CUTOFF (20 ms); at least 9 ms (the hard budget), or crate::AudioEngine::start refuses the config. Duration::MAX leaves CPU time alone to decide. Ignored with StageClock::Wall (every call counts its wall time there). Only applies with a stage set.

Implementations§

Source§

impl ProcessingConfig

Source

pub fn off() -> Self

No processing at all: capture passes through unchanged.

Source

pub fn with_capture_stage(self, stage: Box<dyn CaptureStage>) -> Self

Set the capture_stage. Noise suppression stays as it is: turn it off with with_noise_suppression(None) if the stage removes noise.

Source

pub fn with_noise_suppression( self, ns: Option<NoiseSuppressionStrength>, ) -> Self

Source

pub fn with_echo_cancellation(self, on: bool) -> Self

Source

pub fn with_gain_control(self, on: bool) -> Self

Source

pub fn with_high_pass(self, on: bool) -> Self

Set high_pass.

Source

pub fn with_stage_fallback_noise_suppression( self, ns: Option<NoiseSuppressionStrength>, ) -> Self

Source

pub fn with_stage_grace(self, grace: Duration) -> Self

Source

pub fn with_stage_clock(self, clock: StageClock) -> Self

Set stage_clock. with_stage_clock(StageClock::Wall) times the stage as 0.2.2 did.

Source

pub fn with_stage_starvation_cutoff(self, cutoff: Duration) -> Self

Trait Implementations§

Source§

impl Debug for ProcessingConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ProcessingConfig

Source§

fn default() -> Self

Everything on: AEC3, moderate noise suppression, AGC2 and the high-pass filter. No capture stage.

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<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more