apollon.onsets module¶
apollon/onsets.py – Onset detection routines.
- Classes:
- OnsetDetector Base class for onset detection. EntropyOnsetDetector Onset detection based on phase pace entropy estimation. FluxOnsetDetector Onset detection based on spectral flux.
- Functions:
- peak_picking Identify local peaks in time series. evaluate_onsets Evaluation of onset detection results given ground truth.
-
class
apollon.onsets.
EntropyOnsetDetector
(inp: numpy.ndarray, delay: int = 10, m_dims: int = 3, bins: int = 10, n_perseg: int = 1024, hop_size: int = 512, pp_params=None)¶ Bases:
apollon.onsets.OnsetDetector
Detect onsets based on entropy maxima.
Parameters: - inp – Audio signal.
- delay – Embedding delay.
- m_dim – Embedding dimension.
- bins – Boxes per axis.
- n_perseg – Length of segments in samples.
- hop_size – Displacement in samples.
- smooth – Smoothing filter length.
-
class
apollon.onsets.
FluxOnsetDetector
(inp: numpy.ndarray, fps: int, window: str = 'hamming', n_perseg: int = 2048, hop_size: int = 441, cutoff=(80, 10000), n_fft: int = None, pp_params=None)¶ Bases:
apollon.onsets.OnsetDetector
Onset detection based on spectral flux.
Parameters: - inp –
- stft_params – Parameters for the STFT
- pp_params – Peak picking paraneters
-
params
() → dict¶
-
class
apollon.onsets.
OnsetDetector
¶ Bases:
object
Onset detection base class.
Subclasses have to implement an __init__ method to take in custom arguments. It necessarily has to call the base classes __init__ method. Additionally, subclasses have to implement a custom onset detection function named _odf. This method should return an one-dimensional ndarray.
-
index
() → numpy.ndarray¶ Compute onset index.
Onset values are centered within the detection window.
Returns: Onset position in samples
-
times
(fps: int) → numpy.ndarray¶ Compute time code im ms for each onset give the sample rate.
Parameters: fps – Sample rate. Returns: Time code of onsets.
-
-
apollon.onsets.
evaluate_onsets
(targets: Dict[str, numpy.ndarray], estimates: Dict[str, numpy.ndarray]) → Tuple[float, float, float]¶ Evaluate onset detection performance.
This function uses the mir_eval package for evaluation.
Parameters: - targets – Ground truth onset times, with dict keys being file names, and values being target onset time codes in ms.
- estimates – Estimated onsets times, with dictkeys being file names, and values being the estimated onset time codes in ms.
Returns: Precison, recall, f-measure.
-
apollon.onsets.
peak_picking
(odf: numpy.ndarray, post_window: int = 10, pre_window: int = 10, alpha: float = 0.1, delta: float = 0.1) → numpy.ndarray¶ Pick local maxima from a numerical time series.
Pick local maxima from the onset detection function odf, which is assumed to be an one-dimensional array. Typically, odf is the Spectral Flux per time step.
- Params:
- odf: Onset detection function, e.g., Spectral Flux. post_window: Window lenght to consider after now. pre_window: Window lenght to consider before now. alpha: Smoothing factor. Must be in ]0, 1[. delta: Difference to the mean.
Returns: Peak indices.