#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.echo_cancellation: boolAcoustic 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: boolAutomatic gain control (AGC2 adaptive digital, plus its limiter).
high_pass: boolThe 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: DurationThe 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: StageClockWhat 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: DurationWith 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
impl ProcessingConfig
Sourcepub fn with_capture_stage(self, stage: Box<dyn CaptureStage>) -> Self
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.
Sourcepub fn with_noise_suppression(
self,
ns: Option<NoiseSuppressionStrength>,
) -> Self
pub fn with_noise_suppression( self, ns: Option<NoiseSuppressionStrength>, ) -> Self
Set noise_suppression.
Sourcepub fn with_echo_cancellation(self, on: bool) -> Self
pub fn with_echo_cancellation(self, on: bool) -> Self
Set echo_cancellation.
Sourcepub fn with_gain_control(self, on: bool) -> Self
pub fn with_gain_control(self, on: bool) -> Self
Set gain_control.
Sourcepub fn with_high_pass(self, on: bool) -> Self
pub fn with_high_pass(self, on: bool) -> Self
Set high_pass.
Sourcepub fn with_stage_fallback_noise_suppression(
self,
ns: Option<NoiseSuppressionStrength>,
) -> Self
pub fn with_stage_fallback_noise_suppression( self, ns: Option<NoiseSuppressionStrength>, ) -> Self
Sourcepub fn with_stage_grace(self, grace: Duration) -> Self
pub fn with_stage_grace(self, grace: Duration) -> Self
Set stage_grace.
Sourcepub fn with_stage_clock(self, clock: StageClock) -> Self
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.