Skip to main content

Crate sew_noise

Crate sew_noise 

Source
Expand description

sew-noise: microphone noise removal, a thin API over nnnoiseless (Joe Neeman’s pure-Rust port of RNNoise, by Jean-Marc Valin and Mozilla; BSD-3-Clause, pinned exactly).

  • Stage: the native capture stage. One FRAME (480 samples, 10 ms) block of 48 kHz mono f32 in place, a fixed latency of one block, a Mode that any thread can change at any block without a click, and per-block timing counters (StageStats).
  • Denoiser: one frame at a time, FRAME samples of 48 kHz mono f32 in the range [-1, 1], in and out. The output lags the input by one frame (Denoiser::LATENCY, 10 ms), RNNoise’s overlap-add.
  • StreamDenoiser: any block size at any rate (8–192 kHz). It buffers to frames, resamples linearly to and from 48 kHz when the rate differs, and keeps a fixed latency (StreamDenoiser::latency_samples). This is what a Web Audio worklet calls.

No allocation after construction, no C, no unsafe. Non-finite input samples are read as silence (one NaN would otherwise poison the RNN state for good) and the output is always finite.

RNNoise’s model is compiled in from nnnoiseless; without feature dfn3 nothing is loaded at run time.

Cargo features:

  • capture-stage: the capture_stage module, the capture-hook trait an audio pipeline calls a Stage through.
  • dfn3: Mode::Strong, DeepFilterNet3’s low-latency model (by Hendrik Schröter and the DeepFilterNet authors; MIT OR Apache-2.0), run by inference code in this crate. Its weights are not in the crate: an app ships them beside itself and loads them with dfn3::Dfn3Model::load, which checks their pinned sha256 first (RustCrypto’s sha2). The feature adds sha2 (and realfft, which nnnoiseless already brings), and no C, no unsafe code and no neural-network runtime.

Modules§

capture_stage
The capture-hook shape an audio pipeline calls a Stage through (cargo feature capture-stage).
dfn3
DeepFilterNet3’s low-latency model (cargo feature dfn3): the weights, loaded from a file beside the app, and the model run by hand-written inference in this crate.
probe
A measuring stage (cargo feature probe; for measurement builds only, never a release).

Structs§

Denoiser
One RNNoise state: 480-sample frames of 48 kHz mono f32 in [-1, 1].
Dfn3Layer
DeepFilterNet3’s layer for a running stage (cargo feature dfn3): built and warmed up off the audio thread (Dfn3Layer::new), then handed to a stage built without the model with StageControl::attach_dfn3.
Linear
A streaming converter from from Hz to to Hz. Each input sample emits zero or more output samples; the output lags by at most one input sample.
ModeUnavailable
A mode this build cannot run was asked for. The stage’s mode is unchanged.
Stage
Noise removal for a native capture path: one 10 ms block at a time, in place.
StageControl
A handle on a Stage for other threads: change the mode, read what runs, read the counters. Cheap to clone; every call is a few atomic loads or stores.
StageStats
A snapshot of a stage’s timing counters (StageControl::stats).
StreamDenoiser
Noise removal for a stream of blocks at the context rate (what a Web Audio worklet runs).

Enums§

Error
A refused call. Nothing is processed when one is returned.
Mode
How much noise removal a Stage applies.
StepDownReason
Why the stage stepped down from Strong to Standard.
StrongState
Where Strong is.

Constants§

DEFAULT_GRACE
The grace window a stage opens by itself (StageControl::set_auto_grace): at its first block, at Stage::reset and when it takes a model layer handed over during a call.
FRAME
Samples per frame (10 ms at 48 kHz).
MAX_RATE
The highest context rate StreamDenoiser takes.
MIN_RATE
The lowest context rate StreamDenoiser takes.
SAMPLE_RATE
RNNoise’s only rate.

Functions§

warm_up_thread
Makes the calling thread ready to denoise without allocating.