mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 06:53:46 +02:00
adds 'Oscilloscope::setColor' and uses it when visualizing echo cancellation
This commit is contained in:
parent
7588b7f6bb
commit
9c54ef18d3
3 changed files with 21 additions and 6 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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__) */
|
||||
|
|
Loading…
Reference in a new issue