Fixed avatar volume adjustment

This commit is contained in:
ksuprynowicz 2024-03-01 01:32:43 +01:00
parent a1089b5b50
commit 04e85d53e6
2 changed files with 21 additions and 4 deletions

View file

@ -223,12 +223,24 @@ void AudioMixerClientData::parseInjectorGainSet(ReceivedMessage& message, const
} }
void AudioMixerClientData::setGainForAvatar(QUuid nodeID, float gain) { void AudioMixerClientData::setGainForAvatar(QUuid nodeID, float gain) {
auto it = std::find_if(_streams.active.cbegin(), _streams.active.cend(), [nodeID](const MixableStream& mixableStream){ auto itActive = std::find_if(_streams.active.cbegin(), _streams.active.cend(), [nodeID](const MixableStream& mixableStream){
return mixableStream.nodeStreamID.nodeID == nodeID && mixableStream.nodeStreamID.streamID.isNull(); return mixableStream.nodeStreamID.nodeID == nodeID && mixableStream.nodeStreamID.streamID.isNull();
}); });
if (it != _streams.active.cend()) { if (itActive != _streams.active.cend()) {
it->hrtf->setGainAdjustment(gain); itActive->hrtf->setGainAdjustment(gain);
return;
}
// If someone is not speaking at the moment, then stream is not in active streams, and volume adjustment will fail,
// so we need to search in inactive streams too
auto itInactive = std::find_if(_streams.inactive.cbegin(), _streams.inactive.cend(), [nodeID](const MixableStream& mixableStream){
return mixableStream.nodeStreamID.nodeID == nodeID && mixableStream.nodeStreamID.streamID.isNull();
});
if (itInactive != _streams.active.cend()) {
itInactive->hrtf->setGainAdjustment(gain);
return;
} }
} }

View file

@ -16,6 +16,8 @@
#include <string.h> #include <string.h>
#include <algorithm> #include <algorithm>
#include <qdebug.h>
#include "AudioHelpers.h" #include "AudioHelpers.h"
static const int HRTF_AZIMUTHS = 72; // 360 / 5-degree steps static const int HRTF_AZIMUTHS = 72; // 360 / 5-degree steps
@ -80,7 +82,10 @@ public:
// //
// HRTF local gain adjustment in amplitude (1.0 == unity) // HRTF local gain adjustment in amplitude (1.0 == unity)
// //
void setGainAdjustment(float gain) { _gainAdjust = HRTF_GAIN * gain; }; void setGainAdjustment(float gain) {
_gainAdjust = HRTF_GAIN * gain;
qDebug() << "AudioHRTF::setGainAdjustment: " << _gainAdjust;
};
float getGainAdjustment() { return _gainAdjust; } float getGainAdjustment() { return _gainAdjust; }
// clear internal state, but retain settings // clear internal state, but retain settings