Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tempo algorithm is wrong. #14

Open
enn-nafnlaus opened this issue Apr 6, 2023 · 0 comments
Open

Tempo algorithm is wrong. #14

enn-nafnlaus opened this issue Apr 6, 2023 · 0 comments

Comments

@enn-nafnlaus
Copy link

Tempo appears to be calculated as "duration / (# of beats - 1)". That's not an accurate algorithm, as not all beats will be detected (or even present in the song), while half-beats will sometimes be detected.

A proper algorithm is:

tempo = sorted([beat_times[i+1] - beat_times[i] for i in range(len(beat_times) - 1)])[int((len(beat_times) - 1) / 2)]

or

tempo = statistics.median([beat_times[i+1] - beat_times[i] for i in range(len(beat_times) - 1)])

... depending on whether you want a hard median (no averaging in the case of there being an odd number of detected beats, aka an even number of gaps between them) or a soft median (with averaging between the two centre elements).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant