From 6ba2a83bbe0c94aa5efad2f7b25c5b6118e81666 Mon Sep 17 00:00:00 2001 From: Ken Cooke Date: Sun, 29 Oct 2017 10:47:56 -0700 Subject: [PATCH] Send and receive Avatar MASTER Gain packets, signaled using null nodeID. Packet protocol change is not needed (existing audio-mixer will ignore). --- .../src/audio/AudioMixerClientData.cpp | 10 ++++++++-- libraries/networking/src/NodeList.cpp | 13 +++++++++---- .../script-engine/src/UsersScriptingInterface.h | 4 ++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/assignment-client/src/audio/AudioMixerClientData.cpp b/assignment-client/src/audio/AudioMixerClientData.cpp index 9bba9c7f30..59bc878cba 100644 --- a/assignment-client/src/audio/AudioMixerClientData.cpp +++ b/assignment-client/src/audio/AudioMixerClientData.cpp @@ -189,8 +189,14 @@ void AudioMixerClientData::parsePerAvatarGainSet(ReceivedMessage& message, const uint8_t packedGain; message.readPrimitive(&packedGain); float gain = unpackFloatGainFromByte(packedGain); - hrtfForStream(avatarUuid, QUuid()).setGainAdjustment(gain); - qDebug() << "Setting gain adjustment for hrtf[" << uuid << "][" << avatarUuid << "] to " << gain; + + if (avatarUuid.isNull()) { + // FIXME: change master gain, and reset hrtf gains for all active streams + qDebug() << "Setting MASTER avatar gain for [" << uuid << "] to " << gain; + } else { + hrtfForStream(avatarUuid, QUuid()).setGainAdjustment(gain); + qDebug() << "Setting avatar gain adjustment for hrtf[" << uuid << "][" << avatarUuid << "] to " << gain; + } } void AudioMixerClientData::parseNodeIgnoreRequest(QSharedPointer message, const SharedNodePointer& node) { diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 71128c5ff0..04699d8ad1 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -979,8 +979,8 @@ void NodeList::maybeSendIgnoreSetToNode(SharedNodePointer newNode) { } void NodeList::setAvatarGain(const QUuid& nodeID, float gain) { - // cannot set gain of yourself or nobody - if (!nodeID.isNull() && _sessionUUID != nodeID) { + // cannot set gain of yourself + if (_sessionUUID != nodeID) { auto audioMixer = soloNodeOfType(NodeType::AudioMixer); if (audioMixer) { // setup the packet @@ -988,10 +988,15 @@ void NodeList::setAvatarGain(const QUuid& nodeID, float gain) { // write the node ID to the packet setAvatarGainPacket->write(nodeID.toRfc4122()); + // We need to convert the gain in dB (from the script) to an amplitude before packing it. setAvatarGainPacket->writePrimitive(packFloatGainToByte(fastExp2f(gain / 6.0206f))); - qCDebug(networking) << "Sending Set Avatar Gain packet UUID: " << uuidStringWithoutCurlyBraces(nodeID) << "Gain:" << gain; + if (nodeID.isNull()) { + qCDebug(networking) << "Sending Set Avatar MASTER Gain packet with Gain:" << gain; + } else { + qCDebug(networking) << "Sending Set Avatar Gain packet with UUID: " << uuidStringWithoutCurlyBraces(nodeID) << "Gain:" << gain; + } sendPacket(std::move(setAvatarGainPacket), *audioMixer); QWriteLocker{ &_avatarGainMapLock }; @@ -1001,7 +1006,7 @@ void NodeList::setAvatarGain(const QUuid& nodeID, float gain) { qWarning() << "Couldn't find audio mixer to send set gain request"; } } else { - qWarning() << "NodeList::setAvatarGain called with an invalid ID or an ID which matches the current session ID:" << nodeID; + qWarning() << "NodeList::setAvatarGain called with an ID which matches the current session ID:" << nodeID; } } diff --git a/libraries/script-engine/src/UsersScriptingInterface.h b/libraries/script-engine/src/UsersScriptingInterface.h index acaa92d9c8..2d33bbca14 100644 --- a/libraries/script-engine/src/UsersScriptingInterface.h +++ b/libraries/script-engine/src/UsersScriptingInterface.h @@ -65,7 +65,7 @@ public slots: * Sets an avatar's gain for you and you only. * Units are Decibels (dB) * @function Users.setAvatarGain - * @param {nodeID} nodeID The node or session ID of the user whose gain you want to modify. + * @param {nodeID} nodeID The node or session ID of the user whose gain you want to modify, or null to set the master gain. * @param {float} gain The gain of the avatar you'd like to set. Units are dB. */ void setAvatarGain(const QUuid& nodeID, float gain); @@ -73,7 +73,7 @@ public slots: /**jsdoc * Gets an avatar's gain for you and you only. * @function Users.getAvatarGain - * @param {nodeID} nodeID The node or session ID of the user whose gain you want to get. + * @param {nodeID} nodeID The node or session ID of the user whose gain you want to get, or null to get the master gain. * @return {float} gain (in dB) */ float getAvatarGain(const QUuid& nodeID);