Skip to content

introlab/MusicBeatDetector

Repository files navigation

MusicBeatDetector

Actions Status

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

Dependencies

  • 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.

ROS Users

Setup (Ubuntu)

The following subsections explain how to use the library on Ubuntu.

Install Dependencies

sudo apt-get install cmake build-essential gfortran texinfo

Setup Submodules

git submodule init
git submodule update

Build

cd <<<repository dir>>>
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make

Example

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;
}

License

Sponsor

IntRoLab

IntRoLab - Intelligent / Interactive / Integrated / Interdisciplinary Robot Lab

Releases

No releases published

Packages

No packages published