Rhythm: Onsets, Tempo and Beats
Rhythm analysis as AudioSamples methods that start from audio, and as free
functions in audio_samples.rhythm that take precomputed inputs (a
spectrogram S, an onset_envelope or a tempogram tg).
Onsets:
onset_strength,onset_strength_multi,onset_detect(methods and functions);rhythm.onset_backtrack,rhythm.peak_pick.Tempograms and tempo:
tempogram,fourier_tempogram,hybrid_tempogram,tempogram_ratio,tempo(methods and functions);rhythm.metrogram,rhythm.tempo_frequencies,rhythm.fourier_tempo_frequencies.Beats:
beat_trackandplp(methods and functions);rhythm.beat_track_with_bpmtracks beats at a given tempo.
Shapes: the AudioSamples methods always return a leading channel axis
((channels, n_frames) envelopes, (channels, F, T) tempograms); index
[0] for mono audio. Event detectors need mono audio and return 1-D int64
frames/samples or float64 times. beat_track returns (tempo, beats).
Event output is sparse only (sparse=False raises); custom
tempogram_ratio(freqs=...) and non-linear kind are not supported;
onset_backtrack with no events returns an empty array.
beat_track defaults to trim=False.
Rhythm analysis over NumPy arrays (onset strength and detection, peak picking, tempograms, tempo, beat tracking, PLP). float32 / complex64 arrays are processed in float32 and give float32 output; any other input is converted to float64.
AudioSamples methods
- AudioSamples.onset_strength(*, lag=1, max_size=1, detrend=False, center=True, aggregate=None, n_fft=2048, hop_length=512, win_length=None, window='hann', pad_mode='constant', power=2.0, n_mels=128, fmin=0.0, fmax=None, htk=False, norm='slaney')
Onset strength envelope of every channel.
The envelope is the aggregated positive increase of the log-power mel spectrogram (
power_to_dbwithref=1,top_db=80) from framet - lagtot.- Parameters:
lag (int) – Time lag of the difference in frames. Default 1.
max_size (int) – Maximum filter across frequency on the reference (SuperFlux); 1 disables it. Default 1.
detrend (bool) – High-pass filter the envelope. Default False.
center (bool) – Compensate the centred-STFT delay. Default True.
aggregate – Reduction across mel bins: None (mean),
numpy.mean,numpy.median,numpy.max,numpy.min,numpy.sum, a name, or a callablef(x, axis=-1).n_fft (int) – Default 2048.
hop_length (int) – Default 512.
win_length – Mel spectrogram parameters, as
melspectrogram.window – Mel spectrogram parameters, as
melspectrogram.pad_mode – Mel spectrogram parameters, as
melspectrogram.power – Mel spectrogram parameters, as
melspectrogram.n_mels – Mel spectrogram parameters, as
melspectrogram.fmin – Mel spectrogram parameters, as
melspectrogram.fmax – Mel spectrogram parameters, as
melspectrogram.htk – Mel spectrogram parameters, as
melspectrogram.norm – Mel spectrogram parameters, as
melspectrogram.
- Returns:
shape
(channels, n_frames)withn_frames = 1 + len // hop_length; index[0]for the(n_frames,)envelope of mono audio.- Return type:
numpy.ndarray[float32 | float64]
- Raises:
ValueError – For invalid parameters.
- AudioSamples.onset_strength_multi(*, channels=None, lag=1, max_size=1, detrend=False, center=True, aggregate=None, n_fft=2048, hop_length=512, win_length=None, window='hann', pad_mode='constant', power=2.0, n_mels=128, fmin=0.0, fmax=None, htk=False, norm='slaney')
Multi-band onset strength of every channel: one envelope per group of mel bands.
- Parameters:
channels (Optional[Sequence[int] | Sequence[slice]]) – Sub-band boundaries in mel bins: values above
n_melsare dropped, the rest sorted and de-duplicated, each consecutive pair is one band. Or one slice of the mel bins per band, in any order. None gives one band.aggregate – As
onset_strength;Falsekeeps every mel bin.**kwargs –
lag,max_size,detrend,center,n_fft,hop_length,win_length,window,pad_mode,power,n_mels,fmin,fmax,htk,normasonset_strength.
- Returns:
shape
(channels, n_bands, n_frames)(n_melsrows withaggregate=False); index[0]for the(n_bands, n_frames)array of mono audio.- Return type:
numpy.ndarray[float32 | float64]
- Raises:
ValueError – For invalid parameters or boundaries.
- AudioSamples.onset_detect(*, hop_length=512, backtrack=False, energy=None, units='frames', normalize=True, sparse=True, pre_max=None, post_max=None, pre_avg=None, post_avg=None, delta=None, wait=None, method='greedy')
Detects onsets by peak picking on the onset strength envelope.
The default onset envelope (
onset_strength(hop_length=hop_length)) is normalised to[0, 1], peak-picked and optionally backtracked.- Parameters:
hop_length (int) – Hop of the onset envelope. Default 512.
backtrack (bool) – Move onsets back to the preceding local minimum of
energy. Default False.energy (Optional[array_like]) – 1-D function to backtrack on (one value per frame); None uses the normalised envelope.
units (str) –
"frames"(default),"samples"or"time".normalize (bool) – Scale the envelope to
[0, 1]. Default True.sparse (bool) – Must be True.
pre_max (Optional[int])
post_max (Optional[int])
pre_avg (Optional[int])
post_avg (Optional[int])
wait (Optional[int])
delta (Optional[float]), method (str) – Peak-picking parameters (see
rhythm.peak_pick); None derives the value from the frame rate (30 ms / 100 ms windows,delta=0.07).
- Returns:
1-D onset frames or samples (int64), or times (float64).
- Return type:
- Raises:
ValueError – For multi-channel audio, invalid parameters or
sparse=False.
- AudioSamples.tempogram(*, hop_length=512, win_length=384, center=True, window='hann', norm=inf)
Autocorrelation tempogram of every channel.
- Parameters:
hop_length (int) – Hop of the onset envelope. Default 512.
win_length (int) – Autocorrelation window (lag bins). Default 384.
center (bool) – Centre the windows. Default True.
window – Window before the autocorrelation. Default
"hann".norm (Optional[float]) – Column normalisation (
numpy.infdefault, a p-norm, or None).
- Returns:
shape
(channels, win_length, n_frames); index[0]for the 2-D array of mono audio.- Return type:
numpy.ndarray[float32 | float64]
- Raises:
ValueError – For invalid parameters.
- AudioSamples.fourier_tempogram(*, hop_length=512, win_length=384, center=True, window='hann')
Fourier tempogram of every channel.
- Parameters:
- Returns:
shape
(channels, win_length // 2 + 1, n_frames + 1)(centred); index[0]for the 2-D array of mono audio.- Return type:
numpy.ndarray[complex64 | complex128]
- AudioSamples.tempo(*, hop_length=512, start_bpm=120, std_bpm=1.0, ac_size=8.0, max_tempo=320.0, aggregate='mean', prior=None)
Estimates the tempo of every channel in BPM.
- Parameters:
hop_length (int) – Hop of the onset envelope. Default 512.
start_bpm (float) – Prior centre. Default 120.
std_bpm (float) – Prior spread in octaves. Default 1.
ac_size (float) – Autocorrelation window in seconds. Default 8.
max_tempo (Optional[float]) – Exclude tempi at or above this. Default 320.
aggregate – Reduction over time (default
numpy.mean); None gives one tempo per frame.prior – None (log-normal), a
scipy.statsdistribution or a callable of the BPM returning a log-density.
- Returns:
shape
(channels, 1)((channels, n_frames)withaggregate=None); index[0]for the(1,)array of mono audio.- Return type:
numpy.ndarray[float64]
- Raises:
ValueError – For invalid parameters.
- AudioSamples.beat_track(*, hop_length=512, start_bpm=120.0, tightness=100, trim=False, bpm=None, prior=None, units='frames', sparse=True)
Tracks beats with the dynamic-programming beat tracker.
The onset envelope is
onset_strength(hop_length=hop_length, aggregate=numpy.median).- Parameters:
hop_length (int) – Hop of the onset envelope. Default 512.
start_bpm (float) – Prior centre of the tempo estimate. Default 120.
tightness (float) – Tempo-consistency weight. Default 100.
trim (bool) – Remove weak leading/trailing beats. Default False.
bpm (Optional[float | array_like]) – Tempo to track at (one value or one per frame); None estimates it.
prior – Tempo prior (see
tempo).units (str) –
"frames"(default),"samples"or"time".sparse (bool) – Must be True.
- Returns:
(tempo, beats):tempois the estimate as a float64 array of shape(1,)(bpmunchanged when given,0.0for silence);beatsis a 1-D int64 (frames/samples) or float64 (time) array.- Return type:
- Raises:
ValueError – For multi-channel audio, invalid parameters or
sparse=False.
- AudioSamples.plp(*, hop_length=512, win_length=384, tempo_min=30, tempo_max=300, prior=None)
Predominant local pulse of every channel.
- Parameters:
hop_length (int) – Hop of the (median-aggregated) onset envelope. Default 512.
win_length (int) – Fourier tempogram window in frames. Default 384.
tempo_min (Optional[float]) – Lowest tempo (BPM). Default 30.
tempo_max (Optional[float]) – Highest tempo (BPM). Default 300.
prior – Tempo prior (see
tempo).
- Returns:
shape
(channels, n_frames), values in[0, 1]; index[0]for the(n_frames,)array of mono audio.- Return type:
numpy.ndarray[float32 | float64]
- Raises:
ValueError – If
tempo_max <= tempo_minor parameters are invalid.
- AudioSamples.tempogram_ratio(*, hop_length=512, win_length=384, start_bpm=120, std_bpm=1.0, max_tempo=320.0, factors=None, aggregate=None, prior=None, center=True, window='hann', fill_value=0, norm=inf)
Tempogram ratio features of every channel: the tempogram sampled at fixed multiples of the per-frame tempo estimate.
- Parameters:
hop_length (int) – Hop of the onset envelope. Default 512.
win_length – Tempogram parameters (as
tempogram).center – Tempogram parameters (as
tempogram).window – Tempogram parameters (as
tempogram).norm – Tempogram parameters (as
tempogram).start_bpm – Per-frame tempo estimation (as
tempo).std_bpm – Per-frame tempo estimation (as
tempo).max_tempo – Per-frame tempo estimation (as
tempo).prior – Per-frame tempo estimation (as
tempo).factors (Optional[array_like]) – Tempo multiples; None uses the 13 default factors.
aggregate – Optional reduction over time (default None).
fill_value (float) – Value outside the tempogram range. Default 0.
- Returns:
shape
(channels, n_factors, n_frames), or(channels, n_factors, 1)when aggregated (the time axis is kept); index[0]for the array of mono audio.- Return type:
numpy.ndarray[float32 | float64]
- AudioSamples.hybrid_tempogram(*, hop_length=512, win_length=384, center=True, window='hann')
Hybrid tempogram of every channel: the Fourier and autocorrelation tempograms combined on the Fourier tempo grid.
- Parameters:
- Returns:
shape
(channels, win_length // 2 + 1, n_frames)on thefourier_tempo_frequenciesgrid; index[0]for the 2-D array of mono audio.- Return type:
numpy.ndarray[float32 | float64]
Onsets
- audio_samples.rhythm.onset_strength(*, S, sr, lag=1, max_size=1, ref=None, detrend=False, center=True, aggregate=None, n_fft=2048, hop_length=512)
Onset strength of a log-power spectrogram: positive differences between frames, aggregated across bins.
Sis used as given (compute it withspectral.power_to_dbof a mel spectrogram, or useAudioSamples.onset_strength).- Parameters:
S (array_like) – Log-power spectrogram, shape
(n_bins, n_frames)or(channels, n_bins, n_frames).sr (float) – Required. Unused (
Sis already computed).lag (int) – Time lag of the difference in frames. Default 1.
max_size (int) – Size of the maximum filter across frequency applied to the reference (SuperFlux); 1 disables it. Default 1.
ref (Optional[array_like]) – Reference spectrogram of the same shape as
S; None usesS(maximum-filtered whenmax_size > 1).detrend (bool) – High-pass filter the envelope. Default False.
center (bool) – Shift by
n_fft // (2 * hop_length)frames to undo the centred-STFT delay. Default True.aggregate – Reduction across bins: None (mean),
numpy.mean,numpy.median,numpy.max,numpy.min,numpy.sum, a name, or a callablef(x, axis=-1).Falsereturns the first bin’s flux.n_fft (int) – FFT size behind
S(centring shift). Default 2048.hop_length (int) – Hop behind
S(centring shift). Default 512.
- Returns:
shape
(n_frames,)for 2-DS,(channels, n_frames)for 3-D.- Return type:
numpy.ndarray[float32 | float64]
- Raises:
ValueError – For invalid parameters or an empty spectrogram.
- audio_samples.rhythm.onset_strength_multi(*, S, sr, n_fft=2048, hop_length=512, lag=1, max_size=1, ref=None, detrend=False, center=True, aggregate=None, channels=None)
Multi-band onset strength of a precomputed spectrogram: one envelope per group of bins.
- Parameters:
S (array_like) – Log-power spectrogram
(n_bins, n_frames)or(channels, n_bins, n_frames), used as given.sr (float) – Required. Unused (see
onset_strength).n_fft (int) – FFT size behind
S(centring shift). Default 2048.hop_length (int) – Hop behind
S(centring shift). Default 512.lag – As
onset_strength.max_size – As
onset_strength.ref – As
onset_strength.detrend – As
onset_strength.center – As
onset_strength.aggregate – As
onset_strength;Falsekeeps every bin.channels (Optional[Sequence[int] | Sequence[slice]]) – Sub-band boundaries in bins: values above
n_binsare dropped, the rest sorted and de-duplicated, and each consecutive pair is one band. Or one slice of the bins per band, in any order. None gives one band.
- Returns:
shape
(n_bands, n_frames)for 2-DS,(channels, n_bands, n_frames)for 3-D.- Return type:
numpy.ndarray[float32 | float64]
- Raises:
ValueError – For invalid parameters or boundaries.
- audio_samples.rhythm.onset_detect(*, onset_envelope, sr, hop_length=512, backtrack=False, energy=None, units='frames', normalize=True, sparse=True, pre_max=None, post_max=None, pre_avg=None, post_avg=None, delta=None, wait=None, method='greedy')
Detects onsets by peak picking on a precomputed onset strength envelope.
The envelope is normalised to
[0, 1](normalize=True), peak-picked with the parameters below (defaults derived from the frame rate: 30 mspre_maxandwait, 100 ms averaging windows,delta=0.07) and optionally backtracked.- Parameters:
onset_envelope (array_like) – 1-D onset strength envelope.
sr (float) – Sampling rate of the analysed audio. Required.
hop_length (int) – Hop of the envelope in samples. Default 512.
backtrack (bool) – Move onsets back to the preceding local minimum of
energy. Default False.energy (Optional[array_like]) – 1-D function to backtrack on; None uses the (normalised) envelope.
units (str) –
"frames"(default),"samples"or"time".normalize (bool) – Scale the envelope to
[0, 1]first. Default True.sparse (bool) – Must be True.
pre_max (Optional[int])
post_max (Optional[int])
pre_avg (Optional[int])
post_avg (Optional[int])
wait (Optional[int])
delta (Optional[float]), method (str) – Peak-picking parameters (see
peak_pick); None derives the value from the frame rate.
- Returns:
onset frames or samples (int64), or times (float64).
- Return type:
- Raises:
ValueError – For invalid parameters, a 2-D envelope or
sparse=False.
- audio_samples.rhythm.onset_backtrack(events, energy)
Moves events back to the preceding local minimum of
energy.- Parameters:
events (array_like) – Event frame indices (non-negative integers).
energy (array_like) – 1-D function to search for minima (onset envelope or RMS energy).
- Returns:
one backtracked frame per event. An empty
eventsgives an empty array.- Return type:
numpy.ndarray[int64]
- audio_samples.rhythm.peak_pick(x, *, pre_max, post_max, pre_avg, post_avg, delta, wait, sparse=True, method='greedy', axis=-1)
Picks peaks against a local maximum and a local mean threshold (1-D input, sparse output only).
A sample
nis a peak ifx[n] == max(x[n - pre_max : n + post_max]),x[n] >= mean(x[n - pre_avg : n + post_avg]) + deltaand (greedy method) it is more thanwaitsamples after the previous peak.- Parameters:
x (array_like) – 1-D finite signal.
pre_max (int) – Window extents in samples (
post_maxandpost_avgat least 1).post_max (int) – Window extents in samples (
post_maxandpost_avgat least 1).pre_avg (int) – Window extents in samples (
post_maxandpost_avgat least 1).post_avg (int) – Window extents in samples (
post_maxandpost_avgat least 1).delta (float) – Threshold offset above the local mean (>= 0).
wait (int) – Minimum number of samples between peaks.
sparse (bool) – Must be True (indices are returned).
method (str) –
"greedy"(default),"dp_count"or"dp_value".axis (int) – Must be -1 (1-D input only).
- Returns:
ascending peak indices.
- Return type:
numpy.ndarray[int64]
- Raises:
ValueError – For invalid parameters, non-finite input or
sparse=False.
Tempograms and tempo
- audio_samples.rhythm.tempo_frequencies(n_bins, *, hop_length=512, sr)
Tempo (BPM) of each lag bin of an autocorrelation tempogram.
- Parameters:
- Returns:
shape
(n_bins,); bin 0 (zero lag) isinf.- Return type:
numpy.ndarray[float64]
- audio_samples.rhythm.fourier_tempo_frequencies(*, sr, win_length=384, hop_length=512)
Tempo (BPM) of each bin of a Fourier tempogram.
- Parameters:
- Returns:
shape
(win_length // 2 + 1,).- Return type:
numpy.ndarray[float64]
- audio_samples.rhythm.tempogram(*, onset_envelope, sr, hop_length=512, win_length=384, center=True, window='hann', norm=inf)
Autocorrelation tempogram: windowed autocorrelation of an onset strength envelope.
- Parameters:
onset_envelope (array_like) –
(n_frames,)or(channels, n_frames).sr (float) – Required. Unused (the envelope is already computed).
hop_length (int) – Unused (as above).
win_length (int) – Autocorrelation window in frames (number of lag bins). Default 384.
center (bool) – Centre the windows (linear-ramp padding). Default True.
window – Window applied before the autocorrelation. Default
"hann".norm (Optional[float]) – Column normalisation:
numpy.inf(default, divide by the maximum), a p-norm, or None.
- Returns:
shape
(win_length, n_frames)for 1-D input,(channels, win_length, n_frames)for 2-D (n_frames - win_length + 1frames when not centred).- Return type:
numpy.ndarray[float32 | float64]
- Raises:
ValueError – For invalid parameters or (uncentred) a too-short envelope.
- audio_samples.rhythm.fourier_tempogram(*, onset_envelope, sr, hop_length=512, win_length=384, center=True, window='hann')
Fourier tempogram: short-time Fourier transform of an onset strength envelope.
- Parameters:
onset_envelope (array_like) –
(n_frames,)or(channels, n_frames).sr – Unused (the envelope is already computed).
hop_length – Unused (the envelope is already computed).
win_length (int) – STFT length in frames. Default 384.
center (bool) – Centre the frames (zero padding). Default True.
window – Analysis window. Default
"hann".
- Returns:
shape
(win_length // 2 + 1, n_frames + 1)(centred) for 1-D input, with a leading channel axis for 2-D.- Return type:
numpy.ndarray[complex64 | complex128]
- audio_samples.rhythm.tempo(*, onset_envelope=None, tg=None, sr, hop_length=512, start_bpm=120, std_bpm=1.0, ac_size=8.0, max_tempo=320.0, aggregate='mean', prior=None)
Estimates the tempo in BPM from an onset envelope or a precomputed tempogram
tg.The tempo is the lag bin maximising
log1p(1e6 * tempogram) + log prior(default prior: log-normal aroundstart_bpmwithstd_bpmoctaves).- Parameters:
onset_envelope (Optional[array_like]) –
(n_frames,)or(channels, n_frames). Exactly one ofonset_envelope/tg.tg (Optional[array_like]) – Autocorrelation tempogram
(win_length, n_frames)or(channels, win_length, n_frames).sr (float) – Sampling rate. Required.
hop_length (int) – Hop in samples. Default 512.
start_bpm (float) – Prior centre. Default 120.
std_bpm (float) – Prior spread in octaves. Default 1.
ac_size (float) – Autocorrelation window in seconds (envelope input). Default 8.
max_tempo (Optional[float]) – Tempi at or above this are excluded. Default 320; None allows any.
aggregate – Reduction over time (default
numpy.mean); None estimates one tempo per frame.prior – None (log-normal default), a
scipy.statsdistribution (itslogpdfis used) or a callable of the BPM.
- Returns:
shape
(1,)(or(n_frames,)withaggregate=None) for 1-D input, with a leading channel axis for 2-D.- Return type:
numpy.ndarray[float64]
- Raises:
ValueError – For invalid parameters, or neither/both inputs given.
- audio_samples.rhythm.tempogram_ratio(*, onset_envelope=None, tg=None, bpm=None, sr, hop_length=512, win_length=384, start_bpm=120, std_bpm=1.0, max_tempo=320.0, freqs=None, factors=None, aggregate=None, prior=None, center=True, window='hann', kind='linear', fill_value=0, norm=inf)
Tempogram ratio features from an onset envelope or a precomputed tempogram
tg.The tempogram is sampled at
factorstimes the per-frame tempo estimate (Prockup et al. 2015).- Parameters:
onset_envelope (Optional[array_like]) –
(n_frames,)or(channels, n_frames); used to compute the tempogram whentgis None.tg (Optional[array_like]) – Autocorrelation tempogram
(win_length, n_frames)or(channels, win_length, n_frames).bpm (Optional[array_like]) – Per-frame tempo
(n_frames,)/(channels, n_frames); None estimates it from the tempogram.sr (float) – Sampling rate. Required.
hop_length (int) – Hop in samples. Default 512.
win_length – Tempogram parameters (envelope input).
center – Tempogram parameters (envelope input).
window – Tempogram parameters (envelope input).
norm – Tempogram parameters (envelope input).
start_bpm – Per-frame tempo estimation.
std_bpm – Per-frame tempo estimation.
max_tempo – Per-frame tempo estimation.
prior – Per-frame tempo estimation.
freqs – Must be None (the
tempo_frequenciesgrid is used).factors (Optional[array_like]) – Tempo multiples; None uses the 13 default factors.
aggregate – Optional reduction over time (default None).
kind (str) – Must be
"linear".fill_value (float) – Value outside the tempogram’s range. Default 0.
- Returns:
shape
(n_factors, n_frames)for 1-D input ((n_factors,)when aggregated), with a leading channel axis for 2-D.- Return type:
numpy.ndarray[float32 | float64]
- Raises:
ValueError – For invalid parameters, unsupported
freqs/kind, or neither input given.
- audio_samples.rhythm.hybrid_tempogram(*, onset_envelope, sr, hop_length=512, win_length=384, center=True, window='hann')
Hybrid tempogram: the Fourier and autocorrelation tempograms combined on the Fourier tempo grid.
- Parameters:
onset_envelope (array_like) –
(n_frames,)or(channels, n_frames).sr (float) – Sampling rate. Required.
hop_length (int) – Hop in samples. Default 512.
win_length (int) – Window of both tempograms in frames (>= 3). Default 384.
center (bool) – Centred frames. Default True.
window – Window of both tempograms. Default
"hann".
- Returns:
shape
(win_length // 2 + 1, n_frames)on thefourier_tempo_frequenciesgrid, with a leading channel axis for 2-D input.- Return type:
numpy.ndarray[float32 | float64]
- audio_samples.rhythm.metrogram(*, tg, freqs, factors=None, aggregate='sum', kind='linear', fill_value=0)
Metrogram (metrical subharmonic salience) of a tempogram: for each factor
h, the tempogram interpolated ath * freqs, multiplied by the tempogram and aggregated over the tempo axis.- Parameters:
tg (array_like) – Tempogram magnitude
(n_freqs, n_frames)or(channels, n_freqs, n_frames).freqs (array_like) – Tempo (BPM) of each bin; at least two finite values (drop the infinite zero-lag bin of
tempo_frequenciesfirst).factors (Optional[array_like]) – Subharmonic factors; None uses
[1/3, 1/4, 1/5, 1/7].aggregate – Reduction over the tempo axis (default
numpy.sum). None keeps every bin.kind (str) – Must be
"linear".fill_value (float) – Value outside the frequency grid. Default 0.
- Returns:
shape
(n_factors, n_frames), or(n_factors, n_freqs, n_frames)withaggregate=None, with a leading channel axis for 3-D input.- Return type:
numpy.ndarray[float32 | float64]
Beats
- audio_samples.rhythm.beat_track(*, onset_envelope, sr, hop_length=512, start_bpm=120.0, tightness=100, trim=False, bpm=None, prior=None, units='frames', sparse=True)
Tracks beats in an onset strength envelope.
Ellis’s dynamic-programming tracker: beats maximise onset strength while keeping inter-beat intervals close to the tempo’s period.
- Parameters:
onset_envelope (array_like) – 1-D onset envelope (
AudioSamples.beat_trackcomputes it withaggregate=numpy.median).sr (float) – Sampling rate. Required.
hop_length (int) – Hop in samples. Default 512.
start_bpm (float) – Prior centre of the tempo estimate. Default 120.
tightness (float) – Tempo-consistency weight. Default 100.
trim (bool) – Remove weak leading/trailing beats. Default False.
bpm (Optional[float | array_like]) – Tempo to track at (a number, or one value per frame for a time-varying tempo); None estimates it.
prior – Tempo prior (see
tempo).units (str) –
"frames"(default),"samples"or"time".sparse (bool) – Must be True.
- Returns:
(tempo, beats):tempois the estimate as a float64 array of shape(1,), orbpmunchanged when given, or0.0when the envelope is all zeros;beatsare int64 frames or samples, or float64 times.- Return type:
- Raises:
ValueError – For invalid parameters, a 2-D envelope or
sparse=False.
- audio_samples.rhythm.beat_track_with_bpm(onset_envelope, bpm, *, sr, hop_length=512, tightness=100.0, trim=False)
Runs the dynamic-programming beat tracker at a given tempo, without tempo estimation (what
beat_track(onset_envelope=..., bpm=...)runs).- Parameters:
onset_envelope (array_like) – 1-D onset envelope.
bpm (float | array_like) – Tempo in BPM: one value, or one per frame.
sr (float) – Sampling rate. Required.
hop_length (int) – Hop in samples (frame rate
sr / hop_length). Default 512.tightness (float) – Tempo-consistency weight. Default 100.
trim (bool) – Remove weak leading/trailing beats. Default False.
- Returns:
ascending beat frames.
- Return type:
numpy.ndarray[int64]
- Raises:
ValueError – For a wrong-length or non-positive
bpm, or a tempo so fast that its period is under one frame.
- audio_samples.rhythm.plp(*, onset_envelope, sr, hop_length=512, win_length=384, tempo_min=30, tempo_max=300, prior=None)
Predominant local pulse from the Fourier tempogram of an onset envelope.
- Parameters:
onset_envelope (array_like) –
(n_frames,)or(channels, n_frames)(AudioSamples.plpcomputes it withaggregate=numpy.median).sr (float) – Sampling rate. Required.
hop_length (int) – Hop in samples. Default 512.
win_length (int) – Fourier tempogram window in frames. Default 384.
tempo_min (Optional[float]) – Lowest tempo (BPM). Default 30.
tempo_max (Optional[float]) – Highest tempo (BPM). Default 300.
prior – Tempo prior (see
tempo), added in the log domain.
- Returns:
pulse curve, same shape as the envelope, in
[0, 1].- Return type:
numpy.ndarray[float32 | float64]
- Raises:
ValueError – If
tempo_max <= tempo_minor the envelope is empty.