From b758d18a3de5599e03420c71ca7d7644c1d92f76 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sun, 25 Oct 2015 01:35:35 +0200 Subject: [PATCH] src/ofxAubioBlock.h: add block processing, use in ofxAubioPitch --- src/ofxAubioBlock.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ src/ofxAubioBlock.h | 36 ++++++++++++++++++++++++++++++++++++ src/ofxAubioPitch.cpp | 20 -------------------- src/ofxAubioPitch.h | 15 ++++----------- 4 files changed, 81 insertions(+), 31 deletions(-) create mode 100644 src/ofxAubioBlock.cpp create mode 100644 src/ofxAubioBlock.h diff --git a/src/ofxAubioBlock.cpp b/src/ofxAubioBlock.cpp new file mode 100644 index 0000000..88b19cf --- /dev/null +++ b/src/ofxAubioBlock.cpp @@ -0,0 +1,41 @@ +/* + 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 "ofxAubioBlock.h" + +void ofxAubioBlock::audioIn(float * input, int bufferSize, int nChannels) +{ + uint_t i, j; + for (i = 0; i < bufferSize; i++) { + // downmix into aubio_input + aubio_input->data[curpos] = 0.; + for (j = 0; j < nChannels; j++) { + aubio_input->data[curpos] += input[i * nChannels + j]; + } + aubio_input->data[curpos] /= (smpl_t)nChannels; + // run aubio block when appropriate + curpos += 1; + if (curpos == hop_size) + { + blockAudioIn(); + curpos = 0; + } + } +} diff --git a/src/ofxAubioBlock.h b/src/ofxAubioBlock.h new file mode 100644 index 0000000..6acc56f --- /dev/null +++ b/src/ofxAubioBlock.h @@ -0,0 +1,36 @@ +/* + 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 + +class ofxAubioBlock { + + protected: + uint_t buf_size; + uint_t hop_size; + uint_t curpos; + fvec_t * aubio_input; + fvec_t * aubio_output; + virtual void blockAudioIn() {}; + + public: + void audioIn(float *input, int bufferSize, int nChannels); +}; diff --git a/src/ofxAubioPitch.cpp b/src/ofxAubioPitch.cpp index b523895..b781d5c 100644 --- a/src/ofxAubioPitch.cpp +++ b/src/ofxAubioPitch.cpp @@ -58,26 +58,6 @@ ofxAubioPitch::~ofxAubioPitch() if (aubio_output) del_fvec(aubio_output); } -void ofxAubioPitch::audioIn(float * input, int bufferSize, int nChannels) -{ - uint_t i, j; - for (i = 0; i < bufferSize; i++) { - // downmix into aubio_input - aubio_input->data[curpos] = 0.; - for (j = 0; j < nChannels; j++) { - aubio_input->data[curpos] += input[i * nChannels + j]; - } - aubio_input->data[curpos] /= (smpl_t)nChannels; - // run aubio block when appropriate - curpos += 1; - if (curpos == hop_size) - { - blockAudioIn(); - curpos = 0; - } - } -} - void ofxAubioPitch::blockAudioIn() { aubio_pitch_do(pitch, aubio_input, aubio_output); diff --git a/src/ofxAubioPitch.h b/src/ofxAubioPitch.h index 28e91b5..fe91186 100644 --- a/src/ofxAubioPitch.h +++ b/src/ofxAubioPitch.h @@ -20,12 +20,13 @@ #pragma once -#include +#include "ofxAubioBlock.h" #include +#include using namespace std; -class ofxAubioPitch { +class ofxAubioPitch : public ofxAubioBlock { public: @@ -35,19 +36,11 @@ class ofxAubioPitch { void setup(); void setup(string method, int buf_s, int hop_s, int samplerate); - void audioIn(float *input, int bufferSize, int nChannels); - float latestPitch; float pitchConfidence; - private: + protected: void blockAudioIn(); // aubio stuff - uint_t buf_size; - uint_t hop_size; - fvec_t * aubio_input; - fvec_t * aubio_output; aubio_pitch_t * pitch; - uint_t curpos; - }; -- 2.11.0