You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#include "tools/beatutils.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include <numeric>
|
|
|
|
|
|
|
|
auto beat_utils::calculateBeatRateInfo(
|
|
|
|
const std::vector<kku::microsec> &approximate_deltas) -> BeatInfo
|
|
|
|
{
|
|
|
|
if (approximate_deltas.empty())
|
|
|
|
return {};
|
|
|
|
|
|
|
|
const long double sum = std::accumulate(approximate_deltas.begin(),
|
|
|
|
approximate_deltas.end(), 0);
|
|
|
|
const long double amount = approximate_deltas.size();
|
|
|
|
|
|
|
|
long double average = sum / amount;
|
|
|
|
|
|
|
|
const int bpm = static_cast<int>(60000000. / average);
|
|
|
|
|
|
|
|
return BeatInfo{bpm, static_cast<kku::microsec>(
|
|
|
|
1. / static_cast<long double>(bpm) * 60000000.)};
|
|
|
|
}
|