From: Paul Brossier Date: Fri, 30 Oct 2015 15:56:06 +0000 (+0100) Subject: src/ofxAubioMelBands.h: add object to get energies of each mel band X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=d970aa7052e131f2bebc13b20f795080d850e2db;p=ofxAubio.git src/ofxAubioMelBands.h: add object to get energies of each mel band --- diff --git a/src/ofxAubio.h b/src/ofxAubio.h index d417ac3..d0d7500 100644 --- a/src/ofxAubio.h +++ b/src/ofxAubio.h @@ -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 index 0000000..0516fb2 --- /dev/null +++ b/src/ofxAubioMelBands.cpp @@ -0,0 +1,66 @@ +/* + 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 "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 index 0000000..885df28 --- /dev/null +++ b/src/ofxAubioMelBands.h @@ -0,0 +1,48 @@ +/* + 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 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; +};