Audacity 3.2.0
GetMeterUsingTatumQuantizationFit.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4Audacity: A Digital Audio Editor
5
6GetMeterUsingTatumQuantizationFit.h
7
8Matthieu Hodgkinson
9
10A method to classify audio recordings in loops and non-loops, with a
11confidence score, together with a BPM estimate.
12
13The method evaluates the assumption that the given audio is a loop. Based on
14this assumption, and finite possible tempi and time signatures, a set of
15hypotheses is tested. For each hypothesis, a tatum* quantization is tried,
16returning an average of the normalized distance between Onset Detection Function
17(ODF) peaks and the closest tatum, weighted by the ODF peak values. This yields
18a single scalar that strongly correlates with the fact that the audio is a loop
19or not, and that we use for loop/non-loop classification.
20
21Besides this score, the classification stage also yields the most likely tatum
22rate, which still needs disambiguation to find the beat rate. The
23autocorrelation of the ODF is taken, and, for each bar division explaining the
24tatum rate, is comb-filtered. The energy of the comb-filtering together with the
25BPM likelihood are combined together, and the BPM with largest score is
26returned.
27
28This approach is in some aspects like existing tempo detection methods (e.g.
29Percival, Graham & Tzanetakis, George (2014), implemented in the Essentia
30framework at https://essentia.upf.edu/), insofar as it first derives an ODF and
31then somehow correlates it with expected rhythmic patterns. However, the
32quantization distance, at the core of the method, is not known by the author to
33be used in other methods. Also, once the ODF is taken, the loop assumption lends
34itself to a single analysis of the entire ODF, rather than performing mid-term
35analyses which are then combined together. Finally, albeit restricting the use
36of application, the loop assumption reduces the number of tried hypotheses,
37reducing the risk of non-musical recordings to be detected as musical by sheer
38luck. This increased robustness of the algorithm against false positives is
39quintessential for Audacity, where non-music users should not be bothered by
40wrong detections. The loop assumption is nevertheless not fundamental, and the
41algorithm could be implemented without it, at the cost of a higher risk of false
42positives.
43
44Evaluation and benchmarking code can be found in
45TatumQuantizationFitBenchmarking.cpp. This code takes a tolerable false-positive
46rate, and outputs the corresponding loop/non-loop threshold. It also returns the
47Octave Error accuracy measure, as introduced in "Schreiber, H., et al. (2020).
48Music Tempo Estimation: Are We Done Yet?".
49
50*A tatum is the smallest rhythmic unit in a musical piece. Quoting from
51https://en.wikipedia.org/wiki/Tatum_(music): "The term was coined by Jeff Bilmes
52(...) and is named after the influential jazz pianist Art Tatum, "whose tatum
53was faster than all others""
54
55**********************************************************************/
56
57#pragma once
58
59#include "MirTypes.h"
60
61#include <functional>
62#include <optional>
63
64namespace MIR
65{
66class MirAudioReader;
67
72std::optional<MusicalMeter> GetMeterUsingTatumQuantizationFit(
73 const MirAudioReader& audio, FalsePositiveTolerance tolerance,
74 const std::function<void(double)>& progressCallback,
75 QuantizationFitDebugOutput* debugOutput);
76
77} // namespace MIR
MockedAudio audio
FalsePositiveTolerance
Definition: MirTypes.h:25
std::optional< MusicalMeter > GetMeterUsingTatumQuantizationFit(const MirAudioReader &audio, FalsePositiveTolerance tolerance, const std::function< void(double)> &progressCallback, QuantizationFitDebugOutput *debugOutput)
Get the BPM of the given audio file, using the Tatum Quantization Fit method.