diff --git a/assignment-client/src/audio/AudioMixerClientData.cpp b/assignment-client/src/audio/AudioMixerClientData.cpp index 07fa337a57..a5f5521a2d 100644 --- a/assignment-client/src/audio/AudioMixerClientData.cpp +++ b/assignment-client/src/audio/AudioMixerClientData.cpp @@ -226,11 +226,31 @@ AvatarAudioStream* AudioMixerClientData::getAvatarAudioStream() { return NULL; } +AudioHRTF& AudioMixerClientData::hrtfForStream(Node::LocalID nodeID, const QUuid& streamID) { + auto& hrtfVector = _nodeSourcesHRTFMap[nodeID]; + + auto streamIt = std::find_if(hrtfVector.begin(), hrtfVector.end(), [&streamID](IdentifiedHRTF& identifiedHRTF){ + return identifiedHRTF.streamIdentifier == streamID; + }); + + if (streamIt == hrtfVector.end()) { + hrtfVector.push_back({ streamID, std::unique_ptr(new AudioHRTF) }); + + return *hrtfVector.back().hrtf; + } else { + return *streamIt->hrtf; + } +} + void AudioMixerClientData::removeHRTFForStream(Node::LocalID nodeID, const QUuid& streamID) { auto it = _nodeSourcesHRTFMap.find(nodeID); if (it != _nodeSourcesHRTFMap.end()) { + auto streamIt = std::find_if(it->second.begin(), it->second.end(), [&streamID](IdentifiedHRTF& identifiedHRTF){ + return identifiedHRTF.streamIdentifier == streamID; + }); + // erase the stream with the given ID from the given node - it->second.erase(streamID); + it->second.erase(streamIt); // is the map for this node now empty? // if so we can remove it diff --git a/assignment-client/src/audio/AudioMixerClientData.h b/assignment-client/src/audio/AudioMixerClientData.h index d74c8bb6a4..a35f3dea5a 100644 --- a/assignment-client/src/audio/AudioMixerClientData.h +++ b/assignment-client/src/audio/AudioMixerClientData.h @@ -50,7 +50,7 @@ public: // they are not thread-safe // returns a new or existing HRTF object for the given stream from the given node - AudioHRTF& hrtfForStream(Node::LocalID nodeID, const QUuid& streamID = QUuid()) { return _nodeSourcesHRTFMap[nodeID][streamID]; } + AudioHRTF& hrtfForStream(Node::LocalID nodeID, const QUuid& streamID = QUuid()); // removes an AudioHRTF object for a given stream void removeHRTFForStream(Node::LocalID nodeID, const QUuid& streamID = QUuid()); @@ -152,8 +152,13 @@ private: }; IgnoreZoneMemo _ignoreZone; - using HRTFMap = std::unordered_map; - using NodeSourcesHRTFMap = std::unordered_map; + struct IdentifiedHRTF { + QUuid streamIdentifier; + std::unique_ptr hrtf; + }; + + using HRTFVector = std::vector; + using NodeSourcesHRTFMap = std::unordered_map; NodeSourcesHRTFMap _nodeSourcesHRTFMap; quint16 _outgoingMixedAudioSequenceNumber;