Skip to main content

sound_to_patch/
dsp.rs

1//! The signal core that every estimator uses.
2//!
3//! It holds windows, the STFT, peak picking, active frames with their
4//! statistics, the analytic signal, decay fits, the stem descriptors, the
5//! modulation spectrum and the Lomb-Scargle periodogram.
6//!
7//! Conventions that bind every estimator:
8//!
9//! - Samples and spectra are `f64` at the stem's native rate.
10//! - The window is the periodic Hann, `w[n] = 0.5 - 0.5 cos(2 pi n / N)`.
11//! - Frames are centred and zero-padded, with hop `N/4`. The layer chooses
12//!   `N` from the median f0 of the note list: 8192 below 100 Hz, else 4096.
13//!   A Hann main lobe is about 4 bins wide, so harmonics `f0` apart need
14//!   `N >= 4 fs / f0`.
15//! - A frame is active when its RMS lies within 40 dB of the loudest frame.
16//!   Statistics over active frames are the median and the interquartile
17//!   range, which resist outliers.
18//! - The transforms are not normalised; the caller scales.
19
20mod analytic;
21mod decay;
22pub(crate) mod descriptors;
23mod frames;
24mod lomb;
25mod modulation;
26mod peak;
27mod stft;
28mod window;
29
30pub use analytic::{
31    ATTACK_LOW_PASS_HZ, AnalyticSignal, Baseband, FilterError, HeterodyneParams, am_depth,
32    band_magnitude, band_pass_zero_phase, heterodyne, low_pass_zero_phase,
33};
34pub(crate) use decay::fit_line;
35pub use decay::{Decay, DecayFailure, FitRange, backward_integral};
36pub use descriptors::{
37    BAND_CONVENTION, BAND_EDGES_HZ, BandShare, Descriptors, FLATNESS_CONVENTION, FLATNESS_FLOOR,
38    FrameDescriptors, LEVEL_CONVENTION, SHAPE_CONVENTION, describe, frame_descriptors,
39};
40pub use frames::{
41    ACTIVE_GATE_DB, ActiveFrames, MIN_ACTIVE_FRAMES, Stats, Summary, frame_rms, quantile,
42};
43pub use lomb::{GRID_STEP_HZ, SETTLE_S, gated_samples, grid, lomb_scargle, periodogram_rate};
44pub use modulation::{
45    BPM_SCAN, FOLD_BINS, LINE_PROMINENCE, MIN_CYCLES, MIN_LINE_DEPTH, ModulationSpectrum,
46    SCAN_BOTTOM_HZ, SCAN_TOP_HZ, SPECTRUM_OVERSAMPLE, Shape, ShapeKind, Snap, TRACK_RATE_HZ, Track,
47    band_envelope, cmndf_period, fold, scan_range, shape, snap, snap_scan,
48};
49pub use peak::{Peak, interpolate, local_maxima, strongest_peak};
50pub use realfft::num_complex::Complex64;
51pub use stft::{Padding, Stft, StftError, StftParams};
52pub use window::Window;