From 8d37f5ae00365060dd5916877bb4f842c2a49cef Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 20 Jan 2015 15:35:22 -0800 Subject: [PATCH] More setting handles --- interface/src/Audio.cpp | 48 +++++++++++++++++---- interface/src/Audio.h | 3 ++ interface/src/devices/Faceshift.cpp | 19 ++++++++ interface/src/devices/Faceshift.h | 4 +- libraries/audio/src/InboundAudioStream.cpp | 41 ++++++++++++++++++ libraries/audio/src/InboundAudioStream.h | 2 + libraries/networking/src/AddressManager.cpp | 2 +- libraries/octree/src/OctreeQuery.cpp | 17 +++++++- libraries/octree/src/OctreeQuery.h | 4 +- libraries/octree/src/ViewFrustum.cpp | 27 ++++++++++-- libraries/octree/src/ViewFrustum.h | 6 ++- 11 files changed, 154 insertions(+), 19 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 6c7705a56c..8ef3c12ed1 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -10,9 +10,10 @@ // #include +#include #include -#include +#include #ifdef __APPLE__ #include @@ -28,29 +29,35 @@ #include #endif -#include - #include #include #include -#include - +#include #include #include #include - #include - +#include #include #include #include "Application.h" - #include "Audio.h" static const int RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES = 100; +namespace SettingHandles { + const SettingHandle audioOutputStarveDetectionEnabled("audioOutputStarveDetectionEnabled", + DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_ENABLED); + const SettingHandle audioOutputStarveDetectionThreshold("audioOutputStarveDetectionThreshold", + DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_THRESHOLD); + const SettingHandle audioOutputStarveDetectionPeriod("audioOutputStarveDetectionPeriod", + DEFAULT_AUDIO_OUTPUT_STARVE_DETECTION_PERIOD); + const SettingHandle audioOutputBufferSize("audioOutputBufferSize", + DEFAULT_MAX_FRAMES_OVER_DESIRED); +} + Audio::Audio() : AbstractAudioInterface(), _audioInput(NULL), @@ -1114,3 +1121,28 @@ qint64 Audio::AudioOutputIODevice::readData(char * data, qint64 maxSize) { return bytesWritten; } + +void Audio::loadSettings() { + _receivedAudioStream.loadSettings(); + + setOutputStarveDetectionEnabled(SettingHandles::audioOutputStarveDetectionEnabled.get()); + setOutputStarveDetectionThreshold(SettingHandles::audioOutputStarveDetectionThreshold.get()); + setOutputStarveDetectionPeriod(SettingHandles::audioOutputStarveDetectionPeriod.get()); + + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setOutputBufferSize", + Q_ARG(int, SettingHandles::audioOutputBufferSize.get())); + } else { + setOutputBufferSize(SettingHandles::audioOutputBufferSize.get()); + } +} + +void Audio::saveSettings() { + _receivedAudioStream.saveSettings(); + + SettingHandles::audioOutputStarveDetectionEnabled.set(getOutputStarveDetectionEnabled()); + SettingHandles::audioOutputStarveDetectionThreshold.set(getOutputStarveDetectionThreshold()); + SettingHandles::audioOutputStarveDetectionPeriod.set(getOutputStarveDetectionPeriod()); + SettingHandles::audioOutputBufferSize.set(getOutputBufferSize()); +} + diff --git a/interface/src/Audio.h b/interface/src/Audio.h index 0d6ffcfb1d..d122830b44 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -173,6 +173,9 @@ public slots: void outputNotify(); + void loadSettings(); + void saveSettings(); + private slots: void audioMuteToggled(); diff --git a/interface/src/devices/Faceshift.cpp b/interface/src/devices/Faceshift.cpp index 0d5eace74b..eec2e64d3c 100644 --- a/interface/src/devices/Faceshift.cpp +++ b/interface/src/devices/Faceshift.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include "Faceshift.h" @@ -28,6 +29,11 @@ using namespace std; const quint16 FACESHIFT_PORT = 33433; float STARTING_FACESHIFT_FRAME_TIME = 0.033f; +namespace SettingHandles { + const SettingHandle faceshiftEyeDeflection("faceshiftEyeDeflection", DEFAULT_FACESHIFT_EYE_DEFLECTION); + const SettingHandle faceshiftHostname("faceshiftHostname", DEFAULT_FACESHIFT_HOSTNAME); +} + Faceshift::Faceshift() : _tcpEnabled(true), _tcpRetryCount(0), @@ -67,6 +73,9 @@ Faceshift::Faceshift() : _udpSocket.bind(FACESHIFT_PORT); #endif + + _eyeDeflection = SettingHandles::faceshiftEyeDeflection.get(); + _hostname = SettingHandles::faceshiftHostname.get(); } void Faceshift::init() { @@ -310,3 +319,13 @@ void Faceshift::receive(const QByteArray& buffer) { } #endif } + +void Faceshift::setEyeDeflection(float faceshiftEyeDeflection) { + _eyeDeflection = faceshiftEyeDeflection; + SettingHandles::faceshiftEyeDeflection.set(_eyeDeflection); +} + +void Faceshift::setHostname(const QString& hostname) { + _hostname = hostname; + SettingHandles::faceshiftHostname.set(_hostname); +} diff --git a/interface/src/devices/Faceshift.h b/interface/src/devices/Faceshift.h index f48309abf4..c02fa26262 100644 --- a/interface/src/devices/Faceshift.h +++ b/interface/src/devices/Faceshift.h @@ -63,10 +63,10 @@ public: float getMouthSmileRight() const { return getBlendshapeCoefficient(_mouthSmileRightIndex); } float getEyeDeflection() const { return _eyeDeflection; } - void setEyeDeflection(float faceshiftEyeDeflection) { _eyeDeflection = faceshiftEyeDeflection; } + void setEyeDeflection(float faceshiftEyeDeflection); const QString& getHostname() const { return _hostname; } - void setHostname(const QString& hostname) { _hostname = hostname; } + void setHostname(const QString& hostname); void update(); void reset(); diff --git a/libraries/audio/src/InboundAudioStream.cpp b/libraries/audio/src/InboundAudioStream.cpp index 7d0bb0fdca..d65521941c 100644 --- a/libraries/audio/src/InboundAudioStream.cpp +++ b/libraries/audio/src/InboundAudioStream.cpp @@ -11,11 +11,27 @@ #include +#include + #include "InboundAudioStream.h" #include "PacketHeaders.h" const int STARVE_HISTORY_CAPACITY = 50; +namespace SettingHandles { + const SettingHandle dynamicJitterBuffers("dynamicJitterBuffers", DEFAULT_DYNAMIC_JITTER_BUFFERS); + const SettingHandle maxFramesOverDesired("maxFramesOverDesired", DEFAULT_MAX_FRAMES_OVER_DESIRED); + const SettingHandle staticDesiredJitterBufferFrames("staticDesiredJitterBufferFrames", + DEFAULT_STATIC_DESIRED_JITTER_BUFFER_FRAMES); + const SettingHandle useStDevForJitterCalc("useStDevForJitterCalc", DEFAULT_USE_STDEV_FOR_JITTER_CALC); + const SettingHandle windowStarveThreshold("windowStarveThreshold", DEFAULT_WINDOW_STARVE_THRESHOLD); + const SettingHandle windowSecondsForDesiredCalcOnTooManyStarves("windowSecondsForDesiredCalcOnTooManyStarves", + DEFAULT_WINDOW_SECONDS_FOR_DESIRED_CALC_ON_TOO_MANY_STARVES); + const SettingHandle windowSecondsForDesiredReduction("windowSecondsForDesiredReduction", + DEFAULT_WINDOW_SECONDS_FOR_DESIRED_REDUCTION); + const SettingHandle repetitionWithFade("repetitionWithFade", DEFAULT_REPETITION_WITH_FADE); +} + InboundAudioStream::InboundAudioStream(int numFrameSamples, int numFramesCapacity, const Settings& settings) : _ringBuffer(numFrameSamples, false, numFramesCapacity), _lastPopSucceeded(false), @@ -500,3 +516,28 @@ float calculateRepeatedFrameFadeFactor(int indexOfRepeat) { } return 0.0f; } + +void InboundAudioStream::loadSettings() { + setDynamicJitterBuffers(SettingHandles::dynamicJitterBuffers.get()); + setMaxFramesOverDesired(SettingHandles::maxFramesOverDesired.get()); + setStaticDesiredJitterBufferFrames(SettingHandles::staticDesiredJitterBufferFrames.get()); + setUseStDevForJitterCalc(SettingHandles::useStDevForJitterCalc.get()); + setWindowStarveThreshold(SettingHandles::windowStarveThreshold.get()); + setWindowSecondsForDesiredCalcOnTooManyStarves(SettingHandles::windowSecondsForDesiredCalcOnTooManyStarves.get()); + setWindowSecondsForDesiredReduction(SettingHandles::windowSecondsForDesiredReduction.get()); + setRepetitionWithFade(SettingHandles::repetitionWithFade.get()); +} + +void InboundAudioStream::saveSettings() { + SettingHandles::dynamicJitterBuffers.set(getDynamicJitterBuffers()); + SettingHandles::maxFramesOverDesired.set(getMaxFramesOverDesired()); + SettingHandles::staticDesiredJitterBufferFrames.set(getDesiredJitterBufferFrames()); + SettingHandles::useStDevForJitterCalc.set(getUseStDevForJitterCalc()); + SettingHandles::windowStarveThreshold.set(getWindowStarveThreshold()); + SettingHandles::windowSecondsForDesiredCalcOnTooManyStarves.set(getWindowSecondsForDesiredCalcOnTooManyStarves()); + SettingHandles::windowSecondsForDesiredReduction.set(getWindowSecondsForDesiredReduction()); + SettingHandles::repetitionWithFade.set(getRepetitionWithFade()); +} + + + diff --git a/libraries/audio/src/InboundAudioStream.h b/libraries/audio/src/InboundAudioStream.h index 0941ce67f2..4e75602fe8 100644 --- a/libraries/audio/src/InboundAudioStream.h +++ b/libraries/audio/src/InboundAudioStream.h @@ -126,6 +126,8 @@ public: void setWindowSecondsForDesiredReduction(int windowSecondsForDesiredReduction); void setRepetitionWithFade(bool repetitionWithFade) { _repetitionWithFade = repetitionWithFade; } + void loadSettings(); + void saveSettings(); virtual AudioStreamStats getAudioStreamStats() const; diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 507ddd6e5e..6c228054d4 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -38,7 +38,7 @@ AddressManager::AddressManager() : _positionGetter(NULL), _orientationGetter(NULL) { - + connect(qApp, &QCoreApplication::aboutToQuit, this, &AddressManager::storeCurrentAddress); } bool AddressManager::isConnected() { diff --git a/libraries/octree/src/OctreeQuery.cpp b/libraries/octree/src/OctreeQuery.cpp index 00c1a4a62d..dc8d5fe8c2 100644 --- a/libraries/octree/src/OctreeQuery.cpp +++ b/libraries/octree/src/OctreeQuery.cpp @@ -9,12 +9,27 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include #include +#include +#include #include "OctreeConstants.h" #include "OctreeQuery.h" +namespace SettingHandles { + const SettingHandle maxOctreePacketsPerSecond("maxOctreePPS", DEFAULT_MAX_OCTREE_PPS); +} + +OctreeQuery::OctreeQuery() { + _maxOctreePPS = SettingHandles::maxOctreePacketsPerSecond.get(); +} + +void OctreeQuery::setMaxOctreePacketsPerSecond(int maxOctreePPS) { + _maxOctreePPS = maxOctreePPS; + SettingHandles::maxOctreePacketsPerSecond.set(_maxOctreePPS); +} + + int OctreeQuery::getBroadcastData(unsigned char* destinationBuffer) { unsigned char* bufferStart = destinationBuffer; diff --git a/libraries/octree/src/OctreeQuery.h b/libraries/octree/src/OctreeQuery.h index 3d76857acc..66abe53931 100644 --- a/libraries/octree/src/OctreeQuery.h +++ b/libraries/octree/src/OctreeQuery.h @@ -44,7 +44,7 @@ class OctreeQuery : public NodeData { Q_OBJECT public: - OctreeQuery() {} + OctreeQuery(); virtual ~OctreeQuery() {} int getBroadcastData(unsigned char* destinationBuffer); @@ -86,7 +86,7 @@ public slots: void setWantDelta(bool wantDelta) { _wantDelta = wantDelta; } void setWantOcclusionCulling(bool wantOcclusionCulling) { _wantOcclusionCulling = wantOcclusionCulling; } void setWantCompression(bool wantCompression) { _wantCompression = wantCompression; } - void setMaxOctreePacketsPerSecond(int maxOctreePPS) { _maxOctreePPS = maxOctreePPS; } + void setMaxOctreePacketsPerSecond(int maxOctreePPS); void setOctreeSizeScale(float octreeSizeScale) { _octreeElementSizeScale = octreeSizeScale; } void setBoundaryLevelAdjust(int boundaryLevelAdjust) { _boundaryLevelAdjust = boundaryLevelAdjust; } diff --git a/libraries/octree/src/ViewFrustum.cpp b/libraries/octree/src/ViewFrustum.cpp index 7f7f8fb47b..dd25ac51c3 100644 --- a/libraries/octree/src/ViewFrustum.cpp +++ b/libraries/octree/src/ViewFrustum.cpp @@ -17,6 +17,8 @@ #include +#include + #include "GeometryUtil.h" #include "SharedUtil.h" #include "ViewFrustum.h" @@ -24,11 +26,30 @@ using namespace std; +namespace SettingHandles { + const SettingHandle fieldOfView("fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES); + const SettingHandle realWorldFieldOfView("realWorldFieldOfView", DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES); +} + +ViewFrustum::ViewFrustum() { + _fieldOfView = SettingHandles::fieldOfView.get(); + _realWorldFieldOfView = SettingHandles::realWorldFieldOfView.get(); +} + void ViewFrustum::setOrientation(const glm::quat& orientationAsQuaternion) { _orientation = orientationAsQuaternion; - _right = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_RIGHT, 0.0f)); - _up = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_UP, 0.0f)); - _direction = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_FRONT, 0.0f)); + _right = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_RIGHT, 0.0f)); + _up = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_UP, 0.0f)); + _direction = glm::vec3(orientationAsQuaternion * glm::vec4(IDENTITY_FRONT, 0.0f)); +} + +void ViewFrustum::setFieldOfView(float f) { + _fieldOfView = f; + SettingHandles::fieldOfView.set(f); +} +void ViewFrustum::setRealWorldFieldOfView(float realWorldFieldOfView) { + _realWorldFieldOfView = realWorldFieldOfView; + SettingHandles::realWorldFieldOfView.set(realWorldFieldOfView); } // ViewFrustum::calculateViewFrustum() diff --git a/libraries/octree/src/ViewFrustum.h b/libraries/octree/src/ViewFrustum.h index 3f68574bfe..2ea2d29e11 100644 --- a/libraries/octree/src/ViewFrustum.h +++ b/libraries/octree/src/ViewFrustum.h @@ -34,6 +34,8 @@ const float DEFAULT_FAR_CLIP = TREE_SCALE; class ViewFrustum { public: + ViewFrustum(); + // setters for camera attributes void setPosition(const glm::vec3& p) { _position = p; _positionVoxelScale = (p / (float)TREE_SCALE); } void setOrientation(const glm::quat& orientationAsQuaternion); @@ -50,8 +52,8 @@ public: void setOrthographic(bool orthographic) { _orthographic = orthographic; } void setWidth(float width) { _width = width; } void setHeight(float height) { _height = height; } - void setFieldOfView(float f) { _fieldOfView = f; } - void setRealWorldFieldOfView(float realWorldFieldOfView) { _realWorldFieldOfView = realWorldFieldOfView; } + void setFieldOfView(float f); + void setRealWorldFieldOfView(float realWorldFieldOfView); void setAspectRatio(float a) { _aspectRatio = a; } void setNearClip(float n) { _nearClip = n; } void setFarClip(float f) { _farClip = f; }