Made oscilloscope 2 channel, turned on by default (need to fix injecting the last audio buffer tho).

This commit is contained in:
Philip Rosedale 2013-02-13 10:14:31 -08:00
parent 53a3d1f8c9
commit 4ed1971276
4 changed files with 32 additions and 13 deletions

View file

@ -104,7 +104,7 @@ int audioCallback (const void *inputBuffer,
// //
if (scope->getState()) { if (scope->getState()) {
for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) { for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) {
scope->addData((float)inputLeft[i]/32767.0, i); scope->addData((float)inputLeft[i]/32767.0, 1, i);
} }
} }
} }
@ -115,6 +115,14 @@ int audioCallback (const void *inputBuffer,
memset(outputLeft, 0, BUFFER_LENGTH_BYTES); memset(outputLeft, 0, BUFFER_LENGTH_BYTES);
memset(outputRight, 0, BUFFER_LENGTH_BYTES); memset(outputRight, 0, BUFFER_LENGTH_BYTES);
// Copy output data to oscilloscope
if (scope->getState()) {
for (int i = 0; i < BUFFER_LENGTH_SAMPLES; i++) {
scope->addData((float)outputRight[i]/32767.0, 2, i);
}
}
if (ECHO_SERVER_TEST) { if (ECHO_SERVER_TEST) {
AudioRingBuffer *ringBuffer = data->ringBuffer; AudioRingBuffer *ringBuffer = data->ringBuffer;

View file

@ -12,23 +12,34 @@ Oscilloscope::Oscilloscope(int w,
int h, bool isOn) { int h, bool isOn) {
width = w; width = w;
height = h; height = h;
data = new float[width]; data1 = new float[width];
data2 = new float[width];
for (int i = 0; i < width; i++) { for (int i = 0; i < width; i++) {
data[i] = 0.0; data1[i] = 0.0;
data2[i] = 0.0;
} }
state = isOn; state = isOn;
current_sample = 0; current_sample = 0;
} }
void Oscilloscope::addData(float d, int position) { void Oscilloscope::addData(float d, int channel, int position) {
data[position] = d; if (channel == 1) data1[position] = d;
else data2[position] = d;
} }
void Oscilloscope::render(float r, float g, float b) { void Oscilloscope::render() {
glColor3f(r,g,b); glColor3f(1,1,1);
glBegin(GL_LINES); glBegin(GL_LINES);
for (int i = 0; i < width; i++) { for (int i = 0; i < width; i++) {
glVertex2f((float)i, height/2 + data[i]*(float)height); glVertex2f((float)i, height/2 + data1[i]*(float)height);
} }
glEnd(); glEnd();
glColor3f(0,1,1);
glBegin(GL_LINES);
for (int i = 0; i < width; i++) {
glVertex2f((float)i, height/2 + data2[i]*(float)height);
}
glEnd();
} }

View file

@ -19,14 +19,14 @@ class Oscilloscope {
public: public:
Oscilloscope(int width, Oscilloscope(int width,
int height, bool isOn); int height, bool isOn);
void addData(float d, int position); void addData(float d, int channel, int position);
void render(float r, float g, float b); void render();
void setState(bool s) {state = s;}; void setState(bool s) {state = s;};
bool getState() {return state;}; bool getState() {return state;};
private: private:
int width; int width;
int height; int height;
float * data; float *data1, *data2;
int current_sample; int current_sample;
bool state; bool state;
}; };

View file

@ -79,7 +79,7 @@ int WIDTH = 1200;
int HEIGHT = 800; int HEIGHT = 800;
int fullscreen = 0; int fullscreen = 0;
Oscilloscope audioScope(512,200,false); Oscilloscope audioScope(512,200,true);
#define HAND_RADIUS 0.25 // Radius of in-world 'hand' of you #define HAND_RADIUS 0.25 // Radius of in-world 'hand' of you
Head myHead; // The rendered head of oneself Head myHead; // The rendered head of oneself
@ -621,7 +621,7 @@ void display(void)
// lattice.render(WIDTH, HEIGHT); // lattice.render(WIDTH, HEIGHT);
// myFinger.render(); // myFinger.render();
Audio::render(WIDTH, HEIGHT); Audio::render(WIDTH, HEIGHT);
if (audioScope.getState()) audioScope.render(0,1,0); if (audioScope.getState()) audioScope.render();
//drawvec3(100, 100, 0.15, 0, 1.0, 0, myHead.getPos(), 0, 1, 0); //drawvec3(100, 100, 0.15, 0, 1.0, 0, myHead.getPos(), 0, 1, 0);