From 7296f1230064343abde4fd31d83151989c90a05b Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sun, 25 Oct 2015 02:15:12 +0200 Subject: [PATCH] src/ofxAubioBlock.cpp: add setup / cleanup --- src/ofxAubioBlock.cpp | 15 +++++++++++++++ src/ofxAubioBlock.h | 3 +++ src/ofxAubioPitch.cpp | 21 +++++++-------------- src/ofxAubioPitch.h | 8 +++----- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/ofxAubioBlock.cpp b/src/ofxAubioBlock.cpp index 88b19cf..8679e99 100644 --- a/src/ofxAubioBlock.cpp +++ b/src/ofxAubioBlock.cpp @@ -20,6 +20,21 @@ #include "ofxAubioBlock.h" +void ofxAubioBlock::setup(std::string method, int buf_s, int hop_s, int samplerate) +{ + hop_size = (uint_t)hop_s; + buf_size = (uint_t)buf_s; + aubio_input = new_fvec(hop_size); + aubio_output = new_fvec(1); + curpos = 0; +} + +void ofxAubioBlock::cleanup() +{ + if (aubio_input) del_fvec(aubio_input); + if (aubio_output) del_fvec(aubio_output); +} + void ofxAubioBlock::audioIn(float * input, int bufferSize, int nChannels) { uint_t i, j; diff --git a/src/ofxAubioBlock.h b/src/ofxAubioBlock.h index 6acc56f..2d21ebd 100644 --- a/src/ofxAubioBlock.h +++ b/src/ofxAubioBlock.h @@ -19,6 +19,7 @@ */ #pragma once +#include #include class ofxAubioBlock { @@ -29,6 +30,8 @@ class ofxAubioBlock { uint_t curpos; fvec_t * aubio_input; fvec_t * aubio_output; + void setup(std::string method, int buf_s, int hop_s, int samplerate); + void cleanup(); virtual void blockAudioIn() {}; public: diff --git a/src/ofxAubioPitch.cpp b/src/ofxAubioPitch.cpp index b781d5c..19de0e0 100644 --- a/src/ofxAubioPitch.cpp +++ b/src/ofxAubioPitch.cpp @@ -32,15 +32,11 @@ void ofxAubioPitch::setup() void ofxAubioPitch::setup(string method, int buf_s, int hop_s, int samplerate) { - hop_size = (uint_t)hop_s; - buf_size = (uint_t)buf_s; + ofxAubioBlock::setup(method, buf_s, hop_s, samplerate); pitch = new_aubio_pitch((char_t*)method.c_str(), buf_size, hop_size, samplerate); aubio_pitch_set_unit(pitch, (char_t*)"midi"); - aubio_pitch_set_tolerance(pitch, 0.7); - aubio_input = new_fvec(hop_size); - aubio_output = new_fvec(1); - curpos = 0; + //aubio_pitch_set_tolerance(pitch, 0.7); if (pitch) { ofLogNotice() << "created ofxAubioPitch(" << method << ", " << buf_size @@ -52,18 +48,15 @@ void ofxAubioPitch::setup(string method, int buf_s, int hop_s, int samplerate) ofxAubioPitch::~ofxAubioPitch() { - ofLogNotice() << "deleted ofxAubioPitch"; if (pitch) del_aubio_pitch(pitch); - if (aubio_input) del_fvec(aubio_input); - if (aubio_output) del_fvec(aubio_output); + cleanup(); + ofLogNotice() << "deleted ofxAubioPitch"; } void ofxAubioPitch::blockAudioIn() { aubio_pitch_do(pitch, aubio_input, aubio_output); - if (aubio_output->data[0]) { - //ofLogNotice() << "found pitch: " << aubio_output->data[0]; - latestPitch = aubio_output->data[0]; - pitchConfidence = aubio_pitch_get_confidence(pitch); - } + //ofLogNotice() << "found pitch: " << aubio_output->data[0]; + pitchConfidence = aubio_pitch_get_confidence(pitch); + latestPitch = aubio_output->data[0]; } diff --git a/src/ofxAubioPitch.h b/src/ofxAubioPitch.h index fe91186..d332119 100644 --- a/src/ofxAubioPitch.h +++ b/src/ofxAubioPitch.h @@ -20,11 +20,9 @@ #pragma once -#include "ofxAubioBlock.h" -#include #include - -using namespace std; +#include +#include "ofxAubioBlock.h" class ofxAubioPitch : public ofxAubioBlock { @@ -34,7 +32,7 @@ class ofxAubioPitch : public ofxAubioBlock { ~ofxAubioPitch(); void setup(); - void setup(string method, int buf_s, int hop_s, int samplerate); + void setup(std::string method, int buf_s, int hop_s, int samplerate); float latestPitch; float pitchConfidence; -- 2.11.0