From 3793a5e4b95491f4ed0fd6295981b545eb27606f Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sun, 25 Oct 2015 02:39:59 +0200 Subject: [PATCH] src/ofxAubioBeat.*: add ofxAubioBeat --- src/ofxAubioBeat.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ofxAubioBeat.h | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 src/ofxAubioBeat.cpp create mode 100644 src/ofxAubioBeat.h diff --git a/src/ofxAubioBeat.cpp b/src/ofxAubioBeat.cpp new file mode 100644 index 0000000..2add9a0 --- /dev/null +++ b/src/ofxAubioBeat.cpp @@ -0,0 +1,62 @@ +/* + Copyright (C) 2015 Paul Brossier + + This file is part of ofxAubio. + + ofxAubio is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + aubio is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with aubio. If not, see . + +*/ + +#include "ofxAubioBeat.h" +#include "ofLog.h" + +ofxAubioBeat::ofxAubioBeat() +{ +} + +void ofxAubioBeat::setup() +{ + setup("default", 512, 256, 44100); +} + +void ofxAubioBeat::setup(string method, int buf_s, int hop_s, int samplerate) +{ + ofxAubioBlock::setup(method, buf_s, hop_s, samplerate); + tempo = new_aubio_tempo((char_t*)method.c_str(), + buf_size, hop_size, samplerate); + if (tempo) { + ofLogNotice() << "created ofxAubioBeat(" << method + << ", " << buf_size + << ", " << hop_size + << ", " << samplerate + << ")"; + } +} + +ofxAubioBeat::~ofxAubioBeat() +{ + if (tempo) del_aubio_tempo(tempo); + cleanup(); + ofLogNotice() << "deleted ofxAubioBeat"; +} + +void ofxAubioBeat::blockAudioIn() +{ + aubio_tempo_do(tempo, aubio_input, aubio_output); + if (aubio_output->data[0]) { + //ofLogNotice() << "found beat: " << aubio_output->data[0]; + toSend = true; + bpm = aubio_tempo_get_bpm(tempo); + } +} diff --git a/src/ofxAubioBeat.h b/src/ofxAubioBeat.h new file mode 100644 index 0000000..bcbdfda --- /dev/null +++ b/src/ofxAubioBeat.h @@ -0,0 +1,46 @@ +/* + Copyright (C) 2015 Paul Brossier + + This file is part of ofxAubio. + + ofxAubio is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + aubio is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with aubio. If not, see . + +*/ + +#pragma once + +#include +#include +#include "ofxAubioBlock.h" + +using namespace std; + +class ofxAubioBeat : public ofxAubioBlock { + + public: + + ofxAubioBeat(); + ~ofxAubioBeat(); + + void setup(); + void setup(string method, int buf_s, int hop_s, int samplerate); + + float bpm; + + private: + void blockAudioIn(); + bool beatFlag = false; + // aubio stuff + aubio_tempo_t * tempo; +}; -- 2.11.0