src/ofxAubioBlock.h: add block processing, use in ofxAubioPitch
authorPaul Brossier <piem@piem.org>
Sat, 24 Oct 2015 23:35:35 +0000 (01:35 +0200)
committerPaul Brossier <piem@piem.org>
Sat, 24 Oct 2015 23:35:35 +0000 (01:35 +0200)
src/ofxAubioBlock.cpp [new file with mode: 0644]
src/ofxAubioBlock.h [new file with mode: 0644]
src/ofxAubioPitch.cpp
src/ofxAubioPitch.h

diff --git a/src/ofxAubioBlock.cpp b/src/ofxAubioBlock.cpp
new file mode 100644 (file)
index 0000000..88b19cf
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+  Copyright (C) 2015 Paul Brossier <piem@aubio.org>
+
+  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 <http://www.gnu.org/licenses/>.
+
+*/
+
+#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 (file)
index 0000000..6acc56f
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+  Copyright (C) 2015 Paul Brossier <piem@aubio.org>
+
+  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 <http://www.gnu.org/licenses/>.
+
+*/
+
+#pragma once
+#include <aubio/aubio.h>
+
+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);
+};
index b523895..b781d5c 100644 (file)
@@ -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);
index 28e91b5..fe91186 100644 (file)
 
 #pragma once
 
-#include <iostream>
+#include "ofxAubioBlock.h"
 #include <aubio/aubio.h>
+#include <iostream>
 
 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;
-
 };