Skip to main content

Crate cathar

Crate cathar 

Source
Expand description

Audio restoration toolbox — denoise, de-hum, de-click, de-clip, normalise.

Default denoising uses spectral subtraction (pure Rust, zero weights). Enable the ml feature for candle-based neural denoising (Demucs, DNS Challenge).

§Quick start

use cathar::{Denoiser, SpectralDenoiser, generate_wave};

let audio = generate_wave(44100, 440.0, 1.0, 0.2);
let denoiser = SpectralDenoiser::default();
let clean = denoiser.denoise(&audio)?;
assert_eq!(clean.channels[0].len(), audio.channels[0].len());

Structs§

AudioData
Decoded audio: a sample rate plus one f32 PCM buffer per channel (de-interleaved, sample values in [-1.0, 1.0]).
NoisePrint
Pre-computed noise profile from a silence segment. Feed into SpectralDenoiser::with_noise_print instead of auto-detection.
SpectralDenoiser
STFT spectral-subtraction / Wiener denoiser (see Denoiser).
Spectrogram
A magnitude spectrogram: a column per time frame, each holding bins frequency rows (row 0 = DC, row bins-1 = Nyquist), in decibels.

Enums§

Error
Errors returned by cathar’s decode, encode, and processing routines.

Traits§

Denoiser
A denoising strategy: turn noisy AudioData into a cleaner copy.

Functions§

bandwidth_extend
Restore high-frequency content lost to compression or low sample rates.
breath_remove
Detect and attenuate breath sounds between speech segments.
declick
Detect and interpolate impulse clicks.
declip
Reconstruct clipped samples with A-SPADE sparse declipping (Kitić, Bertin & Gribonval 2015) over a Hann-windowed, 4×-overlapping Gabor tight frame.
deess_multiband
Multiband, adaptive de-esser. The region above crossover_freq is split into bands sub-bands; each tracks its own short-term level (an exponential moving average) and is compressed by ratio only when its instantaneous level rises threshold_db above that adaptive average. Adapting per band and over time catches sibilance concentrated in part of the band and follows a speaker’s changing level, where a single fixed-threshold band over- or under-reacts. Falls back to a single band when bands <= 1.
deesser
Reduce sibilance (harsh “s”, “sh”, “ch” sounds) using HF compression.
dehum
Remove mains hum (50/60 Hz + harmonics) using cascaded notch filters.
deplosive
Tame plosive pops — the low-frequency bursts on “p”/“b” sounds — by attenuating transient energy below ~250 Hz. strength 1–10 (higher removes more). Sustained low-frequency content is preserved.
dereverb
Remove room reverb using spectral envelope decay gating.
derustle
Suppress lavalier / clothing rustle — transient bursts in the ~1.5–6 kHz band are scaled back toward the local temporal median. strength 1–10. Sustained speech in that band is left largely intact.
dewind
Remove low-frequency wind rumble with a 4th-order Butterworth high-pass (two cascaded biquads, ~24 dB/octave). cutoff_hz is the corner frequency (≈ 80 Hz suits most handheld/outdoor wind); content above it is untouched.
dither
Apply triangular-probability-density-function (TPDF) dither at bits resolution. Adds two independent rectangular dithers of amplitude ±0.5 LSB to decorrelate quantisation noise from the signal. Intended for use before truncation to a lower bit depth.
fade
Apply a linear fade-in and/or fade-out to a mono signal. in_sec and out_sec specify the fade durations in seconds. Non-overlapping.
gain_db
Multiply every sample by 10^(db/20). Positive dB boosts, negative cuts.
generate_wave
Generate a mono test tone: a frequency-Hz sine at 0.5 amplitude plus uniform white noise scaled by noise_level, duration_secs long. Uses a fixed seed, so the output is deterministic.
integrated_loudness
Measure integrated loudness in LUFS per ITU-R BS.1770-4 / EBU R128: K-weighting, 400 ms blocks at 75 % overlap, the -70 LUFS absolute gate, then the -10 LU relative gate.
learn_noise_print
Learn a noise profile from an audio segment (should be silence/noise-only).
normalize_peak
Scale to target peak level in dBFS (0 dBFS = ±1.0, -3 dBFS = ~±0.707).
pad
Pad a mono signal with silence at the start and/or end. start_sec and end_sec specify how many seconds of silence to prepend/append.
remix
Remix channels: spec is a list of channel indices or mappings. input_channels are the original channels; output channels are built from spec. Each entry in spec is a list of (channel_index, gain) tuples. The output channel is the sum of input_channel[idx] * gain for each tuple.
resample
Resample one channel from from_rate to to_rate with a Kaiser-windowed sinc (arbitrary ratio). The cutoff tracks the lower of the two Nyquist limits, so downsampling is anti-aliased and upsampling adds no imaging; the filter support widens at low cutoffs to keep the stopband sharp. Returns the input unchanged when the rates already match.
reverse
Reverse a mono signal in time.
select_channels
Select a subset of channels by index.
silence_strip
Strip leading and trailing silence. A sample is “silent” if its magnitude is below threshold_amplitude. Runs shorter than min_duration_sec at the boundary are discarded; gaps shorter than min_duration_sec within non-silent audio are kept.
spectral_repair
Paint out isolated transient spectral artifacts — brief whistles, bursts, and glitches that appear in only a few STFT frames.
spectrogram
Compute the magnitude spectrogram of signal via a Hann-windowed STFT.
trim
Extract a time slice from a mono signal. start and duration are in seconds; samples outside the original range are clamped to the boundary. Returns None if the requested slice is empty.
true_peak_dbtp
Estimate true-peak level in dBTP via 4× polyphase oversampling (the inter-sample-peak method of ITU-R BS.1770-4). Returns f32::NEG_INFINITY for digital silence. Oversampling is fixed at 4×, independent of sample rate.
vad
Simple energy-based voice activity detection: returns (start_sec, end_sec), where the signal rises above threshold_amplitude and stays for at least min_duration_sec. Returns None if no voice segment is found.
variance
Population variance of a sample buffer (mean of squared deviations).
voice_isolate
Isolate speech from background using energy-based VAD + spectral gating.
wiener_denoise
Wiener-filter denoiser — statistically optimal, better transients.