From 61b213804aca492d35d9568e87cf8e7dd905bdad Mon Sep 17 00:00:00 2001 From: stojce Date: Sat, 5 Oct 2013 13:18:35 +0200 Subject: [PATCH 1/2] #19426 - Add a mute control to the interface - OpenGL overlay icon - mute control - icons --- interface/resources/images/mic-tool.svg | 20 ++++++ interface/resources/images/mic.svg | 20 ++++++ interface/resources/images/mute.svg | 20 ++++++ interface/src/Application.cpp | 11 +++- interface/src/Audio.cpp | 87 ++++++++++++++++++++++--- interface/src/Audio.h | 14 ++++ 6 files changed, 160 insertions(+), 12 deletions(-) create mode 100644 interface/resources/images/mic-tool.svg create mode 100644 interface/resources/images/mic.svg create mode 100644 interface/resources/images/mute.svg diff --git a/interface/resources/images/mic-tool.svg b/interface/resources/images/mic-tool.svg new file mode 100644 index 0000000000..956b12dff3 --- /dev/null +++ b/interface/resources/images/mic-tool.svg @@ -0,0 +1,20 @@ + + + Slice 1 + Created with Sketch (http://www.bohemiancoding.com/sketch) + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/interface/resources/images/mic.svg b/interface/resources/images/mic.svg new file mode 100644 index 0000000000..a6dee50740 --- /dev/null +++ b/interface/resources/images/mic.svg @@ -0,0 +1,20 @@ + + + Mic + Created with Sketch (http://www.bohemiancoding.com/sketch) + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/interface/resources/images/mute.svg b/interface/resources/images/mute.svg new file mode 100644 index 0000000000..1f1b238463 --- /dev/null +++ b/interface/resources/images/mute.svg @@ -0,0 +1,20 @@ + + + mute + Created with Sketch (http://www.bohemiancoding.com/sketch) + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 615fcfaa01..5597d708bc 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -971,7 +971,12 @@ void Application::mousePressEvent(QMouseEvent* event) { _mousePressed = true; maybeEditVoxelUnderCursor(); - + + if (_audio.mousePressEvent(_mouseX, _mouseY)) { + // stop propagation + return; + } + if (!_palette.isActive() && (!_isHoverVoxel || _lookatTargetAvatar)) { _pieMenu.mousePressEvent(_mouseX, _mouseY); } @@ -1607,6 +1612,8 @@ void Application::init() { _followMode = new QAction(this); connect(_followMode, SIGNAL(triggered()), this, SLOT(toggleFollowMode())); _pieMenu.addAction(_followMode); + + _audio.init(_glWidget); } @@ -2655,7 +2662,7 @@ void Application::displayOverlay() { #ifndef _WIN32 _audio.render(_glWidget->width(), _glWidget->height()); if (Menu::getInstance()->isOptionChecked(MenuOption::Oscilloscope)) { - _audioScope.render(20, _glWidget->height() - 200); + _audioScope.render(45, _glWidget->height() - 200); } #endif diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index d98577eaaf..bea12af25e 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "Application.h" #include "Audio.h" @@ -69,6 +70,10 @@ static const int PING_FRAMES_TO_RECORD = AEC_BUFFERED_FRAMES; static const int PING_SAMPLES_TO_ANALYZE = AEC_BUFFERED_SAMPLES_PER_CHANNEL; // Samples to analyze (reusing AEC buffer) static const int PING_BUFFER_OFFSET = BUFFER_LENGTH_SAMPLES_PER_CHANNEL - PING_PERIOD * 2.0f; // Signal start +// Mute icon configration +static const int ICON_SIZE = 24; +static const int ICON_LEFT = 20; +static const int BOTTOM_PADDING = 110; inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* outputRight) { @@ -84,17 +89,19 @@ inline void Audio::performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* o if (nodeList && inputLeft) { - // Measure the loudness of the signal from the microphone and store in audio object - float loudness = 0; - for (int i = 0; i < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; i++) { - loudness += abs(inputLeft[i]); + if (!_muted) { + // Measure the loudness of the signal from the microphone and store in audio object + float loudness = 0; + for (int i = 0; i < BUFFER_LENGTH_SAMPLES_PER_CHANNEL; i++) { + loudness += abs(inputLeft[i]); + } + + loudness /= BUFFER_LENGTH_SAMPLES_PER_CHANNEL; + _lastInputLoudness = loudness; + + // add input (@microphone) data to the scope + _scope->addSamples(0, inputLeft, BUFFER_LENGTH_SAMPLES_PER_CHANNEL); } - - loudness /= BUFFER_LENGTH_SAMPLES_PER_CHANNEL; - _lastInputLoudness = loudness; - - // add input (@microphone) data to the scope - _scope->addSamples(0, inputLeft, BUFFER_LENGTH_SAMPLES_PER_CHANNEL); Node* audioMixer = nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER); @@ -323,6 +330,11 @@ int Audio::audioCallback (const void* inputBuffer, return paContinue; } +void Audio::init(QGLWidget *parent) { + switchToResourcesParentIfRequired(); + _micTextureId = parent->bindTexture(QImage("./resources/images/mic.svg")); + _muteTextureId = parent->bindTexture(QImage("./resources/images/mute.svg")); +} static void outputPortAudioError(PaError error) { if (error != paNoError) { @@ -384,6 +396,7 @@ Audio::Audio(Oscilloscope* scope, int16_t initialJitterBufferSamples) : _collisionSoundDuration(0.0f), _proceduralEffectSample(0), _heartbeatMagnitude(0.0f), + _muted(false), _listenMode(AudioRingBuffer::NORMAL), _listenRadius(0.0f) { @@ -515,6 +528,14 @@ void Audio::addReceivedAudioToBuffer(unsigned char* receivedData, int receivedBy _lastReceiveTime = currentReceiveTime; } +bool Audio::mousePressEvent(int x, int y) { + if (_iconBounds.contains(x, y)) { + _muted = !_muted; + return true; + } + return false; +} + void Audio::render(int screenWidth, int screenHeight) { if (_stream) { glLineWidth(2.0); @@ -609,6 +630,7 @@ void Audio::render(int screenWidth, int screenHeight) { glEnd(); } + renderToolIcon(screenHeight); } // @@ -856,4 +878,49 @@ bool Audio::eventuallyAnalyzePing() { return true; } +void Audio::renderToolIcon(int screenHeigh) { + + _iconBounds = QRect(ICON_LEFT, screenHeigh - BOTTOM_PADDING, ICON_SIZE, ICON_SIZE); + glEnable(GL_TEXTURE_2D); + + glBindTexture(GL_TEXTURE_2D, _micTextureId); + glColor3f(1, 1, 1); + glBegin(GL_QUADS); + + glTexCoord2f(1, 1); + glVertex2f(_iconBounds.left(), _iconBounds.top()); + + glTexCoord2f(0, 1); + glVertex2f(_iconBounds.right(), _iconBounds.top()); + + glTexCoord2f(0, 0); + glVertex2f(_iconBounds.right(), _iconBounds.bottom()); + + glTexCoord2f(1, 0); + glVertex2f(_iconBounds.left(), _iconBounds.bottom()); + + glEnd(); + + if (_muted) { + glBindTexture(GL_TEXTURE_2D, _muteTextureId); + glBegin(GL_QUADS); + + glTexCoord2f(1, 1); + glVertex2f(_iconBounds.left(), _iconBounds.top()); + + glTexCoord2f(0, 1); + glVertex2f(_iconBounds.right(), _iconBounds.top()); + + glTexCoord2f(0, 0); + glVertex2f(_iconBounds.right(), _iconBounds.bottom()); + + glTexCoord2f(1, 0); + glVertex2f(_iconBounds.left(), _iconBounds.bottom()); + + glEnd(); + } + + glDisable(GL_TEXTURE_2D); +} + #endif diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 8409f5ca84..7c66c7e375 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -12,6 +12,8 @@ #include #include +#include "InterfaceConfig.h" + #include #include @@ -21,6 +23,8 @@ #include "Oscilloscope.h" +#include + static const int NUM_AUDIO_CHANNELS = 2; static const int PACKET_LENGTH_BYTES = 1024; @@ -56,6 +60,9 @@ public: float getCollisionSoundMagnitude() { return _collisionSoundMagnitude; } void ping(); + + void init(QGLWidget *parent = 0); + bool mousePressEvent(int x, int y); // Call periodically to eventually perform round trip time analysis, // in which case 'true' is returned - otherwise the return value is 'false'. @@ -69,6 +76,7 @@ public: void clearListenSources(); private: + PaStream* _stream; AudioRingBuffer _ringBuffer; Oscilloscope* _scope; @@ -103,6 +111,11 @@ private: float _collisionSoundDuration; int _proceduralEffectSample; float _heartbeatMagnitude; + + bool _muted; + GLuint _micTextureId; + GLuint _muteTextureId; + QRect _iconBounds; AudioRingBuffer::ListenMode _listenMode; float _listenRadius; @@ -130,6 +143,7 @@ private: PaStreamCallbackFlags statusFlags, void *userData); + void renderToolIcon(int screenHeight); }; From 7ce483b658e6dd78ef18910d6686f9a0aae9423d Mon Sep 17 00:00:00 2001 From: stojce Date: Sat, 5 Oct 2013 13:21:34 +0200 Subject: [PATCH 2/2] remove unused resource --- interface/resources/images/mic-tool.svg | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 interface/resources/images/mic-tool.svg diff --git a/interface/resources/images/mic-tool.svg b/interface/resources/images/mic-tool.svg deleted file mode 100644 index 956b12dff3..0000000000 --- a/interface/resources/images/mic-tool.svg +++ /dev/null @@ -1,20 +0,0 @@ - - - Slice 1 - Created with Sketch (http://www.bohemiancoding.com/sketch) - - - - - - - - - - - - - - - - \ No newline at end of file