adds 'Oscilloscope::setColor' and uses it when visualizing echo cancellation

This commit is contained in:
tosh 2013-06-20 03:15:01 +02:00
parent 7588b7f6bb
commit 9c54ef18d3
3 changed files with 21 additions and 6 deletions

View file

@ -109,7 +109,7 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o
// add input (@microphone) data to the scope // add input (@microphone) data to the scope
#ifdef VISUALIZE_ECHO_CANCELLATION #ifdef VISUALIZE_ECHO_CANCELLATION
if (! _isCancellingEcho || _pingFramesToRecord != 0 || ! _speexPreprocessState) { if (! isCancellingEcho()) {
#endif #endif
_scope->addSamples(0, inputLeft, BUFFER_LENGTH_SAMPLES_PER_CHANNEL); _scope->addSamples(0, inputLeft, BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
#ifdef VISUALIZE_ECHO_CANCELLATION #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 // add output (@speakers) data just written to the scope
#ifdef VISUALIZE_ECHO_CANCELLATION #ifdef VISUALIZE_ECHO_CANCELLATION
if (! _isCancellingEcho || _pingFramesToRecord != 0 || ! _speexPreprocessState) { if (! isCancellingEcho()) {
_scope->setColor(2, 0x00ffff);
#endif #endif
_scope->addSamples(1, outputLeft, BUFFER_LENGTH_SAMPLES_PER_CHANNEL); _scope->addSamples(1, outputLeft, BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
_scope->addSamples(2, outputRight, 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) { void Audio::setIsCancellingEcho(bool enable) {
if (enable) { if (enable && _speexPreprocessState) {
speex_echo_state_reset(_speexEchoState); speex_echo_state_reset(_speexEchoState);
_echoWritePos = 0; _echoWritePos = 0;
memset(_echoSamplesLeft, 0, AEC_BUFFERED_SAMPLES * sizeof(int16_t)); memset(_echoSamplesLeft, 0, AEC_BUFFERED_SAMPLES * sizeof(int16_t));
@ -592,6 +593,7 @@ inline void Audio::eventuallyCancelEcho(int16_t* inputLeft) {
#ifdef VISUALIZE_ECHO_CANCELLATION #ifdef VISUALIZE_ECHO_CANCELLATION
// Visualize the result // Visualize the result
_scope->setColor(2, 0x00ff00);
_scope->addSamples(2, inputLeft, BUFFER_LENGTH_SAMPLES_PER_CHANNEL); _scope->addSamples(2, inputLeft, BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
#endif #endif
} }

View file

@ -54,6 +54,10 @@ Oscilloscope::Oscilloscope(int w, int h, bool isEnabled) :
for (unsigned ch = 0; ch < MAX_CHANNELS; ++ch) { for (unsigned ch = 0; ch < MAX_CHANNELS; ++ch) {
_writePos[ch] = MAX_SAMPLES_PER_CHANNEL * ch; _writePos[ch] = MAX_SAMPLES_PER_CHANNEL * ch;
} }
_colors[0] = 0xffffff;
_colors[1] = 0x00ffff;
_colors[2] = 0x00ffff;
} }
Oscilloscope::~Oscilloscope() { Oscilloscope::~Oscilloscope() {
@ -138,17 +142,22 @@ void Oscilloscope::render(int x, int y) {
glScaled(1.0f, _height / 32767.0f, 1.0f); glScaled(1.0f, _height / 32767.0f, 1.0f);
glVertexPointer(2, GL_SHORT, 0, _vertices); glVertexPointer(2, GL_SHORT, 0, _vertices);
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_INDEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
// render channel 0 // 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); glDrawArrays(GL_LINES, MAX_SAMPLES_PER_CHANNEL * 0, usedWidth);
// render channel 1 // render channel 1
glColor3f(0.0f, 1.0f ,1.0f); 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); glDrawArrays(GL_LINES, MAX_SAMPLES_PER_CHANNEL * 1, usedWidth);
// render channel 2 // 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); glDrawArrays(GL_LINES, MAX_SAMPLES_PER_CHANNEL * 2, usedWidth);
// reset rendering state // reset rendering state

View file

@ -28,6 +28,9 @@ public:
static unsigned const MAX_CHANNELS = 3; static unsigned const MAX_CHANNELS = 3;
static unsigned const MAX_SAMPLES_PER_CHANNEL = 4096; 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 // Controls a simple one pole IIR low pass filter that is provided to
// reduce high frequencies aliasing (to lower ones) when downsampling. // 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 // Sets the number of input samples per output sample. Without filtering
// just uses every nTh sample. // just uses every nTh sample.
void setDownsampleRatio(unsigned n) { assert(n > 0); _downsampleRatio = n; } void setDownsampleRatio(unsigned n) { assert(n > 0); _downsampleRatio = n; }
private: private:
// don't copy/assign // don't copy/assign
Oscilloscope(Oscilloscope const&); // = delete; Oscilloscope(Oscilloscope const&); // = delete;
@ -70,6 +73,7 @@ private:
float _lowPassCoeff; float _lowPassCoeff;
unsigned _downsampleRatio; unsigned _downsampleRatio;
unsigned _colors[MAX_CHANNELS];
}; };
#endif /* defined(__interface__oscilloscope__) */ #endif /* defined(__interface__oscilloscope__) */