src/ofxAubioMelBands.h: add object to get energies of each mel band
authorPaul Brossier <piem@piem.org>
Fri, 30 Oct 2015 15:56:06 +0000 (16:56 +0100)
committerPaul Brossier <piem@piem.org>
Fri, 30 Oct 2015 15:56:06 +0000 (16:56 +0100)
src/ofxAubio.h
src/ofxAubioMelBands.cpp [new file with mode: 0644]
src/ofxAubioMelBands.h [new file with mode: 0644]

index d417ac3..d0d7500 100644 (file)
@@ -21,4 +21,5 @@
 #include "ofxAubioBeat.h"
 #include "ofxAubioOnset.h"
 #include "ofxAubioPitch.h"
+#include "ofxAubioMelBands.h"
 
diff --git a/src/ofxAubioMelBands.cpp b/src/ofxAubioMelBands.cpp
new file mode 100644 (file)
index 0000000..0516fb2
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+  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 "ofxAubioMelBands.h"
+#include "ofLog.h"
+
+ofxAubioMelBands::ofxAubioMelBands()
+{
+}
+
+void ofxAubioMelBands::setup()
+{
+    setup("default", 512, 256, 44100);
+}
+
+void ofxAubioMelBands::setup(string method, int buf_s, int hop_s, int samplerate)
+{
+    ofxAubioBlock::setup(method, buf_s, hop_s, samplerate);
+    pv = new_aubio_pvoc(buf_s, hop_s);
+    spectrum = new_cvec(buf_s);
+    fb = new_aubio_filterbank(40, buf_s);
+    aubio_filterbank_set_mel_coeffs_slaney(fb, samplerate);
+    bands = new_fvec(40);
+    energies = bands->data;
+
+    if (pv && fb) {
+        ofLogNotice() << "created ofxAubioMelBands(" << method
+          << ", " << buf_size
+          << ", " << hop_size
+          << ", " << samplerate
+          << ")";
+    }
+}
+
+ofxAubioMelBands::~ofxAubioMelBands()
+{
+    if (spectrum) del_cvec(spectrum);
+    if (pv) del_aubio_pvoc(pv);
+    if (bands) del_fvec(bands);
+    if (fb) del_aubio_filterbank(fb);
+    cleanup();
+    ofLogNotice() << "deleted ofxAubioMelBands";
+}
+
+void ofxAubioMelBands::blockAudioIn()
+{
+    aubio_pvoc_do(pv, aubio_input, spectrum);
+    aubio_filterbank_do(fb, spectrum, bands);
+}
diff --git a/src/ofxAubioMelBands.h b/src/ofxAubioMelBands.h
new file mode 100644 (file)
index 0000000..885df28
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+  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 ofxAubioMelBands : public ofxAubioBlock {
+
+    public:
+
+       ofxAubioMelBands();
+       ~ofxAubioMelBands();
+
+       void setup();
+       void setup(string method, int buf_s, int hop_s, int samplerate);
+
+       float *energies;
+
+    private:
+       void blockAudioIn();
+       // aubio stuff
+       aubio_pvoc_t *pv;
+       cvec_t *spectrum;
+       aubio_filterbank_t *fb;
+       fvec_t *bands;
+};