From 4ed19712765ddc959a86436c14cd1314bfb4f52a Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 13 Feb 2013 10:14:31 -0800 Subject: [PATCH] Made oscilloscope 2 channel, turned on by default (need to fix injecting the last audio buffer tho). --- interface/src/Audio.cpp | 10 +++++++++- interface/src/Oscilloscope.cpp | 25 ++++++++++++++++++------- interface/src/Oscilloscope.h | 6 +++--- interface/src/main.cpp | 4 ++-- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 9614d740ca..a0fa6a9660 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -104,7 +104,7 @@ int audioCallback (const void *inputBuffer, // if (scope->getState()) { 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(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) { AudioRingBuffer *ringBuffer = data->ringBuffer; diff --git a/interface/src/Oscilloscope.cpp b/interface/src/Oscilloscope.cpp index f5c90da4b2..34cf9a62c8 100644 --- a/interface/src/Oscilloscope.cpp +++ b/interface/src/Oscilloscope.cpp @@ -12,23 +12,34 @@ Oscilloscope::Oscilloscope(int w, int h, bool isOn) { width = w; height = h; - data = new float[width]; + data1 = new float[width]; + data2 = new float[width]; for (int i = 0; i < width; i++) { - data[i] = 0.0; + data1[i] = 0.0; + data2[i] = 0.0; } state = isOn; current_sample = 0; } -void Oscilloscope::addData(float d, int position) { - data[position] = d; +void Oscilloscope::addData(float d, int channel, int position) { + if (channel == 1) data1[position] = d; + else data2[position] = d; } -void Oscilloscope::render(float r, float g, float b) { - glColor3f(r,g,b); +void Oscilloscope::render() { + glColor3f(1,1,1); glBegin(GL_LINES); 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(); + + glColor3f(0,1,1); + glBegin(GL_LINES); + for (int i = 0; i < width; i++) { + glVertex2f((float)i, height/2 + data2[i]*(float)height); + } + glEnd(); + } \ No newline at end of file diff --git a/interface/src/Oscilloscope.h b/interface/src/Oscilloscope.h index 6bbeed2a54..503707e990 100644 --- a/interface/src/Oscilloscope.h +++ b/interface/src/Oscilloscope.h @@ -19,14 +19,14 @@ class Oscilloscope { public: Oscilloscope(int width, int height, bool isOn); - void addData(float d, int position); - void render(float r, float g, float b); + void addData(float d, int channel, int position); + void render(); void setState(bool s) {state = s;}; bool getState() {return state;}; private: int width; int height; - float * data; + float *data1, *data2; int current_sample; bool state; }; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 4058575205..dc8fcc25df 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -79,7 +79,7 @@ int WIDTH = 1200; int HEIGHT = 800; 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 Head myHead; // The rendered head of oneself @@ -621,7 +621,7 @@ void display(void) // lattice.render(WIDTH, HEIGHT); // myFinger.render(); 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);