MusicBeatDetector is a small C++ library to estimate the song tempo and to detect if the beat is in the current frame. The algorithm can be used in real time and is based on OBTAIN.
Author(s): Marc-Antoine Maheux
- Most dependencies are part of the project with git submodules in the MusicBeatDetector/3rdParty directory. FFTW is copied because there is no buildable git repository.
- beat_detector_node is a ROS node that integrates this library.
The following subsections explain how to use the library on Ubuntu.
sudo apt-get install cmake build-essential gfortran texinfo
git submodule init
git submodule update
cd <<<repository dir>>>
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
The following example shows how to use the library.
#include <MusicBeatDetector/MusicBeatDetector.h>
#include <iostream>
using namespace introlab;
using namespace std;
void getNextAudioFrame(size_t frameSampleCount, float* data)
{
...
}
int main(int argc, char** argv)
{
constexpr size_t SamplingFrequency = 44100;
constexpr size_t FrameSampleCount = 128;
constexpr size_t ChannelCount = 1; // Other values are not supported
float data[FrameSampleCount] = {0};
try
{
PcmAudioFrame frame(PcmAudioFrameFormat::Float, ChannelCount, FrameSampleCount, reinterpret_cast<uint8_t*>(data));
MusicBeatDetector musicBeatDetector(SamplingFrequency, FrameSampleCount);
while (true)
{
getNextAudioFrame(FrameSampleCount, data);
Beat beat = musicBeatDetector.detect(frame);
cout << "BPM=" << beat.bpm << ", isBeat=" << beat.isBeat << endl;
}
}
catch (const std::exception& e)
{
cout << e.what() << endl;
}
return 0;
}
IntRoLab - Intelligent / Interactive / Integrated / Interdisciplinary Robot Lab