diff options
| author | Tim Redfern <tim@getdrop.com> | 2018-05-22 00:00:06 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@getdrop.com> | 2018-05-22 00:00:06 +0100 |
| commit | 459d1daf71dd8991c60dc8c84d1154802eec331b (patch) | |
| tree | 0a8407a7aad9d4e8fbbd51287bb921f69ae1d073 /gistanalysis/src/ofApp.h | |
| parent | 880f710768391dc3a3399fc1896447a9e6c34fa4 (diff) | |
OE started
Diffstat (limited to 'gistanalysis/src/ofApp.h')
| -rw-r--r-- | gistanalysis/src/ofApp.h | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/gistanalysis/src/ofApp.h b/gistanalysis/src/ofApp.h new file mode 100644 index 0000000..e3ad339 --- /dev/null +++ b/gistanalysis/src/ofApp.h @@ -0,0 +1,132 @@ +#pragma once + +#include "ofMain.h" +#include "ofxHelios.h" +#include "lineTransformer.h" + +//This is included only as a way of getting buffer out of loaded sound. +//There are many other ways you can do that. +//This player includes a version of kissFFT. You can remove the one included in Gist. +//https://github.com/borg/ofxOpenALSoundPlayer +#include "ofxOpenALSoundPlayer.h" + + +//Slightly modified to add a dynamic getVariable method to be able to plot based on +//gist feature list +//https://github.com/local-projects/ofxHistoryPlot +#include "ofxHistoryPlot.h" +#include "ofxGist.h" + + +class Audioplotter{ + //store and draw a numbr of audio samples + //how best to handle transforms - maybe pass in a transform to be added to 2nd and subsequent + //how best to handle length of history data - fixed number that can be set, or line budget? +public: + Audioplotter(int _size=1,bool _joined=true){ + set_size(_size); + set_joined(_joined); + } + void set_size(int _size){ + history_size=_size; + } + void set_joined(bool _joined){ + joined=_joined; + } + const vector <colourPolyline> &output(const ofMatrix4x4 xform=ofMatrix4x4(1.0f,0.0f,0.0f,0.0f, + 0.0f,1.0f,0.0f,0.0f, + 0.0f,0.0f,1.0f,0.0f, + 0.0f,0.0f,0.0f,1.0f)){ + //destructive or non? + float fadefactor=1.0f-(1.0f/history_size); + + for (int i=0;i<data.size();i++){ + data[i]=lineTransformer::polyLineTransform(xform,data[i],fadefactor); + } + + return data; + } + void addpoints(vector <float> &audio,int number){ + colourPolyline newdata; + int num=min(number,(int)audio.size()); + int step=audio.size()/num; + int start=audio.size()/(num+1); + for (int i=0;i<num;i++){ + newdata.addVertex((start+(i*step)*ofGetWidth())/audio.size(),audio[start+(i*step)]*ofGetHeight()); + } + data.insert(data.begin(),newdata); + while (data.size()>history_size) { + data.pop_back(); + } + + } +private: + vector <colourPolyline> data; + bool joined; + int history_size; +}; + + +class ofApp : public ofBaseApp{ + + public: + void setup(); + void update(); + void draw(); + + 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); + void dragEvent(ofDragInfo dragInfo); + void gotMessage(ofMessage msg); + + ofSoundStream soundStream; + ofxOpenALSoundPlayer player; + void processAudio(float * input, int bufferSize, int nChannels); + + void audioIn(float * input, int bufferSize, int nChannels); + + vector<float>fftSmoothed; + vector <float> left; + vector <float> right; + vector <float> centre; + vector <float> volHistory; + vector<float>mfccSmoothed; + float mfccMax; + + + int bufferSize; + int sampleRate; + bool useMic; + + bool isPaused; + + void clear(); + void loadSong(string str); + + + vector<ofxHistoryPlot *>plots; + map<string,ofxHistoryPlot *>plotMap; + + ofxHistoryPlot* addGraph(string varName,float max,ofColor color); + + + ofxGist gist; + void onNoteOn(GistEvent &e); + void onNoteOff(GistEvent &e); + + int noteOnRadius; + + + bool showMFCC; + vector<ofxHistoryPlot *>mfccPlots; + + ofxHelios laser; + + Audioplotter plotter; + +}; |
