Caution
You're reading an old version of this documentation. If you want up-to-date information, please have a look at 0.10.2.
librosa.onset.onset_strength_multi
- librosa.onset.onset_strength_multi(y=None, sr=22050, S=None, n_fft=2048, hop_length=512, lag=1, max_size=1, ref=None, detrend=False, center=True, feature=None, aggregate=None, channels=None, **kwargs)[source]
Compute a spectral flux onset strength envelope across multiple channels.
Onset strength for channel
i
at timet
is determined by:mean_{f in channels[i]} max(0, S[f, t+1] - S[f, t])
- Parameters:
- ynp.ndarray [shape=(n,)]
audio time-series
- srnumber > 0 [scalar]
sampling rate of
y
- Snp.ndarray [shape=(d, m)]
pre-computed (log-power) spectrogram
- n_fftint > 0 [scalar]
FFT window size for use in
feature()
ifS
is not provided.- hop_lengthint > 0 [scalar]
hop length for use in
feature()
ifS
is not provided.- lagint > 0
time lag for computing differences
- max_sizeint > 0
size (in frequency bins) of the local max filter. set to 1 to disable filtering.
- refNone or np.ndarray [shape=(d, m)]
An optional pre-computed reference spectrum, of the same shape as
S
. If not provided, it will be computed fromS
. If provided, it will override any local max filtering governed bymax_size
.- detrendbool [scalar]
Filter the onset strength to remove the DC component
- centerbool [scalar]
Shift the onset function by
n_fft // (2 * hop_length)
frames. This corresponds to using a centered frame analysis in the short-time Fourier transform.- featurefunction
Function for computing time-series features, eg, scaled spectrograms. By default, uses
librosa.feature.melspectrogram
withfmax=11025.0
Must support arguments:
y, sr, n_fft, hop_length
- aggregatefunction or False
Aggregation function to use when combining onsets at different frequency bins.
If
False
, then no aggregation is performed.Default:
np.mean
- channelslist or None
Array of channel boundaries or slice objects. If None, then a single channel is generated to span all bands.
- kwargsadditional keyword arguments
Additional parameters to
feature()
, ifS
is not provided.
- Returns:
- onset_envelopenp.ndarray [shape=(n_channels, m)]
array containing the onset strength envelope for each specified channel
- Raises:
- ParameterError
if neither
(y, sr)
norS
are provided
See also
Notes
This function caches at level 30.
Examples
First, load some audio and plot the spectrogram
>>> import matplotlib.pyplot as plt >>> y, sr = librosa.load(librosa.ex('choice'), duration=5) >>> D = np.abs(librosa.stft(y)) >>> fig, ax = plt.subplots(nrows=2, sharex=True) >>> img1 = librosa.display.specshow(librosa.amplitude_to_db(D, ref=np.max), ... y_axis='log', x_axis='time', ax=ax[0]) >>> ax[0].set(title='Power spectrogram') >>> ax[0].label_outer() >>> fig.colorbar(img1, ax=[ax[0]], format="%+2.f dB")
Construct a standard onset function over four sub-bands
>>> onset_subbands = librosa.onset.onset_strength_multi(y=y, sr=sr, ... channels=[0, 32, 64, 96, 128]) >>> img2 = librosa.display.specshow(onset_subbands, x_axis='time', ax=ax[1]) >>> ax[1].set(ylabel='Sub-bands', title='Sub-band onset strength') >>> fig.colorbar(img2, ax=[ax[1]])