Skip to content

librosa equivalence

tests/test_librosa_parity.py compares these features with librosa. The spectral shape, mel, MFCC and chroma features run at four framings: 22.05 kHz with n_fft 2048 / hop 512, centered and not, and 16 kHz with 400 / 160 uncentered and 512 / 128 centered. tonnetz and onset_strength run centered at 22.05 kHz with 2048 / 512, 1024 / 256 and 512 / 128. zcr and rms_energy run at 16 kHz with frame / hop of 2048 / 512, 400 / 160, 512 / 512 and 401 / 100, centered and not. Agreement is to float32 precision or better.

AFX feature librosa call
spectral_centroid feature.spectral_centroid
spectral_bandwidth feature.spectral_bandwidth
spectral_rolloff feature.spectral_rolloff
spectral_flatness feature.spectral_flatness
spectral_contrast feature.spectral_contrast
melspectrogram feature.melspectrogram(pad_mode='constant')
mfcc feature.mfcc(pad_mode='constant')
mfcc_delta, mfcc_delta_delta feature.delta(mfcc, order=1 / 2)
chroma_stft feature.chroma_stft(tuning=0.0)
tonnetz feature.tonnetz(chroma=feature.chroma_stft(tuning=0.0))
onset_strength onset.onset_strength
zcr feature.zero_crossing_rate
rms_energy (framed) feature.rms

Use the same n_fft/frame_size, hop_length and center on both sides. librosa pads centered frames with zeros (pad_mode='constant') since 0.10, older versions reflected; zcr repeats the edge samples on both sides, as librosa.feature.zero_crossing_rate does.

Differences

pitch agrees with librosa.yin(pad_mode='constant') to within 1% on voiced frames with librosa 0.11 or later. librosa 0.10 reads about 1.2% lower and can be far off on the first, half zero-padded frame. AFX returns NaN for frames without a clear periodicity dip, where librosa always reports its best lag, which can be anywhere in the range (about fmax on silence).

chroma_stft takes the tuning as a parameter (default 0, A440). librosa estimates it from the signal when tuning is not given, which shifts the filterbank on detuned recordings.

cqt and chroma_cqt are computed from the STFT through a triangular log-frequency filterbank. They have the time resolution of the STFT at every frequency and do not match librosa.cqt, which uses true constant-Q filters.

spectral_flux is the Euclidean distance between consecutive magnitude spectra, not librosa's onset strength.