1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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;
};
|