summaryrefslogtreecommitdiff
path: root/plugin/src/Caelestia/beattracker.cpp
blob: a915c0837431c8be5ee1582c065d8aca3f5c78d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "beattracker.hpp"

#include "audioprovider.hpp"
#include <QObject>
#include <aubio/aubio.h>

namespace caelestia {

BeatTracker::BeatTracker(uint_t sampleRate, uint_t hopSize, QObject* parent)
    : AudioProvider(static_cast<int>(sampleRate), static_cast<int>(hopSize), parent)
    , m_tempo(new_aubio_tempo("default", 1024, hopSize, sampleRate))
    , m_in(new_fvec(hopSize))
    , m_out(new_fvec(2))
    , m_bpm(120) {};

BeatTracker::~BeatTracker() {
    del_aubio_tempo(m_tempo);
    del_fvec(m_in);
    del_fvec(m_out);
}

smpl_t BeatTracker::bpm() const {
    return m_bpm;
}

void BeatTracker::processData() {
    process(m_in->data);
}

void BeatTracker::consumeData() {
    aubio_tempo_do(m_tempo, m_in, m_out);
    if (m_out->data[0] != 0.0f) {
        m_bpm = aubio_tempo_get_bpm(m_tempo);
        emit bpmChanged();
        emit beat(m_bpm);
    }
}

} // namespace caelestia