diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index d96fce450a..a9c6b71388 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -33,7 +33,10 @@ #include #include +#include +#include #include +#include #include #include @@ -71,7 +74,9 @@ AudioMixer::AudioMixer(const QByteArray& packet) : _performanceThrottlingRatio(0.0f), _numStatFrames(0), _sumListeners(0), - _sumMixes(0) + _sumMixes(0), + _sourceUnattenuatedZone(), + _listenerUnattenuatedZone() { } @@ -412,6 +417,24 @@ void AudioMixer::run() { nodeList->addNodeTypeToInterestSet(NodeType::Agent); nodeList->linkedDataCreateCallback = attachNewBufferToNode; + + // check the payload to see if we have any unattenuated zones + const QString UNATTENUATED_ZONE_REGEX_STRING = "--unattenuated-zone ([\\d.,-]+)"; + QRegExp unattenuatedZoneMatch(UNATTENUATED_ZONE_REGEX_STRING); + + if (unattenuatedZoneMatch.indexIn(_payload) != -1) { + QString unattenuatedZoneString = unattenuatedZoneMatch.cap(1); + QStringList zoneStringList = unattenuatedZoneString.split(','); + + glm::vec3 sourceCorner(zoneStringList[0].toFloat(), zoneStringList[1].toFloat(), zoneStringList[2].toFloat()); + glm::vec3 sourceDimensions(zoneStringList[3].toFloat(), zoneStringList[4].toFloat(), zoneStringList[5].toFloat()); + + glm::vec3 listenerCorner(zoneStringList[6].toFloat(), zoneStringList[7].toFloat(), zoneStringList[8].toFloat()); + glm::vec3 listenerDimensions(zoneStringList[9].toFloat(), zoneStringList[10].toFloat(), zoneStringList[11].toFloat()); + + _sourceUnattenuatedZone = AABox(sourceCorner, sourceDimensions); + _listenerUnattenuatedZone = AABox(listenerCorner, listenerDimensions); + } int nextFrame = 0; QElapsedTimer timer; diff --git a/assignment-client/src/audio/AudioMixer.h b/assignment-client/src/audio/AudioMixer.h index 659227dffb..70eb8bb32d 100644 --- a/assignment-client/src/audio/AudioMixer.h +++ b/assignment-client/src/audio/AudioMixer.h @@ -12,8 +12,8 @@ #ifndef hifi_AudioMixer_h #define hifi_AudioMixer_h +#include #include - #include class PositionalAudioRingBuffer; @@ -51,6 +51,8 @@ private: int _numStatFrames; int _sumListeners; int _sumMixes; + AABox _sourceUnattenuatedZone; + AABox _listenerUnattenuatedZone; }; #endif // hifi_AudioMixer_h diff --git a/assignment-client/src/audio/AudioMixerClientData.cpp b/assignment-client/src/audio/AudioMixerClientData.cpp index 9494e927a9..483cff6018 100644 --- a/assignment-client/src/audio/AudioMixerClientData.cpp +++ b/assignment-client/src/audio/AudioMixerClientData.cpp @@ -19,7 +19,8 @@ #include "AudioMixerClientData.h" AudioMixerClientData::AudioMixerClientData() : - _ringBuffers() + _ringBuffers(), + _listenerUnattenuatedZone(NULL) { } @@ -98,7 +99,8 @@ int AudioMixerClientData::parseData(const QByteArray& packet) { return 0; } -void AudioMixerClientData::checkBuffersBeforeFrameSend(int jitterBufferLengthSamples) { +void AudioMixerClientData::checkBuffersBeforeFrameSend(int jitterBufferLengthSamples, + AABox* checkSourceZone, AABox* listenerZone) { for (int i = 0; i < _ringBuffers.size(); i++) { if (_ringBuffers[i]->shouldBeAddedToMix(jitterBufferLengthSamples)) { // this is a ring buffer that is ready to go @@ -108,6 +110,12 @@ void AudioMixerClientData::checkBuffersBeforeFrameSend(int jitterBufferLengthSam // calculate the average loudness for the next NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL // that would be mixed in _ringBuffers[i]->updateNextOutputTrailingLoudness(); + + if (checkSourceZone && checkSourceZone->contains(_ringBuffers[i]->getPosition())) { + _listenerUnattenuatedZone = listenerZone; + } else { + _listenerUnattenuatedZone = NULL; + } } } } diff --git a/assignment-client/src/audio/AudioMixerClientData.h b/assignment-client/src/audio/AudioMixerClientData.h index 70b653301b..8c3f980789 100644 --- a/assignment-client/src/audio/AudioMixerClientData.h +++ b/assignment-client/src/audio/AudioMixerClientData.h @@ -12,8 +12,7 @@ #ifndef hifi_AudioMixerClientData_h #define hifi_AudioMixerClientData_h -#include - +#include #include #include @@ -28,10 +27,15 @@ public: AvatarAudioRingBuffer* getAvatarAudioRingBuffer() const; int parseData(const QByteArray& packet); - void checkBuffersBeforeFrameSend(int jitterBufferLengthSamples); + void checkBuffersBeforeFrameSend(int jitterBufferLengthSamples, + AABox* checkSourceZone = NULL, AABox* listenerZone = NULL); void pushBuffersAfterFrameSend(); + + AABox* getListenerUnattenuatedZone() const { return _listenerUnattenuatedZone; } + void setListenerUnattenuatedZone(AABox* listenerUnattenuatedZone) { _listenerUnattenuatedZone = listenerUnattenuatedZone; } private: QList _ringBuffers; + AABox* _listenerUnattenuatedZone; }; #endif // hifi_AudioMixerClientData_h diff --git a/libraries/octree/src/AABox.h b/libraries/octree/src/AABox.h deleted file mode 100644 index ef0e535b38..0000000000 --- a/libraries/octree/src/AABox.h +++ /dev/null @@ -1,69 +0,0 @@ -// -// AABox.h -// libraries/octree/src -// -// Created by Brad Hefta-Gaub on 04/11/13. -// Copyright 2013 High Fidelity, Inc. -// -// Originally from lighthouse3d. Modified to utilize glm::vec3 and clean up to our coding standards -// Simple axis aligned box class. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_AABox_h -#define hifi_AABox_h - -#include - -#include "BoxBase.h" - -class AACube; - -class AABox { - -public: - AABox(const glm::vec3& corner, float size); - AABox(const glm::vec3& corner, const glm::vec3& dimensions); - AABox(); - ~AABox() {}; - - void setBox(const glm::vec3& corner, const glm::vec3& scale); - - void setBox(const glm::vec3& corner, float scale); - glm::vec3 getVertexP(const glm::vec3& normal) const; - glm::vec3 getVertexN(const glm::vec3& normal) const; - void scale(float scale); - const glm::vec3& getCorner() const { return _corner; } - const glm::vec3& getScale() const { return _scale; } - const glm::vec3& getDimensions() const { return _scale; } - - glm::vec3 calcCenter() const; - glm::vec3 calcTopFarLeft() const; - glm::vec3 getVertex(BoxVertex vertex) const; - bool contains(const glm::vec3& point) const; - bool contains(const AABox& otherBox) const; - bool touches(const AABox& otherBox) const; - - bool contains(const AACube& otherCube) const; - bool touches(const AACube& otherCube) const; - - bool expandedContains(const glm::vec3& point, float expansion) const; - bool expandedIntersectsSegment(const glm::vec3& start, const glm::vec3& end, float expansion) const; - bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const; - bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration) const; - bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) const; - -private: - glm::vec3 getClosestPointOnFace(const glm::vec3& point, BoxFace face) const; - glm::vec3 getClosestPointOnFace(const glm::vec4& origin, const glm::vec4& direction, BoxFace face) const; - glm::vec4 getPlane(BoxFace face) const; - - static BoxFace getOppositeFace(BoxFace face); - - glm::vec3 _corner; - glm::vec3 _scale; -}; - -#endif // hifi_AABox_h diff --git a/libraries/octree/src/AABox.cpp b/libraries/shared/src/AABox.cpp similarity index 100% rename from libraries/octree/src/AABox.cpp rename to libraries/shared/src/AABox.cpp diff --git a/libraries/shared/src/AABox.h b/libraries/shared/src/AABox.h new file mode 100644 index 0000000000..71ee7c73d3 --- /dev/null +++ b/libraries/shared/src/AABox.h @@ -0,0 +1,71 @@ +// +// AABox.h +// libraries/octree/src +// +// Created by Brad Hefta-Gaub on 04/11/13. +// Copyright 2013 High Fidelity, Inc. +// +// Originally from lighthouse3d. Modified to utilize glm::vec3 and clean up to our coding standards +// Simple axis aligned box class. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_AABox_h +#define hifi_AABox_h + +#include + +#include "BoxBase.h" + +class AACube; + +class AABox { + +public: + AABox(const glm::vec3& corner, float size); + AABox(const glm::vec3& corner, const glm::vec3& dimensions); + AABox(); + ~AABox() {}; + + void setBox(const glm::vec3& corner, const glm::vec3& scale); + + void setBox(const glm::vec3& corner, float scale); + glm::vec3 getVertexP(const glm::vec3& normal) const; + glm::vec3 getVertexN(const glm::vec3& normal) const; + void scale(float scale); + const glm::vec3& getCorner() const { return _corner; } + const glm::vec3& getScale() const { return _scale; } + const glm::vec3& getDimensions() const { return _scale; } + + glm::vec3 calcCenter() const; + glm::vec3 calcTopFarLeft() const; + glm::vec3 getVertex(BoxVertex vertex) const; + bool contains(const glm::vec3& point) const; + bool contains(const AABox& otherBox) const; + bool touches(const AABox& otherBox) const; + + bool contains(const AACube& otherCube) const; + bool touches(const AACube& otherCube) const; + + bool expandedContains(const glm::vec3& point, float expansion) const; + bool expandedIntersectsSegment(const glm::vec3& start, const glm::vec3& end, float expansion) const; + bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) const; + bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration) const; + bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration) const; + + bool isNull() const { return _scale == glm::vec3(0.0f, 0.0f, 0.0f); } + +private: + glm::vec3 getClosestPointOnFace(const glm::vec3& point, BoxFace face) const; + glm::vec3 getClosestPointOnFace(const glm::vec4& origin, const glm::vec4& direction, BoxFace face) const; + glm::vec4 getPlane(BoxFace face) const; + + static BoxFace getOppositeFace(BoxFace face); + + glm::vec3 _corner; + glm::vec3 _scale; +}; + +#endif // hifi_AABox_h diff --git a/libraries/octree/src/AACube.cpp b/libraries/shared/src/AACube.cpp similarity index 100% rename from libraries/octree/src/AACube.cpp rename to libraries/shared/src/AACube.cpp diff --git a/libraries/octree/src/AACube.h b/libraries/shared/src/AACube.h similarity index 100% rename from libraries/octree/src/AACube.h rename to libraries/shared/src/AACube.h diff --git a/libraries/octree/src/BoxBase.h b/libraries/shared/src/BoxBase.h similarity index 100% rename from libraries/octree/src/BoxBase.h rename to libraries/shared/src/BoxBase.h