librosa.onset.onset_strength_multi

librosa.onset.onset_strength_multi(y=None, sr=22050, S=None, lag=1, max_size=1, 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 time t is determined by:

mean_{f in channels[i]} max(0, S[f, t+1] - S[f, t])

Parameters:
y : np.ndarray [shape=(n,)]

audio time-series

sr : number > 0 [scalar]

sampling rate of y

S : np.ndarray [shape=(d, m)]

pre-computed (log-power) spectrogram

lag : int > 0

time lag for computing differences

max_size : int > 0

size (in frequency bins) of the local max filter. set to 1 to disable filtering.

detrend : bool [scalar]

Filter the onset strength to remove the DC component

center : bool [scalar]

Shift the onset function by n_fft / (2 * hop_length) frames

feature : function

Function for computing time-series features, eg, scaled spectrograms. By default, uses librosa.feature.melspectrogram with fmax=11025.0

aggregate : function

Aggregation function to use when combining onsets at different frequency bins.

Default: np.mean

channels : list or None

Array of channel boundaries or slice objects. If None, then a single channel is generated to span all bands.

kwargs : additional keyword arguments

Additional parameters to feature(), if S is not provided.

Returns:
onset_envelope : np.ndarray [shape=(n_channels, m)]

array containing the onset strength envelope for each specified channel

Raises:
ParameterError

if neither (y, sr) nor S are provided

See also

onset_strength

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.util.example_audio_file(),
...                      duration=10.0)
>>> D = librosa.stft(y)
>>> plt.figure()
>>> plt.subplot(2, 1, 1)
>>> librosa.display.specshow(librosa.amplitude_to_db(D, ref=np.max),
...                          y_axis='log')
>>> plt.title('Power spectrogram')

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])
>>> plt.subplot(2, 1, 2)
>>> librosa.display.specshow(onset_subbands, x_axis='time')
>>> plt.ylabel('Sub-bands')
>>> plt.title('Sub-band onset strength')

(Source code)

../_images/librosa-onset-onset_strength_multi-1.png