src/ofxAubioBeat.*: add ofxAubioBeat
authorPaul Brossier <piem@piem.org>
Sun, 25 Oct 2015 00:39:59 +0000 (02:39 +0200)
committerPaul Brossier <piem@piem.org>
Sun, 25 Oct 2015 00:39:59 +0000 (02:39 +0200)
src/ofxAubioBeat.cpp [new file with mode: 0644]
src/ofxAubioBeat.h [new file with mode: 0644]

diff --git a/src/ofxAubioBeat.cpp b/src/ofxAubioBeat.cpp
new file mode 100644 (file)
index 0000000..2add9a0
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+  Copyright (C) 2015 Paul Brossier <piem@aubio.org>
+
+  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 <http://www.gnu.org/licenses/>.
+
+*/
+
+#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 (file)
index 0000000..bcbdfda
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+  Copyright (C) 2015 Paul Brossier <piem@aubio.org>
+
+  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 <http://www.gnu.org/licenses/>.
+
+*/
+
+#pragma once
+
+#include <iostream>
+#include <aubio/aubio.h>
+#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;
+};