From: Paul Brossier Date: Sun, 25 Oct 2015 00:35:49 +0000 (+0200) Subject: src/ofxAubioOnset.*: add ofxAubioOnset X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=047b36b9e5524d2ea6ae23aa03a02d0a592ae2d0;p=ofxAubio.git src/ofxAubioOnset.*: add ofxAubioOnset --- diff --git a/src/ofxAubioOnset.cpp b/src/ofxAubioOnset.cpp new file mode 100644 index 0000000..3a6e6f7 --- /dev/null +++ b/src/ofxAubioOnset.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 "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 index 0000000..152ae79 --- /dev/null +++ b/src/ofxAubioOnset.h @@ -0,0 +1,43 @@ +/* + 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" + +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; +};