Audiofeatures¶
Auto-generated documentation for musicalgestures._audiofeatures module.
Scipy-only audio feature extraction for sound--motion analysis.
- Mgt-python / Modules / Musicalgestures / Audiofeatures
RMS envelopes, spectral-flux and energy-based onset detection, T60-style backward-decay reverberation time, and attack spectral centroid.
These functions are independent of the MgAudio class and operate on plain
numpy waveforms (y, sr), so they can be used on any mono audio array.
They complement the librosa-based, figure-producing methods of MgAudio
with lightweight numeric outputs. All onset detectors use the canonical
peak-picker (musicalgestures.pick_peaks).
Sources: cymbal-comparison study and Westney-comparisons study (Jensenius).
attack_spectral_centroid¶
Attack spectral centroid: the energy-weighted mean STFT spectral
centroid over the first attack seconds after the RMS-envelope peak.
Discriminates, e.g., strike placement and damping on a cymbal.
The constants (120 ms attack, 2048-sample Hann window, 512 hop) are PROVISIONAL defaults reimplemented from the cymbal-comparison paper's method description.
Source: cymbal-comparison study (Jensenius).
Arguments¶
ynp.ndarray - Mono waveform.srint - Sampling rate (Hz).attackfloat, optional - Analysis span after the envelope peak (s). Defaults to 0.12.npersegint, optional - STFT window length in samples. Defaults to 2048.hopint, optional - STFT hop in samples. Defaults to 512.windowfloat, optional - RMS window length (s) used to locate the envelope peak. Defaults to 0.02.
Returns¶
float- The attack spectral centroid in Hz (NaN if the attack segment is too short to analyse).
energy_onsets¶
Energy-based onset times: the RMS envelope's half-wave-rectified first difference is peak-picked (canonical peak-picker) at a threshold relative to the per-file peak, with a minimum inter-onset interval.
Reliable for discrete strokes; over-fragments sustained rolls/tremolo and can trigger on near-noise material. The default constants (0.15 x peak, 0.06 s) are PROVISIONAL defaults reimplemented from the cymbal-comparison paper's method description.
Source: cymbal-comparison study (Jensenius).
Arguments¶
ynp.ndarray - Mono waveform.srint - Sampling rate (Hz).windowfloat, optional - RMS window length (s). Defaults to 0.02.rel_thresholdfloat, optional - Threshold as a fraction of the onset-function's peak. Defaults to 0.15.min_intervalfloat, optional - Minimum inter-onset interval (s). Defaults to 0.06.
Returns¶
np.ndarray- Onset times in seconds.
rms_envelope¶
RMS energy envelope over consecutive, non-overlapping windows.
Source: cymbal-comparison study (Jensenius); also the Westney-comparisons study's high-rate sync envelope.
Arguments¶
ynp.ndarray - Mono waveform.srint - Sampling rate (Hz).windowfloat, optional - Window length in seconds. Defaults to 0.02.
Returns¶
tuple-(env, rate)whereenvis the RMS envelope (one value per window) andrateits sampling rate (1 /windowHz).
spectral_flux¶
Spectral-flux onset-detection function: the positive first difference of the STFT magnitude, summed over frequency and normalized to a maximum of 1. Rises sharply at note/percussion onsets.
Source: Westney-comparisons study (Jensenius).
Arguments¶
ynp.ndarray - Mono waveform.srint - Sampling rate (Hz).npersegint, optional - STFT window length in samples. Defaults to 2048.noverlapint, optional - STFT window overlap in samples. Defaults to 1536.
Returns¶
tuple-(flux, times)wherefluxis the onset-detection function andtimesare its frame times in seconds (frame ratesr / (nperseg - noverlap)).
spectral_flux_onsets¶
Onset times from the spectral-flux onset-detection function (see spectral_flux), peak-picked with the canonical peak-picker. By default the threshold adapts to the signal as mean + 1 standard deviation of the flux, following the source study.
Source: Westney-comparisons study (Jensenius).
Arguments¶
ynp.ndarray - Mono waveform.srint - Sampling rate (Hz).npersegint, optional - STFT window length in samples. Defaults to 2048.noverlapint, optional - STFT window overlap in samples. Defaults to 1536.thresholdfloat, optional - Absolute flux threshold (the flux has maximum 1). Defaults to None, which uses mean + std of the flux.min_intervalfloat, optional - Minimum inter-onset interval (s). Defaults to 0.05.
Returns¶
np.ndarray- Onset times in seconds.
t60_backward_decay¶
T60-style reverberation time by an ISO-3382-inspired level-span
regression on the RMS envelope (without Schroeder backward
integration): the RMS envelope is converted to dB relative to its peak;
from the peak the decay is followed (stopping if the envelope re-rises
by more than rerise_db dB, marking a new onset), and T60 is estimated
by linear regression of the dB curve over the first available level
span -- by default -5 to -35 dB (a T30 measure, extrapolated x2),
falling back to -5 to -25 dB (T20, x3) when the deeper level is not
reached.
The constants (20 ms window, -5/-35 with -5/-25 fallback, 6 dB re-rise stop) are PROVISIONAL defaults reimplemented from the cymbal-comparison paper's method description.
Source: cymbal-comparison study (Jensenius) -- instrument decay of damped vs undamped cymbal strokes.
Arguments¶
ynp.ndarray - Mono waveform of a decaying event (analysis starts at the envelope peak).srint - Sampling rate (Hz).windowfloat, optional - RMS window length (s). Defaults to 0.02.spanstuple, optional - Level spans (dB re. peak) to try in order, each a(top, bottom)pair. Defaults to ((-5, -35), (-5, -25)).rerise_dbfloat, optional - Stop following the decay when the envelope re-rises this many dB above its running minimum. Defaults to 6.0.
Returns¶
tuple-(t60, span)wheret60is the estimated reverberation time in seconds (NaN if no span was usable) andspanis the(top, bottom)pair actually used (None if none).