diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-06 20:43:17 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-06 20:43:17 +1000 |
| commit | 929d8fa40e371a2adbe1fe0f93f0ebf11bcb0981 (patch) | |
| tree | 965f95279a862cf5853eb6af8ac60938a784a685 /plugin/src/Caelestia/beattracker.cpp | |
| parent | plugin: fix cmake version (diff) | |
| download | caelestia-shell-929d8fa40e371a2adbe1fe0f93f0ebf11bcb0981.tar.gz caelestia-shell-929d8fa40e371a2adbe1fe0f93f0ebf11bcb0981.tar.bz2 caelestia-shell-929d8fa40e371a2adbe1fe0f93f0ebf11bcb0981.zip | |
plugin: async audio processing
Diffstat (limited to 'plugin/src/Caelestia/beattracker.cpp')
| -rw-r--r-- | plugin/src/Caelestia/beattracker.cpp | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/plugin/src/Caelestia/beattracker.cpp b/plugin/src/Caelestia/beattracker.cpp index a915c08..b59abd7 100644 --- a/plugin/src/Caelestia/beattracker.cpp +++ b/plugin/src/Caelestia/beattracker.cpp @@ -6,33 +6,46 @@ namespace caelestia { -BeatTracker::BeatTracker(uint_t sampleRate, uint_t hopSize, QObject* parent) - : AudioProvider(static_cast<int>(sampleRate), static_cast<int>(hopSize), parent) +BeatWorker::BeatWorker(uint_t sampleRate, uint_t hopSize, QObject* parent) + : AudioWorker(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) {}; + , m_out(new_fvec(2)) {}; -BeatTracker::~BeatTracker() { +BeatWorker::~BeatWorker() { del_aubio_tempo(m_tempo); del_fvec(m_in); del_fvec(m_out); } -smpl_t BeatTracker::bpm() const { - return m_bpm; -} - -void BeatTracker::processData() { +void BeatWorker::processData() { process(m_in->data); } -void BeatTracker::consumeData() { +void BeatWorker::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 beat(aubio_tempo_get_bpm(m_tempo)); + } +} + +BeatTracker::BeatTracker(uint_t sampleRate, uint_t hopSize, QObject* parent) + : AudioProvider(parent) + , m_bpm(120) { + m_worker = new BeatWorker(sampleRate, hopSize, this); + init(); + + connect(static_cast<BeatWorker*>(m_worker), &BeatWorker::beat, this, &BeatTracker::updateBpm); +} + +smpl_t BeatTracker::bpm() const { + return m_bpm; +} + +void BeatTracker::updateBpm(smpl_t bpm) { + if (!qFuzzyCompare(bpm + 1.0f, m_bpm + 1.0f)) { + m_bpm = bpm; emit bpmChanged(); - emit beat(m_bpm); } } |