Ken's feedback

This commit is contained in:
Zach Fox 2017-01-11 16:16:35 -08:00
parent b9cddc31a9
commit b0b6aeac6c
9 changed files with 41 additions and 32 deletions

View file

@ -28,6 +28,7 @@
#include <StDev.h>
#include <UUID.h>
#include "AudioHelpers.h"
#include "AudioRingBuffer.h"
#include "AudioMixerClientData.h"
#include "AvatarAudioStream.h"
@ -188,7 +189,6 @@ void AudioMixer::handleNodeKilled(SharedNodePointer killedNode) {
auto clientData = dynamic_cast<AudioMixerClientData*>(node->getLinkedData());
if (clientData) {
QUuid killedUUID = killedNode->getUUID();
clientData->removePerAvatarGain(killedUUID);
clientData->removeHRTFsForNode(killedUUID);
}
});
@ -246,11 +246,14 @@ void AudioMixer::handleNodeIgnoreRequestPacket(QSharedPointer<ReceivedMessage> p
void AudioMixer::handlePerAvatarGainSetDataPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode) {
auto clientData = dynamic_cast<AudioMixerClientData*>(sendingNode->getLinkedData());
if (clientData) {
QUuid listeningNodeUUID = sendingNode->getUUID();
// parse the UUID from the packet
QUuid ignoredUUID = QUuid::fromRfc4122(packet->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
float gain;
packet->readPrimitive(&gain);
clientData->setPerAvatarGain(ignoredUUID, gain);
QUuid audioSourceUUID = QUuid::fromRfc4122(packet->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
uint8_t packedGain;
packet->readPrimitive(&packedGain);
float gain = unpackFloatGainFromByte(packedGain);
clientData->hrtfForStream(audioSourceUUID, QUuid()).setGainAdjustment(gain);
qDebug() << "Setting gain adjustment for hrtf[" << listeningNodeUUID << "][" << audioSourceUUID << "] to " << gain;
}
}

View file

@ -95,10 +95,6 @@ public:
bool getRequestsDomainListData() { return _requestsDomainListData; }
void setRequestsDomainListData(bool requesting) { _requestsDomainListData = requesting; }
float getPerAvatarGain(const QUuid& avatarID) { return (_perAvatarGain.count(avatarID) ? _perAvatarGain.at(avatarID) : 1.0f); }
void setPerAvatarGain(const QUuid& avatarID, float gain) { _perAvatarGain[avatarID] = gain; }
void removePerAvatarGain(const QUuid& avatarID) { _perAvatarGain.erase(avatarID); }
signals:
void injectorStreamFinished(const QUuid& streamIdentifier);
@ -129,8 +125,6 @@ private:
bool _shouldMuteClient { false };
bool _requestsDomainListData { false };
std::unordered_map<QUuid, float> _perAvatarGain;
};
#endif // hifi_AudioMixerClientData_h

View file

@ -252,13 +252,12 @@ bool AudioMixerSlave::prepareMix(const SharedNodePointer& node) {
// Enumerate the audio streams attached to the otherNode
auto streamsCopy = otherData->getAudioStreams();
float thisAvatarGain = nodeData->getPerAvatarGain(otherNode->getUUID());
for (auto& streamPair : streamsCopy) {
auto otherNodeStream = streamPair.second;
bool isSelfWithEcho = ((*otherNode == *node) && (otherNodeStream->shouldLoopbackForNode()));
// Add all audio streams that should be added to the mix
if (isSelfWithEcho || (!isSelfWithEcho && !insideIgnoreRadius)) {
addStreamToMix(*nodeData, otherNode->getUUID(), *nodeAudioStream, *otherNodeStream, thisAvatarGain);
addStreamToMix(*nodeData, otherNode->getUUID(), *nodeAudioStream, *otherNodeStream);
}
}
}
@ -279,7 +278,7 @@ bool AudioMixerSlave::prepareMix(const SharedNodePointer& node) {
}
void AudioMixerSlave::addStreamToMix(AudioMixerClientData& listenerNodeData, const QUuid& sourceNodeID,
const AvatarAudioStream& listeningNodeStream, const PositionalAudioStream& streamToAdd, float perAvatarGain) {
const AvatarAudioStream& listeningNodeStream, const PositionalAudioStream& streamToAdd) {
// to reduce artifacts we calculate the gain and azimuth for every source for this listener
// even if we are not going to end up mixing in this source
@ -296,7 +295,7 @@ void AudioMixerSlave::addStreamToMix(AudioMixerClientData& listenerNodeData, con
float distance = glm::max(glm::length(relativePosition), EPSILON);
// figure out the gain for this source at the listener
float gain = gainForSource(listeningNodeStream, streamToAdd, relativePosition, isEcho) * perAvatarGain;
float gain = gainForSource(listeningNodeStream, streamToAdd, relativePosition, isEcho);
// figure out the azimuth to this source at the listener
float azimuth = isEcho ? 0.0f : azimuthForSource(listeningNodeStream, listeningNodeStream, relativePosition);

View file

@ -43,7 +43,7 @@ private:
bool prepareMix(const SharedNodePointer& node);
// add a stream to the mix
void addStreamToMix(AudioMixerClientData& listenerData, const QUuid& streamerID,
const AvatarAudioStream& listenerStream, const PositionalAudioStream& streamer, float perAvatarGain);
const AvatarAudioStream& listenerStream, const PositionalAudioStream& streamer);
float gainForSource(const AvatarAudioStream& listener, const PositionalAudioStream& streamer,
const glm::vec3& relativePosition, bool isEcho);

View file

@ -155,10 +155,10 @@ Row {
visible: !isMyCard
width: parent.width
height: 18
value: pal.gain[uuid] ? pal.gain[uuid] : 1.0
minimumValue: 0.0
maximumValue: 1.5
stepSize: 0.1
value: pal.gainSliderValueDB[uuid] ? pal.gainSliderValueDB[uuid] : 0.0
minimumValue: -60.0
maximumValue: 20.0
stepSize: 2
updateValueWhileDragging: false
onValueChanged: updateGainFromQML(uuid, value)
style: SliderStyle {
@ -167,6 +167,12 @@ Row {
implicitWidth: gainSlider.width
implicitHeight: 4
radius: 2
MouseArea {
anchors.fill: parent
onDoubleClicked: {
gainSlider.value = 0.0
}
}
}
handle: Rectangle {
anchors.centerIn: parent
@ -178,12 +184,14 @@ Row {
}
}
function updateGainFromQML(avatarUuid, gainValue) {
pal.gain[avatarUuid] = gainValue;
var data = {
sessionId: avatarUuid,
gain: (Math.pow(20, gainValue) - 1) / (20 - 1)
};
pal.sendToScript({method: 'updateGain', params: data});
function updateGainFromQML(avatarUuid, sliderValue) {
if (pal.gainSliderValueDB[avatarUuid] !== sliderValue) {
pal.gainSliderValueDB[avatarUuid] = sliderValue;
var data = {
sessionId: avatarUuid,
gain: sliderValue
};
pal.sendToScript({method: 'updateGain', params: data});
}
}
}

View file

@ -32,7 +32,9 @@ Rectangle {
property var ignored: ({}); // Keep a local list of ignored avatars & their data. Necessary because HashMap is slow to respond after ignoring.
property var userModelData: [] // This simple list is essentially a mirror of the userModel listModel without all the extra complexities.
property bool iAmAdmin: false
property var gain: ({}); // Keep a local list of per-avatar gain. Far faster than keeping this data on the server.
// Keep a local list of per-avatar gainSliderValueDBs. Far faster than fetching this data from the server.
// NOTE: if another script modifies the per-avatar gain, this value won't be accurate!
property var gainSliderValueDB: ({});
// This is the container for the PAL
Rectangle {
@ -497,7 +499,7 @@ Rectangle {
break;
case 'clearLocalQMLData':
ignored = {};
gain = {};
gainSliderValueDB = {};
break;
default:
console.log('Unrecognized message:', JSON.stringify(message));

View file

@ -45,7 +45,7 @@ public:
void renderSilent(int16_t* input, float* output, int index, float azimuth, float distance, float gain, int numFrames);
//
// HRTF local gain adjustment
// HRTF local gain adjustment in amplitude (1.0 == unity)
//
void setGainAdjustment(float gain) { _gainAdjust = HRTF_GAIN * gain; };

View file

@ -26,6 +26,7 @@
#include "AccountManager.h"
#include "AddressManager.h"
#include "Assignment.h"
#include "AudioHelpers.h"
#include "HifiSockAddr.h"
#include "FingerprintUtils.h"
@ -961,7 +962,8 @@ void NodeList::setAvatarGain(const QUuid& nodeID, float gain) {
// write the node ID to the packet
setAvatarGainPacket->write(nodeID.toRfc4122());
setAvatarGainPacket->writePrimitive((gain < 5.0f ? gain : 5.0f));
// 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;

View file

@ -63,9 +63,10 @@ public slots:
/**jsdoc
* 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 {float} gain The gain of the avatar you'd like to set.
* @param {float} gain The gain of the avatar you'd like to set. Units are dB.
*/
void setAvatarGain(const QUuid& nodeID, float gain);