src/ofxAubioBlock.cpp: add setup / cleanup
authorPaul Brossier <piem@piem.org>
Sun, 25 Oct 2015 00:15:12 +0000 (02:15 +0200)
committerPaul Brossier <piem@piem.org>
Sun, 25 Oct 2015 00:15:12 +0000 (02:15 +0200)
src/ofxAubioBlock.cpp
src/ofxAubioBlock.h
src/ofxAubioPitch.cpp
src/ofxAubioPitch.h

index 88b19cf..8679e99 100644 (file)
 
 #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;
index 6acc56f..2d21ebd 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #pragma once
+#include <iostream>
 #include <aubio/aubio.h>
 
 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:
index b781d5c..19de0e0 100644 (file)
@@ -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];
 }
index fe91186..d332119 100644 (file)
 
 #pragma once
 
-#include "ofxAubioBlock.h"
-#include <aubio/aubio.h>
 #include <iostream>
-
-using namespace std;
+#include <aubio/aubio.h>
+#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;