From 9c54ef18d39fa08671d2708146f8923e5107daa5 Mon Sep 17 00:00:00 2001 From: tosh Date: Thu, 20 Jun 2013 03:15:01 +0200 Subject: [PATCH] adds 'Oscilloscope::setColor' and uses it when visualizing echo cancellation --- interface/src/Audio.cpp | 8 +++++--- interface/src/Oscilloscope.cpp | 13 +++++++++++-- interface/src/Oscilloscope.h | 6 +++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 62131c7d3f..533b6e9e3b 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -109,7 +109,7 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o // add input (@microphone) data to the scope #ifdef VISUALIZE_ECHO_CANCELLATION - if (! _isCancellingEcho || _pingFramesToRecord != 0 || ! _speexPreprocessState) { + if (! isCancellingEcho()) { #endif _scope->addSamples(0, inputLeft, BUFFER_LENGTH_SAMPLES_PER_CHANNEL); #ifdef VISUALIZE_ECHO_CANCELLATION @@ -259,7 +259,8 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o // add output (@speakers) data just written to the scope #ifdef VISUALIZE_ECHO_CANCELLATION - if (! _isCancellingEcho || _pingFramesToRecord != 0 || ! _speexPreprocessState) { + if (! isCancellingEcho()) { + _scope->setColor(2, 0x00ffff); #endif _scope->addSamples(1, outputLeft, BUFFER_LENGTH_SAMPLES_PER_CHANNEL); _scope->addSamples(2, outputRight, BUFFER_LENGTH_SAMPLES_PER_CHANNEL); @@ -549,7 +550,7 @@ bool Audio::isCancellingEcho() const { } void Audio::setIsCancellingEcho(bool enable) { - if (enable) { + if (enable && _speexPreprocessState) { speex_echo_state_reset(_speexEchoState); _echoWritePos = 0; memset(_echoSamplesLeft, 0, AEC_BUFFERED_SAMPLES * sizeof(int16_t)); @@ -592,6 +593,7 @@ inline void Audio::eventuallyCancelEcho(int16_t* inputLeft) { #ifdef VISUALIZE_ECHO_CANCELLATION // Visualize the result + _scope->setColor(2, 0x00ff00); _scope->addSamples(2, inputLeft, BUFFER_LENGTH_SAMPLES_PER_CHANNEL); #endif } diff --git a/interface/src/Oscilloscope.cpp b/interface/src/Oscilloscope.cpp index e2f90325f9..ebaddbbb04 100644 --- a/interface/src/Oscilloscope.cpp +++ b/interface/src/Oscilloscope.cpp @@ -54,6 +54,10 @@ Oscilloscope::Oscilloscope(int w, int h, bool isEnabled) : for (unsigned ch = 0; ch < MAX_CHANNELS; ++ch) { _writePos[ch] = MAX_SAMPLES_PER_CHANNEL * ch; } + + _colors[0] = 0xffffff; + _colors[1] = 0x00ffff; + _colors[2] = 0x00ffff; } Oscilloscope::~Oscilloscope() { @@ -138,17 +142,22 @@ void Oscilloscope::render(int x, int y) { glScaled(1.0f, _height / 32767.0f, 1.0f); glVertexPointer(2, GL_SHORT, 0, _vertices); glEnableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glDisableClientState(GL_INDEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); // render channel 0 - glColor3f(1.0f, 1.0f, 1.0f); + glColor3ub(GLubyte(_colors[0] >> 16), GLubyte((_colors[0] >> 8) & 0xff), GLubyte(_colors[0] & 0xff)); glDrawArrays(GL_LINES, MAX_SAMPLES_PER_CHANNEL * 0, usedWidth); // render channel 1 glColor3f(0.0f, 1.0f ,1.0f); + glColor3ub(GLubyte(_colors[1] >> 16), GLubyte((_colors[1] >> 8) & 0xff), GLubyte(_colors[1] & 0xff)); glDrawArrays(GL_LINES, MAX_SAMPLES_PER_CHANNEL * 1, usedWidth); // render channel 2 - glColor3f(0.0f, 1.0f ,0.0f); + glColor3ub(GLubyte(_colors[2] >> 16), GLubyte((_colors[2] >> 8) & 0xff), GLubyte(_colors[2] & 0xff)); glDrawArrays(GL_LINES, MAX_SAMPLES_PER_CHANNEL * 2, usedWidth); // reset rendering state diff --git a/interface/src/Oscilloscope.h b/interface/src/Oscilloscope.h index 65616e701b..d81fc11358 100644 --- a/interface/src/Oscilloscope.h +++ b/interface/src/Oscilloscope.h @@ -28,6 +28,9 @@ public: static unsigned const MAX_CHANNELS = 3; static unsigned const MAX_SAMPLES_PER_CHANNEL = 4096; + // Sets the color for a specific channel. + void setColor(unsigned ch, unsigned rgb) { assert(ch < MAX_CHANNELS); if (! inputPaused) { _colors[ch] = rgb; } } + // Controls a simple one pole IIR low pass filter that is provided to // reduce high frequencies aliasing (to lower ones) when downsampling. // @@ -54,7 +57,7 @@ public: // Sets the number of input samples per output sample. Without filtering // just uses every nTh sample. void setDownsampleRatio(unsigned n) { assert(n > 0); _downsampleRatio = n; } - + private: // don't copy/assign Oscilloscope(Oscilloscope const&); // = delete; @@ -70,6 +73,7 @@ private: float _lowPassCoeff; unsigned _downsampleRatio; + unsigned _colors[MAX_CHANNELS]; }; #endif /* defined(__interface__oscilloscope__) */