From cb7ec4965e6ec3d2142522c5c110b240f800e55d Mon Sep 17 00:00:00 2001 From: Comment Date: Mon, 20 May 2013 08:55:30 +0100 Subject: vamp wrapper begun --- TRSS_02_rec/Makefile | 2 - TRSS_02_rec/addons.make | 5 - TRSS_02_rec/config.make | 56 ------------ TRSS_02_rec/src/main.cpp | 17 ---- TRSS_02_rec/src/testApp.cpp | 199 ---------------------------------------- TRSS_02_rec/src/testApp.h | 42 --------- vamphost/Makefile | 2 + vamphost/addons.make | 1 + vamphost/config.make | 57 ++++++++++++ vamphost/src/main.cpp | 17 ++++ vamphost/src/ofxVamphost.cpp | 212 +++++++++++++++++++++++++++++++++++++++++++ vamphost/src/ofxVamphost.h | 49 ++++++++++ vamphost/src/testApp.cpp | 69 ++++++++++++++ vamphost/src/testApp.h | 28 ++++++ 14 files changed, 435 insertions(+), 321 deletions(-) delete mode 100755 TRSS_02_rec/Makefile delete mode 100644 TRSS_02_rec/addons.make delete mode 100755 TRSS_02_rec/config.make delete mode 100644 TRSS_02_rec/src/main.cpp delete mode 100644 TRSS_02_rec/src/testApp.cpp delete mode 100644 TRSS_02_rec/src/testApp.h create mode 100755 vamphost/Makefile create mode 100644 vamphost/addons.make create mode 100755 vamphost/config.make create mode 100644 vamphost/src/main.cpp create mode 100644 vamphost/src/ofxVamphost.cpp create mode 100644 vamphost/src/ofxVamphost.h create mode 100644 vamphost/src/testApp.cpp create mode 100644 vamphost/src/testApp.h diff --git a/TRSS_02_rec/Makefile b/TRSS_02_rec/Makefile deleted file mode 100755 index 2d83a77..0000000 --- a/TRSS_02_rec/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -include config.make -include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/Makefile.examples diff --git a/TRSS_02_rec/addons.make b/TRSS_02_rec/addons.make deleted file mode 100644 index 0b4df47..0000000 --- a/TRSS_02_rec/addons.make +++ /dev/null @@ -1,5 +0,0 @@ -ofxOpenNI -ofxFenster -ofxGui -ofxXmlSettings -ofxMayaCam diff --git a/TRSS_02_rec/config.make b/TRSS_02_rec/config.make deleted file mode 100755 index 821a73a..0000000 --- a/TRSS_02_rec/config.make +++ /dev/null @@ -1,56 +0,0 @@ -# add custom variables to this file - -# OF_ROOT allows to move projects outside apps/* just set this variable to the -# absoulte path to the OF root folder - -OF_ROOT = ../../openFrameworks - - -# USER_CFLAGS allows to pass custom flags to the compiler -# for example search paths like: -# USER_CFLAGS = -I src/objects - -USER_CFLAGS = -I $(OF_ROOT)/addons/ofxOpenNI/include/openni -I $(OF_ROOT)/addons/ofxOpenNI/include/nite -I $(OF_ROOT)/addons/ofxOpenNI/src - - -# USER_LDFLAGS allows to pass custom flags to the linker -# for example libraries like: -# USER_LDFLAGS = libs/libawesomelib.a - -USER_LDFLAGS = -lOpenNI - - -EXCLUDE_FROM_SOURCE="bin,.xcodeproj,obj" - -# change this to add different compiler optimizations to your project - -USER_COMPILER_OPTIMIZATION = -march=native -mtune=native -Os - - -# android specific, in case you want to use different optimizations -USER_LIBS_ARM = -USER_LIBS_ARM7 = -USER_LIBS_NEON = - -# android optimizations - -ANDROID_COMPILER_OPTIMIZATION = -Os - -NDK_PLATFORM = android-8 - -# uncomment this for custom application name (if the folder name is different than the application name) -#APPNAME = folderName - -# uncomment this for custom package name, must be the same as the java package that contains OFActivity -#PKGNAME = cc.openframeworks.$(APPNAME) - - - - - -# linux arm flags - -LINUX_ARM7_COMPILER_OPTIMIZATIONS = -march=armv7-a -mtune=cortex-a8 -finline-functions -funroll-all-loops -O3 -funsafe-math-optimizations -mfpu=neon -ftree-vectorize -mfloat-abi=hard -mfpu=vfp - - - diff --git a/TRSS_02_rec/src/main.cpp b/TRSS_02_rec/src/main.cpp deleted file mode 100644 index 87dc35f..0000000 --- a/TRSS_02_rec/src/main.cpp +++ /dev/null @@ -1,17 +0,0 @@ - -#include "testApp.h" -#include "ofMain.h" -#include "ofAppGlutWindow.h" - -//======================================================================== -int main( ){ - - ofAppGlutWindow window; - ofSetupOpenGL(&window, 1600,900, OF_FULLSCREEN); // <-------- setup the GL context - - // this kicks off the running of my app - // can be OF_WINDOW or OF_FULLSCREEN - // pass in width and height too: - ofRunApp( new testApp()); - -} diff --git a/TRSS_02_rec/src/testApp.cpp b/TRSS_02_rec/src/testApp.cpp deleted file mode 100644 index 376d357..0000000 --- a/TRSS_02_rec/src/testApp.cpp +++ /dev/null @@ -1,199 +0,0 @@ -#include "testApp.h" - -//-------------------------------------------------------------- -void testApp::setup() { - - ofSetLogLevel(OF_LOG_NOTICE); - - numDevices = openNIRecorders[0].getNumDevices(); - - for (int deviceID = 0; deviceID < numDevices; deviceID++){ - //openNIRecorders[deviceID].setLogLevel(OF_LOG_VERBOSE); - openNIRecorders[deviceID].setup(false); - openNIRecorders[deviceID].addDepthGenerator(); - openNIRecorders[deviceID].addImageGenerator(); - openNIRecorders[deviceID].setRegister(true); // this registers all the image pixels to the depth pixels - openNIRecorders[deviceID].setMirror(true); // flips the image and depth sensors - openNIRecorders[deviceID].start(); - - openNIPlayers[deviceID].setup(false); - openNIPlayers[deviceID].start(); - - filenames[deviceID]=""; - } - - isLive=true; - isRecording=false; - - verdana.loadFont(ofToDataPath("verdana.ttf"), 10); - - startSound.loadSound("tone1.wav"); - stopSound.loadSound("tone0.wav");; -} - - -string testApp::generateFileName(int cam) { - - string _root = "kinectRecord_"; - - string _timestamp = ofToString(ofGetDay()) + - ofToString(ofGetMonth()) + - ofToString(ofGetYear()) + - ofToString(ofGetHours()) + - ofToString(ofGetMinutes()) + - ofToString(ofGetSeconds()); - - string _filename = (_root + ofToString(cam)+"_"+_timestamp + ".oni"); - - return _filename; - -} - -//-------------------------------------------------------------- -void testApp::update(){ - for (int deviceID = 0; deviceID < numDevices; deviceID++){ - if (isLive) { - openNIRecorders[deviceID].update(); - if (isRecording){ - recorded++; - } - } - else { - openNIPlayers[deviceID].update(); - } - } -} - -//-------------------------------------------------------------- -void testApp::draw(){ - ofBackground(0, 0, 0); - ofSetColor(255, 255, 255); - - ofPushMatrix(); - - for (int deviceID = 0; deviceID < numDevices; deviceID++){ - ofTranslate(0, deviceID * 450); - if (isLive) { - //openNIRecorders[deviceID].drawDebug(); // draws all generators - openNIRecorders[deviceID].drawDepth(200, 0,600,450); - openNIRecorders[deviceID].drawImage(800, 0,600,450); - } - else { - //openNIPlayers[deviceID].drawDebug(); - openNIPlayers[deviceID].drawDepth(200, 0,600,450); - openNIPlayers[deviceID].drawImage(800, 0,600,450); - } - } - - ofPopMatrix(); - - ofSetColor(255, 255, 255); - string msg = "MILLIS: " + ofToString(ofGetElapsedTimeMillis()) + "\nFPS: " + ofToString(ofGetFrameRate()); - if (isRecording) { - msg +="\nrecorded "+ofToString(recorded); - } - if (!isLive) { - msg +="\n"+filenames[0]; - } - verdana.drawString(msg, 10, 10); -} - -//-------------------------------------------------------------- -void testApp::exit(){ - for (int deviceID = 0; deviceID < numDevices; deviceID++){ - openNIRecorders[deviceID].stop(); - openNIPlayers[deviceID].stop(); - } -} - -//-------------------------------------------------------------- -void testApp::keyPressed(int key){ - switch (key) { - case 's': - case 'S': - if (isRecording) { - for (int deviceID = 0; deviceID < numDevices; deviceID++){ - openNIRecorders[deviceID].stopRecording(); - stopSound.play(); - } - isRecording = false; - break; - } else { - for (int deviceID = 0; deviceID < numDevices; deviceID++){ - filenames[deviceID]=generateFileName(deviceID); - openNIRecorders[deviceID].startRecording(generateFileName(deviceID)); - startSound.play(); - } - isRecording = true; - recorded=0; - break; - } - break; - case 'p': - case 'P': - if (filenames[0] != "" && !isRecording && isLive) { - for (int deviceID = 0; deviceID < numDevices; deviceID++){ - openNIRecorders[deviceID].stopRecording(); - } - for (int deviceID = 0; deviceID < numDevices; deviceID++){ - openNIPlayers[deviceID].startPlayer(filenames[deviceID]); - } - isLive = false; - //whichUser=&playUser; - //whichImage=&playImage; - } else { - isLive = true; - //whichUser=&recordUser; - //whichImage=&recordImage; - } - break; - } - - /* why do this? - switch (key) { - case 't': - for (int deviceID = 0; deviceID < numDevices; deviceID++){ - openNIRecorders[deviceID].toggleRegister(); - } - break; - case 'x': - for (int deviceID = 0; deviceID < numDevices; deviceID++){ - openNIRecorders[deviceID].stop(); - } - break; - default: - break; - } - */ -} - -//-------------------------------------------------------------- -void testApp::keyReleased(int key){ - -} - -//-------------------------------------------------------------- -void testApp::mouseMoved(int x, int y ){ - -} - -//-------------------------------------------------------------- -void testApp::mouseDragged(int x, int y, int button){ - -} - -//-------------------------------------------------------------- -void testApp::mousePressed(int x, int y, int button){ - -} - -//-------------------------------------------------------------- -void testApp::mouseReleased(int x, int y, int button){ - -} - -//-------------------------------------------------------------- -void testApp::windowResized(int w, int h){ - -} - diff --git a/TRSS_02_rec/src/testApp.h b/TRSS_02_rec/src/testApp.h deleted file mode 100644 index ffb92e9..0000000 --- a/TRSS_02_rec/src/testApp.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _TEST_APP -#define _TEST_APP - -#include "ofxOpenNI.h" -#include "ofMain.h" - -#define MAX_DEVICES 2 - -class testApp : public ofBaseApp{ - -public: - void setup(); - void update(); - void draw(); - void exit(); - - void keyPressed (int key); - void keyReleased(int key); - void mouseMoved(int x, int y ); - void mouseDragged(int x, int y, int button); - void mousePressed(int x, int y, int button); - void mouseReleased(int x, int y, int button); - void windowResized(int w, int h); - string generateFileName(int cam); - - int numDevices; - ofxOpenNI openNIRecorders[MAX_DEVICES]; - ofxOpenNI openNIPlayers[MAX_DEVICES]; - string filenames[MAX_DEVICES]; - - bool isLive, isRecording; - - ofTrueTypeFont verdana; - - ofSoundPlayer startSound; - ofSoundPlayer stopSound; - - int recorded; - -}; - -#endif diff --git a/vamphost/Makefile b/vamphost/Makefile new file mode 100755 index 0000000..2d83a77 --- /dev/null +++ b/vamphost/Makefile @@ -0,0 +1,2 @@ +include config.make +include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/Makefile.examples diff --git a/vamphost/addons.make b/vamphost/addons.make new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/vamphost/addons.make @@ -0,0 +1 @@ + diff --git a/vamphost/config.make b/vamphost/config.make new file mode 100755 index 0000000..a4db95a --- /dev/null +++ b/vamphost/config.make @@ -0,0 +1,57 @@ +# add custom variables to this file + +# OF_ROOT allows to move projects outside apps/* just set this variable to the +# absoulte path to the OF root folder + +#OF_ROOT = ../../openFrameworks +OF_ROOT = /home/tim/workspace/openFrameworks + + +# USER_CFLAGS allows to pass custom flags to the compiler +# for example search paths like: +# USER_CFLAGS = -I src/objects + +USER_CFLAGS = -I $(OF_ROOT)/addons/ofxOpenNI/include/openni -I $(OF_ROOT)/addons/ofxOpenNI/include/nite -I $(OF_ROOT)/addons/ofxOpenNI/src + + +# USER_LDFLAGS allows to pass custom flags to the linker +# for example libraries like: +# USER_LDFLAGS = libs/libawesomelib.a + +USER_LDFLAGS = -lvamp-hostsdk + + +EXCLUDE_FROM_SOURCE="bin,.xcodeproj,obj" + +# change this to add different compiler optimizations to your project + +USER_COMPILER_OPTIMIZATION = -march=native -mtune=native -Os + + +# android specific, in case you want to use different optimizations +USER_LIBS_ARM = +USER_LIBS_ARM7 = +USER_LIBS_NEON = + +# android optimizations + +ANDROID_COMPILER_OPTIMIZATION = -Os + +NDK_PLATFORM = android-8 + +# uncomment this for custom application name (if the folder name is different than the application name) +#APPNAME = folderName + +# uncomment this for custom package name, must be the same as the java package that contains OFActivity +#PKGNAME = cc.openframeworks.$(APPNAME) + + + + + +# linux arm flags + +LINUX_ARM7_COMPILER_OPTIMIZATIONS = -march=armv7-a -mtune=cortex-a8 -finline-functions -funroll-all-loops -O3 -funsafe-math-optimizations -mfpu=neon -ftree-vectorize -mfloat-abi=hard -mfpu=vfp + + + diff --git a/vamphost/src/main.cpp b/vamphost/src/main.cpp new file mode 100644 index 0000000..1ef19ab --- /dev/null +++ b/vamphost/src/main.cpp @@ -0,0 +1,17 @@ + +#include "testApp.h" +#include "ofMain.h" +#include "ofAppGlutWindow.h" + +//======================================================================== +int main( ){ + + ofAppGlutWindow window; + ofSetupOpenGL(&window, 1024,768, OF_FULLSCREEN); // <-------- setup the GL context + + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + ofRunApp( new testApp()); + +} diff --git a/vamphost/src/ofxVamphost.cpp b/vamphost/src/ofxVamphost.cpp new file mode 100644 index 0000000..3da842b --- /dev/null +++ b/vamphost/src/ofxVamphost.cpp @@ -0,0 +1,212 @@ +#include "ofxVamphost.h" + +using namespace std; + +bool Vamphost::init(const string &soname,const string &id,const int &_channels,const int &_bits,const int &_samples,const int &_rate,const int &_outputNo,const string &_output){ + + //stuff that only happens once + channels =_channels; + samples=_samples; + rate=_rate; + bits=_bits; + outputNo=_outputNo; + output=_output; + + //http://www.mega-nerd.com/libsndfile/api.html#note1 + //libsndfile returns -1..1 for fp data + bytes=(bits>>3); + stride=channels*bytes; + scale=(1.0f/pow(2.0f,bits)); + + features[0.0f]=0; + + loader = PluginLoader::getInstance(); + key = loader->composePluginKey(soname, id); + plugin = loader->loadPlugin(key, _rate, PluginLoader::ADAPT_ALL_SAFE); + if (!plugin) { + cerr << ": ERROR: Failed to load plugin \"" << id + << "\" from library \"" << soname << "\"" << endl; + return false; + } + + cerr << "Running plugin: \"" << plugin->getIdentifier() << "\"..." << endl; + + blockSize = plugin->getPreferredBlockSize(); + stepSize = plugin->getPreferredStepSize(); + + if (blockSize == 0) { + blockSize = 1024; + } + if (stepSize == 0) { + if (plugin->getInputDomain() == Plugin::FrequencyDomain) { + stepSize = blockSize/2; + } else { + stepSize = blockSize; + } + } + else if (stepSize > blockSize) { + cerr << "WARNING: stepSize " << stepSize << " > blockSize " << blockSize << ", resetting blockSize to "; + if (plugin->getInputDomain() == Plugin::FrequencyDomain) { + blockSize = stepSize * 2; + } else { + blockSize = stepSize; + } + cerr << blockSize << endl; + } + overlapSize = blockSize - stepSize; + currentStep = 0; + finalStepsRemaining = max(1, (blockSize / stepSize) - 1); // at end of file, this many part-silent frames needed after we hit EOF + + plugbuf = new float*[channels]; + for (int c = 0; c < channels; ++c) plugbuf[c] = new float[blockSize + 2]; + + cerr << "Using block size = " << blockSize << ", step size = " + << stepSize << endl; + + // The channel queries here are for informational purposes only -- + // a PluginChannelAdapter is being used automatically behind the + // scenes, and it will take case of any channel mismatch + + int minch = plugin->getMinChannelCount(); + int maxch = plugin->getMaxChannelCount(); + cerr << "Plugin accepts " << minch << " -> " << maxch << " channel(s)" << endl; + cerr << "Sound file has " << channels << " (will mix/augment if necessary)" << endl; + + Plugin::OutputList outputs = plugin->getOutputDescriptors(); + Plugin::OutputDescriptor od; + + int returnValue = 1; + int prog = 0; + + RealTime rt; + PluginWrapper *wrapper = 0; + RealTime adjustment = RealTime::zeroTime; + + if (outputs.empty()) { + cerr << "ERROR: Plugin has no outputs!" << endl; + return false; + } + + if (outputNo < 0) { + for (size_t oi = 0; oi < outputs.size(); ++oi) { + if (outputs[oi].identifier == output) { + outputNo = oi; + break; + } + } + if (outputNo < 0) { + cerr << "ERROR: Non-existent output \"" << output << "\" requested" << endl; + return false; + } + } + else { + if (int(outputs.size()) <= outputNo) { + cerr << "ERROR: Output " << outputNo << " requested, but plugin has only " << outputs.size() << " output(s)" << endl; + return false; + } + } + od = outputs[outputNo]; + cerr << "Output is: \"" << od.identifier << "\"" << endl; + + if (!plugin->initialise(channels, stepSize, blockSize)) { + cerr << "ERROR: Plugin initialise (channels = " << channels + << ", stepSize = " << stepSize << ", blockSize = " + << blockSize << ") failed." << endl; + return false; + } + + wrapper = dynamic_cast(plugin); + if (wrapper) { + // See documentation for + // PluginInputDomainAdapter::getTimestampAdjustment + PluginInputDomainAdapter *ida =wrapper->getWrapper(); + if (ida) adjustment = ida->getTimestampAdjustment(); + } + + //everything is prepared to start consuming data in blocks + + in_block=0; + blocks_processed=0; + currentStep=0; + + featureNo=1; + + return true; +} +void Vamphost::process_frame(unsigned char *data,int samples_in_frame){ + int sample=0; + + //process the whole frame which may be f>1getIdentifier()<<" processed block "<process(plugbuf, rt); + + for (unsigned int i = 0; i < feat[outputNo].size(); ++i) { + features[((float)feat[outputNo][i].timestamp.sec)+(((float)feat[outputNo][i].timestamp.nsec)*.000000001)]=featureNo; + featureNo++; + } + + //shunt it down + for (int i=0;iprocess(plugbuf, rt); + + for (unsigned int i = 0; i < feat[outputNo].size(); ++i) { + features[((float)feat[outputNo][i].timestamp.sec)+(((float)feat[outputNo][i].timestamp.nsec)*.000000001)]=featureNo; + featureNo++; + } + + feat=plugin->getRemainingFeatures(); + + for (unsigned int i = 0; i < feat[outputNo].size(); ++i) { + features[((float)feat[outputNo][i].timestamp.sec)+(((float)feat[outputNo][i].timestamp.nsec)*.000000001)]=featureNo; + featureNo++; + } + + cerr<getIdentifier()<<" found "<<(features.size()-1)<<" features"< +#include +#include + +#include +#include + +using Vamp::Plugin; +using Vamp::PluginHostAdapter; +using Vamp::RealTime; +using Vamp::HostExt::PluginLoader; +using Vamp::HostExt::PluginWrapper; +using Vamp::HostExt::PluginInputDomainAdapter; + +#define HOST_VERSION "1.5" + +class Vamphost{ + //can load any vamp analysis plugin and present its data with a unified interface + public: + bool init(const std::string &soname,const std::string &id,const int &_channels,const int &_bits,const int &_samples,const int &_rate,const int &_outputNo=0,const std::string &_output=""); + void process_frame(unsigned char *data,int samples_in_frame); + void cleanup(); + + std::map features; + //map + //this is the best way to store features: because map allows to search for the key below and above the present time + + private: + PluginLoader *loader; + PluginLoader::PluginKey key; + Plugin *plugin; + RealTime rt; + int channels,bits,samples,rate; + int bytes,stride; + float scale; + int blockSize,stepSize,overlapSize,finalStepsRemaining,currentStep,outputNo; + int in_block,blocks_processed; + std::string output; + float **plugbuf; + + int featureNo; + +}; + +#endif + diff --git a/vamphost/src/testApp.cpp b/vamphost/src/testApp.cpp new file mode 100644 index 0000000..adf7416 --- /dev/null +++ b/vamphost/src/testApp.cpp @@ -0,0 +1,69 @@ +#include "testApp.h" + +//-------------------------------------------------------------- +void testApp::setup() { + + +} + + +//-------------------------------------------------------------- +void testApp::update(){ + +} + +//-------------------------------------------------------------- +void testApp::draw(){ + ofBackground(0, 0, 0); + ofSetColor(255, 255, 255); + + +} + +//-------------------------------------------------------------- +void testApp::exit(){ + +} + +//-------------------------------------------------------------- +void testApp::keyPressed(int key){ + switch (key) { + case 's': + case 'S': + break; + case 'p': + case 'P': + break; + } +} + +//-------------------------------------------------------------- +void testApp::keyReleased(int key){ + +} + +//-------------------------------------------------------------- +void testApp::mouseMoved(int x, int y ){ + +} + +//-------------------------------------------------------------- +void testApp::mouseDragged(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::mousePressed(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::mouseReleased(int x, int y, int button){ + +} + +//-------------------------------------------------------------- +void testApp::windowResized(int w, int h){ + +} + diff --git a/vamphost/src/testApp.h b/vamphost/src/testApp.h new file mode 100644 index 0000000..855889c --- /dev/null +++ b/vamphost/src/testApp.h @@ -0,0 +1,28 @@ +#ifndef _TEST_APP +#define _TEST_APP + +#include "ofMain.h" +#include "ofxVamphost.h" + + +class testApp : public ofBaseApp{ + +public: + void setup(); + void update(); + void draw(); + void exit(); + + void keyPressed (int key); + void keyReleased(int key); + void mouseMoved(int x, int y ); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void windowResized(int w, int h); + + + +}; + +#endif -- cgit v1.2.3