madmom.features.tempo

This module contains tempo related functionality.

madmom.features.tempo.smooth_histogram(histogram, smooth)[source]

Smooth the given histogram.

Parameters:

histogram : tuple

Histogram (tuple of 2 numpy arrays, the first giving the strengths of the bins and the second corresponding delay values).

smooth : int or numpy array

Smoothing kernel (size).

Returns:

histogram_bins : numpy array

Bins of the smoothed histogram.

histogram_delays : numpy array

Corresponding delays.

Notes

If smooth is an integer, a Hamming window of that length will be used as a smoothing kernel.

madmom.features.tempo.interval_histogram_acf(activations, min_tau=1, max_tau=None)[source]

Compute the interval histogram of the given (beat) activation function via auto-correlation as in [R66].

Parameters:

activations : numpy array

Beat activation function.

min_tau : int, optional

Minimal delay for the auto-correlation function [frames].

max_tau : int, optional

Maximal delay for the auto-correlation function [frames].

Returns:

histogram_bins : numpy array

Bins of the tempo histogram.

histogram_delays : numpy array

Corresponding delays [frames].

References

[R66](1, 2) Sebastian Böck and Markus Schedl, “Enhanced Beat Tracking with Context-Aware Neural Networks”, Proceedings of the 14th International Conference on Digital Audio Effects (DAFx), 2011.
madmom.features.tempo.interval_histogram_comb(activations, alpha, min_tau=1, max_tau=None)[source]

Compute the interval histogram of the given (beat) activation function via a bank of resonating comb filters as in [R67].

Parameters:

activations : numpy array

Beat activation function.

alpha : float or numpy array

Scaling factor for the comb filter; if only a single value is given, the same scaling factor for all delays is assumed.

min_tau : int, optional

Minimal delay for the comb filter [frames].

max_tau : int, optional

Maximal delta for comb filter [frames].

Returns:

histogram_bins : numpy array

Bins of the tempo histogram.

histogram_delays : numpy array

Corresponding delays [frames].

References

[R67](1, 2) Sebastian Böck, Florian Krebs and Gerhard Widmer, “Accurate Tempo Estimation based on Recurrent Neural Networks and Resonating Comb Filters”, Proceedings of the 16th International Society for Music Information Retrieval Conference (ISMIR), 2015.
madmom.features.tempo.dominant_interval(histogram, smooth=None)[source]

Extract the dominant interval of the given histogram.

Parameters:

histogram : tuple

Histogram (tuple of 2 numpy arrays, the first giving the strengths of the bins and the second corresponding delay values).

smooth : int or numpy array, optional

Smooth the histogram with the given kernel (size).

Returns:

interval : int

Dominant interval.

Notes

If smooth is an integer, a Hamming window of that length will be used as a smoothing kernel.

madmom.features.tempo.detect_tempo(histogram, fps)[source]

Extract the tempo from the given histogram.

Parameters:

histogram : tuple

Histogram (tuple of 2 numpy arrays, the first giving the strengths of the bins and the second corresponding delay values).

fps : float

Frames per second.

Returns:

tempi : numpy array

Numpy array with the dominant tempi [bpm] (first column) and their relative strengths (second column).

class madmom.features.tempo.TempoEstimationProcessor(method='comb', min_bpm=40.0, max_bpm=250.0, act_smooth=0.14, hist_smooth=9, alpha=0.79, fps=None, **kwargs)[source]

Tempo Estimation Processor class.

Parameters:

method : {‘comb’, ‘acf’, ‘dbn’}

Method used for tempo estimation.

min_bpm : float, optional

Minimum tempo to detect [bpm].

max_bpm : float, optional

Maximum tempo to detect [bpm].

act_smooth : float, optional (default: 0.14)

Smooth the activation function over act_smooth seconds.

hist_smooth : int, optional (default: 7)

Smooth the tempo histogram over hist_smooth bins.

alpha : float, optional

Scaling factor for the comb filter.

fps : float, optional

Frames per second.

Examples

Create a TempoEstimationProcessor. The returned array represents the estimated tempi (given in beats per minute) and their relative strength.

>>> proc = TempoEstimationProcessor(fps=100)
>>> proc  
<madmom.features.tempo.TempoEstimationProcessor object at 0x...>

Call this TempoEstimationProcessor with the beat activation function obtained by RNNBeatProcessor to estimate the tempi.

>>> from madmom.features.beats import RNNBeatProcessor
>>> act = RNNBeatProcessor()('tests/data/audio/sample.wav')
>>> proc(act)  
array([[ 176.47059,  0.47469],
       [ 117.64706,  0.17667],
       [ 240.     ,  0.15371],
       [  68.96552,  0.09864],
       [  82.19178,  0.09629]])
min_interval

Minimum beat interval [frames].

max_interval

Maximum beat interval [frames].

process(activations, **kwargs)[source]

Detect the tempi from the (beat) activations.

Parameters:

activations : numpy array

Beat activation function.

Returns:

tempi : numpy array

Array with the dominant tempi [bpm] (first column) and their relative strengths (second column).

interval_histogram(activations)[source]

Compute the histogram of the beat intervals with the selected method.

Parameters:

activations : numpy array

Beat activation function.

Returns:

histogram_bins : numpy array

Bins of the beat interval histogram.

histogram_delays : numpy array

Corresponding delays [frames].

dominant_interval(histogram)[source]

Extract the dominant interval of the given histogram.

Parameters:

histogram : tuple

Histogram (tuple of 2 numpy arrays, the first giving the strengths of the bins and the second corresponding delay values).

Returns:

interval : int

Dominant interval.

static add_arguments(parser, method='comb', min_bpm=40.0, max_bpm=250.0, act_smooth=0.14, hist_smooth=9, alpha=0.79)[source]

Add tempo estimation related arguments to an existing parser.

Parameters:

parser : argparse parser instance

Existing argparse parser.

method : {‘comb’, ‘acf’, ‘dbn’}

Method used for tempo estimation.

min_bpm : float, optional

Minimum tempo to detect [bpm].

max_bpm : float, optional

Maximum tempo to detect [bpm].

act_smooth : float, optional

Smooth the activation function over act_smooth seconds.

hist_smooth : int, optional

Smooth the tempo histogram over hist_smooth bins.

alpha : float, optional

Scaling factor for the comb filter.

Returns:

parser_group : argparse argument group

Tempo argument parser group.

Notes

Parameters are included in the group only if they are not ‘None’.

madmom.features.tempo.write_tempo(tempi, filename, mirex=False)[source]

Write the most dominant tempi and the relative strength to a file.

Parameters:

tempi : numpy array

Array with the detected tempi (first column) and their strengths (second column).

filename : str or file handle

Output file.

mirex : bool, optional

Report the lower tempo first (as required by MIREX).

Returns:

tempo_1 : float

The most dominant tempo.

tempo_2 : float

The second most dominant tempo.

strength : float

Their relative strength.