From c43847946c12da9761b1df95a45f19c15af23877 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 16 May 2013 20:31:17 -0600 Subject: [PATCH 1/4] Tweaked mouse camera movement a bit --- interface/src/Avatar.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 0e7cad3f05..8dc8ee7324 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -280,9 +280,9 @@ bool Avatar::getIsNearInteractingOther() { void Avatar::updateFromMouse(int mouseX, int mouseY, int screenWidth, int screenHeight) { // Update yaw based on mouse behavior - const float MOUSE_MOVE_RADIUS = 0.25f; - const float MOUSE_ROTATE_SPEED = 5.0f; - const float MOUSE_PITCH_SPEED = 3.0f; + const float MOUSE_MOVE_RADIUS = 0.15f; + const float MOUSE_ROTATE_SPEED = 3.0f; + const float MOUSE_PITCH_SPEED = 1.5f; const float MAX_YAW_TO_ADD = 180.f; const int TITLE_BAR_HEIGHT = 46; float mouseLocationX = (float)mouseX / (float)screenWidth - 0.5f; From d9cc07cf172b4f2f36869af1dd0f188840fb47bd Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Sat, 18 May 2013 12:33:21 -0700 Subject: [PATCH 2/4] Working on audio echo cancellation --- interface/src/Application.cpp | 2 +- interface/src/Audio.cpp | 40 ++++++++++++++++++++--------------- interface/src/Audio.h | 10 ++++++--- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c70b674f38..7a9faa54f6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1662,7 +1662,7 @@ void Application::displayOverlay() { #ifndef _WIN32 _audio.render(_glWidget->width(), _glWidget->height()); _audioScope.render(20, _glWidget->height() - 200); - //_audio.renderEchoCompare(); // PER: Will turn back on to further test echo + _audio.renderEchoCompare(); // PER: Will turn back on to further test echo #endif //noiseTest(_glWidget->width(), _glWidget->height()); diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 5bca301552..c64701d67e 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -99,12 +99,21 @@ int audioCallback (const void* inputBuffer, parentAudio->_scope->addSamples(2, outputRight, PACKET_LENGTH_SAMPLES_PER_CHANNEL); // if needed, add input/output data to echo analysis buffers - if (parentAudio->_isGatheringEchoFrames) { - memcpy(parentAudio->_echoInputSamples, inputLeft, + if (parentAudio->_echoInputFrameCountdown > 0) { + if (--parentAudio->_echoInputFrameCountdown == 0) { + memcpy(parentAudio->_echoInputSamples, inputLeft, PACKET_LENGTH_SAMPLES_PER_CHANNEL * sizeof(int16_t)); + parentAudio->_echoInputFrameCountdown = 0; + printLog("got input\n"); + } + } + + if (parentAudio->_isGatheringEchoOutputFrames) { memcpy(parentAudio->_echoOutputSamples, outputLeft, PACKET_LENGTH_SAMPLES_PER_CHANNEL * sizeof(int16_t)); - parentAudio->addedPingFrame(); + parentAudio->_isGatheringEchoOutputFrames = false; + parentAudio->_echoInputFrameCountdown = 2; + printLog("got output\n"); } if (inputLeft != NULL) { @@ -273,7 +282,10 @@ int audioCallback (const void* inputBuffer, for (int s = 0; s < PACKET_LENGTH_SAMPLES_PER_CHANNEL; s++) { outputLeft[s] = outputRight[s] = (int16_t)(sinf((float) s / PING_PITCH) * PING_VOLUME); } - parentAudio->_isGatheringEchoFrames = true; + printLog("Send echo ping\n"); + parentAudio->_isSendingEchoPing = false; + parentAudio->_isGatheringEchoOutputFrames = true; + } gettimeofday(&parentAudio->_lastCallbackTime, NULL); return paContinue; @@ -293,6 +305,9 @@ Audio::Audio(Oscilloscope* scope) : _scope(scope), _averagedLatency(0.0), _measuredJitter(0), + _jitterBufferLengthMsecs(12.0), + _jitterBufferSamples(_jitterBufferLengthMsecs * + NUM_AUDIO_CHANNELS * (SAMPLE_RATE / 1000.0)), _wasStarved(0), _lastInputLoudness(0), _mixerLoopbackFlag(false), @@ -303,8 +318,8 @@ Audio::Audio(Oscilloscope* scope) : _packetsReceivedThisPlayback(0), _shouldStartEcho(false), _isSendingEchoPing(false), - _echoPingFrameCount(0), - _isGatheringEchoFrames(false) + _echoInputFrameCountdown(0), + _isGatheringEchoOutputFrames(false) { outputPortAudioError(Pa_Initialize()); outputPortAudioError(Pa_OpenDefaultStream(&_stream, @@ -376,20 +391,11 @@ void Audio::addProceduralSounds(int16_t* inputBuffer, int numSamples) { void Audio::startEchoTest() { _shouldStartEcho = true; - _echoPingFrameCount = 0; _isSendingEchoPing = true; - _isGatheringEchoFrames = false; + _isGatheringEchoOutputFrames = false; + } -void Audio::addedPingFrame() { - const int ECHO_PING_FRAMES = 1; - _echoPingFrameCount++; - if (_echoPingFrameCount == ECHO_PING_FRAMES) { - _isGatheringEchoFrames = false; - _isSendingEchoPing = false; - //startEchoTest(); - } -} void Audio::analyzeEcho(int16_t* inputBuffer, int16_t* outputBuffer, int numSamples) { // Compare output and input streams, looking for evidence of correlation needing echo cancellation // diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 2eae70bb34..34a342a1d4 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -38,7 +38,6 @@ public: void addReceivedAudioToBuffer(unsigned char* receivedData, int receivedBytes); void startEchoTest(); - void addedPingFrame(); void renderEchoCompare(); private: @@ -49,6 +48,8 @@ private: timeval _lastReceiveTime; float _averagedLatency; float _measuredJitter; + float _jitterBufferLengthMsecs; + short _jitterBufferSamples; int _wasStarved; float _lastInputLoudness; bool _mixerLoopbackFlag; @@ -57,12 +58,15 @@ private: int _totalPacketsReceived; timeval _firstPlaybackTime; int _packetsReceivedThisPlayback; + // Echo Analysis bool _shouldStartEcho; bool _isSendingEchoPing; - int _echoPingFrameCount; int16_t* _echoInputSamples; int16_t* _echoOutputSamples; - bool _isGatheringEchoFrames; + int _echoInputFrameCountdown; + bool _isGatheringEchoOutputFrames; + + // give access to AudioData class from audioCallback friend int audioCallback (const void*, void*, unsigned long, const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags, void*); From 50ee9b9ee492278d07df898c1d3965c2c351a0aa Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 20 May 2013 11:50:04 -0700 Subject: [PATCH 3/4] Added options menu choice for 'MouseLook', defaults off --- interface/src/Application.cpp | 14 +++++++++----- interface/src/Application.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7a10a6af90..427c91176f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -860,11 +860,13 @@ void Application::idle() { } // Update from Mouse - QPoint mouse = QCursor::pos(); - _myAvatar.updateFromMouse(_glWidget->mapFromGlobal(mouse).x(), - _glWidget->mapFromGlobal(mouse).y(), - _glWidget->width(), - _glWidget->height()); + if (_mouseLook->isChecked()) { + QPoint mouse = QCursor::pos(); + _myAvatar.updateFromMouse(_glWidget->mapFromGlobal(mouse).x(), + _glWidget->mapFromGlobal(mouse).y(), + _glWidget->width(), + _glWidget->height()); + } // Read serial port interface devices if (_serialPort.active) { @@ -1117,6 +1119,8 @@ void Application::initMenu() { optionsMenu->addAction("Noise", this, SLOT(setNoise(bool)), Qt::Key_N)->setCheckable(true); (_gyroLook = optionsMenu->addAction("Gyro Look"))->setCheckable(true); _gyroLook->setChecked(true); + (_mouseLook = optionsMenu->addAction("Mouse Look"))->setCheckable(true); + _mouseLook->setChecked(false); optionsMenu->addAction("Fullscreen", this, SLOT(setFullscreen(bool)), Qt::Key_F)->setCheckable(true); QMenu* renderMenu = menuBar->addMenu("Render"); diff --git a/interface/src/Application.h b/interface/src/Application.h index 8a949fa183..f1c8d3ff1c 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -133,6 +133,7 @@ private: QAction* _lookingInMirror; // Are we currently rendering one's own head as if in mirror? QAction* _gyroLook; // Whether to allow the gyro data from head to move your view + QAction* _mouseLook; // Whether the have the mouse near edge of screen move your view QAction* _renderVoxels; // Whether to render voxels QAction* _renderStarsOn; // Whether to display the stars QAction* _renderAtmosphereOn; // Whether to display the atmosphere From 28581e33ccd9f40b8b50bbbcb3ceb6ee177aa3ba Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 20 May 2013 11:56:40 -0700 Subject: [PATCH 4/4] turn off audio echo rendering (it's for debug) --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 427c91176f..a1778bff54 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1662,7 +1662,7 @@ void Application::displayOverlay() { #ifndef _WIN32 _audio.render(_glWidget->width(), _glWidget->height()); _audioScope.render(20, _glWidget->height() - 200); - _audio.renderEchoCompare(); // PER: Will turn back on to further test echo + //_audio.renderEchoCompare(); // PER: Will turn back on to further test echo #endif //noiseTest(_glWidget->width(), _glWidget->height());