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

diff --git a/src/ofxAubioOnset.cpp b/src/ofxAubioOnset.cpp
new file mode 100644 (file)
index 0000000..3a6e6f7
--- /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 "ofxAubioOnset.h"
+#include "ofLog.h"
+
+ofxAubioOnset::ofxAubioOnset()
+{
+}
+
+void ofxAubioOnset::setup()
+{
+    setup("default", 512, 256, 44100);
+}
+
+void ofxAubioOnset::setup(string method, int buf_s, int hop_s, int samplerate)
+{
+    ofxAubioBlock::setup(method, buf_s, hop_s, samplerate);
+    onset = new_aubio_onset((char_t*)method.c_str(),
+                            buf_size, hop_size, samplerate);
+    if (onset) {
+        ofLogNotice() << "created ofxAubioOnset(" << method
+          << ", " << buf_size
+          << ", " << hop_size
+          << ", " << samplerate
+          << ")";
+    }
+}
+
+ofxAubioOnset::~ofxAubioOnset()
+{
+    if (onset) del_aubio_onset(onset);
+    cleanup();
+    ofLogNotice() << "deleted ofxAubioOnset";
+}
+
+void ofxAubioOnset::blockAudioIn()
+{
+    aubio_onset_do(onset, aubio_input, aubio_output);
+    if (aubio_output->data[0]) {
+        toSend = true;
+        //ofLogNotice() << "found onset";
+    }
+    latestDescriptor = aubio_onset_get_descriptor(onset);
+}
diff --git a/src/ofxAubioOnset.h b/src/ofxAubioOnset.h
new file mode 100644 (file)
index 0000000..152ae79
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+  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"
+
+class ofxAubioOnset : public ofxAubioBlock {
+
+    public:
+
+       ofxAubioOnset();
+       ~ofxAubioOnset();
+
+       void setup();
+       void setup(std::string method, int buf_s, int hop_s, int samplerate);
+
+       float latestDescriptor = 0;
+
+    private:
+       void blockAudioIn();
+       // aubio stuff
+       aubio_onset_t * onset;
+};