Expand description
The signal core that every estimator uses.
It holds windows, the STFT, peak picking, active frames with their statistics, the analytic signal, decay fits, the stem descriptors, the modulation spectrum and the Lomb-Scargle periodogram.
Conventions that bind every estimator:
- Samples and spectra are
f64at the stem’s native rate. - The window is the periodic Hann,
w[n] = 0.5 - 0.5 cos(2 pi n / N). - Frames are centred and zero-padded, with hop
N/4. The layer choosesNfrom the median f0 of the note list: 8192 below 100 Hz, else 4096. A Hann main lobe is about 4 bins wide, so harmonicsf0apart needN >= 4 fs / f0. - A frame is active when its RMS lies within 40 dB of the loudest frame. Statistics over active frames are the median and the interquartile range, which resist outliers.
- The transforms are not normalised; the caller scales.
Structs§
- Active
Frames - The frames that carry signal: frame RMS within a gate of the loudest frame. Digital silence has no active frame.
- Analytic
Signal - The analytic signal
z = x + j H{x}of a real signal. - Band
Share - The share of power in one band.
- Baseband
- One partial moved to baseband: complex samples at a reduced rate.
- Decay
- The decay of one tail: the noise floor and a decay time per fit range.
- Descriptors
- The descriptors of a stem.
- Filter
Error - A filter cutoff that the sample rate cannot carry.
- Frame
Descriptors - The descriptors of one frame.
- Heterodyne
Params - Settings of a band-pass heterodyne.
- Modulation
Spectrum - The magnitude spectrum of a detrended, Hann-windowed track, zero-padded
8x. Its resolution stays
1 / T; the padding samples it finer. - Peak
- A spectral peak with its interpolated position.
- Shape
- The shape of a folded cycle.
- Snap
- A rate snapped to the nearest note division.
- Stats
- The median and the interquartile range of a value over active frames, in its unit type.
- Stft
- A planned STFT. It computes one frame at a time into a buffer it owns, so a long stem never holds its whole spectrogram in memory.
- Stft
Params - The frame layout of an STFT: frame length
N, hop, window, padding and FFT oversampling. - Summary
- The median and the interquartile range of a set of values.
- Track
- A time series at its own rate, such as a band envelope.
Enums§
- Decay
Failure - Why a decay fit has no value.
- FitRange
- The level range of a decay fit, in decibels below the start of the energy decay curve.
- Padding
- How a centred frame continues past either end of the signal.
- Shape
Kind - The coarse shape of a folded cycle. A sine and a triangle are never told apart.
- Stft
Error - STFT parameters that cannot work.
- Window
- An analysis window. Every window is periodic: its
Nsamples are the firstNof a symmetric window of lengthN + 1, as spectral analysis expects. The symmetric form shifts every bin slightly.
Constants§
- ACTIVE_
GATE_ DB - The gate of the project’s convention: a frame is active when its RMS lies within 40 dB of the loudest frame.
- ATTACK_
LOW_ PASS_ HZ - The default low-pass for an attack envelope. A 5 Hz smoother smears any attack shorter than tens of milliseconds; 100 to 200 Hz keeps it.
- BAND_
CONVENTION - The convention of the band shares.
- BAND_
EDGES_ HZ - The band edges of the band shares in hertz. The edges are a project choice.
- BPM_
SCAN - The tempo scan of the snap, as a share of the BPM on either side.
- FLATNESS_
CONVENTION - The convention of the flatness.
- FLATNESS_
FLOOR - The flatness floor, applied after the window-sum scale.
- FOLD_
BINS - The bins of a folded cycle.
- GRID_
STEP_ HZ - The step of the trial frequencies.
- LEVEL_
CONVENTION - The convention of the levels.
- LINE_
PROMINENCE - How many times above the median amplitude of the scan a rate line must stand.
- MIN_
ACTIVE_ FRAMES - The fewest active frames a statistic over frames needs; with fewer it gives no estimate.
- MIN_
CYCLES - A rate needs this many full cycles in the span. A pure count, so a
bare
f64. - MIN_
LINE_ DEPTH - A rate line needs at least this relative depth: the amplitude of its sine in the log track, about the share by which the level swings.
- SCAN_
BOTTOM_ HZ - The bottom of the modulation scan unless the 4-bar rate lies lower.
- SCAN_
TOP_ HZ - The top of the modulation scan. Above it a modulation leaves the envelope domain and shows as sidebands.
- SETTLE_
S - The settling time after an onset whose samples are left out.
- SHAPE_
CONVENTION - The convention of the shape descriptors.
- SPECTRUM_
OVERSAMPLE - Zero padding of the modulation spectrum.
- TRACK_
RATE_ HZ - The rate of envelope tracks: a 5 ms hop, Nyquist at 100 Hz.
Functions§
- am_
depth - The modulation depth of an envelope,
(max - min) / (max + min). ReturnsNonefor an empty or all-zero envelope. - backward_
integral - The Schroeder integral of an energy sequence: element
nis the sum fromnto the end. Summed backward, so the small late terms add first. - band_
envelope - The envelope of one band at 200 Hz:
band_magnitude, then the mean of each 5 ms block. - band_
magnitude - The envelope of the band from
lotohi. - band_
pass_ zero_ phase - Band-passes a signal with a fourth-order Butterworth high-pass at
loand low-pass athi, each run forward and backward, so the band has no delay. - cmndf_
period - The period of a track between
1 / hiand1 / lo. - describe
- Computes the descriptors of a mono signal.
- fold
- Folds a track over a period into 64 bins: bin
bis the mean of the samples whose phase falls in[b / 64, (b + 1) / 64). The result is one cycle of the waveform. - frame_
descriptors - Computes the descriptors of one magnitude frame, already divided by the
window sum, with bins
bin_hzapart. ReturnsNonefor an all-zero frame, or for one with a negative, NaN or infinite magnitude. - frame_
rms - Returns the RMS of each centred frame of an STFT layout, over the raw
samples (no window) with the layout’s padding. Frame
mlines up with STFT framem. - gated_
samples - The samples of a level track that a modulation estimate may use: level
within 40 dB of the track’s peak, inside a note, and at least
settleafter the note’s onset. - grid
- The trial frequencies from
lotohiin 0.01 Hz steps. - heterodyne
- Moves the band around
centreto baseband, so a tone atf_c + dcomes out atd. - interpolate
- Interpolates the local maximum at bin
kof a magnitude spectrum. - local_
maxima - Returns the bins of the strict local maxima of a magnitude spectrum, skipping the first and the last bin.
- lomb_
scargle - The periodogram of
valuesattimes, one power per frequency. - low_
pass_ zero_ phase - Low-passes a signal forward and then backward with a fourth-order
Butterworth, so the result has no delay: an attack stays where it is.
For attack envelopes use
ATTACK_LOW_PASS_HZ. - periodogram_
rate - The modulation rate of irregular samples between
loandhi. - quantile
- The linear quantile of sorted values, the default of
numpy.quantile. ReturnsNonefor no values. - scan_
range - The scan range at a tempo: from two semitones below
min(0.2 Hz, the 4-bar rate)to 20 Hz. - shape
- Reads the shape of a folded cycle, or
Nonefor a flat one. - snap
- Snaps a rate to the nearest division at a tempo, in log distance.
- snap_
scan - Snaps a rate at the BPM and at tempos within 2 % of it, in 0.1 % steps, and returns the snap with the smallest residual. A drifting tempo shows as a best BPM away from the nominal one.
- strongest_
peak - Returns the interpolated peak with the largest magnitude between bins
loandhiinclusive, orNonewhen the range holds no local maximum.
Type Aliases§
- Complex64
- Alias for a
Complex<f64>