mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 19:04:32 +02:00
Move mute environment handling to Application
This commit is contained in:
parent
dd9dea7a97
commit
5e65f422fa
3 changed files with 19 additions and 47 deletions
|
@ -419,6 +419,17 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
&AudioScriptingInterface::getInstance(), &AudioScriptingInterface::receivedFirstPacket);
|
||||
connect(audioIO.data(), &AudioClient::disconnected,
|
||||
&AudioScriptingInterface::getInstance(), &AudioScriptingInterface::disconnected);
|
||||
connect(audioIO.data(), &AudioClient::muteEnvironmentRequested, [](glm::vec3 position, float radius) {
|
||||
auto audioClient = DependencyManager::get<AudioClient>();
|
||||
float distance = glm::distance(DependencyManager::get<AvatarManager>()->getMyAvatar()->getPosition(),
|
||||
position);
|
||||
bool shouldMute = !audioClient->isMuted() && (distance < radius);
|
||||
|
||||
if (shouldMute) {
|
||||
audioClient->toggleMute();
|
||||
AudioScriptingInterface::getInstance().environmentMuted();
|
||||
}
|
||||
});
|
||||
|
||||
audioThread->start();
|
||||
|
||||
|
|
|
@ -602,19 +602,13 @@ void AudioClient::handleMuteEnvironmentPacket(std::unique_ptr<NLPacket> packet,
|
|||
int headerSize = numBytesForPacketHeaderGivenPacketType(PacketType::MuteEnvironment);
|
||||
memcpy(&position, packet->getPayload(), sizeof(glm::vec3));
|
||||
memcpy(&radius, packet->getPayload() + sizeof(glm::vec3), sizeof(float));
|
||||
float distance = glm::distance(DependencyManager::get<AvatarManager>()->getMyAvatar()->getPosition(),
|
||||
position);
|
||||
bool shouldMute = !_muted && (distance < radius);
|
||||
|
||||
if (shouldMute) {
|
||||
toggleMute();
|
||||
// TODO reimplement on interface side
|
||||
//AudioScriptingInterface::getInstance().environmentMuted();
|
||||
}
|
||||
emit muteEnvironmentRequested(position, radius);
|
||||
}
|
||||
|
||||
void AudioClient::updateLastHeardFromAudioMixer(std::unique_ptr<NLPacket>& packet) {
|
||||
// update having heard from the audio-mixer and record the bytes received
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
SharedNodePointer audioMixer = nodeList->nodeWithUUID(packet->getSourceID());
|
||||
if (audioMixer) {
|
||||
audioMixer->setLastHeardMicrostamp(usecTimestampNow());
|
||||
|
@ -1023,44 +1017,6 @@ void AudioClient::sendMuteEnvironmentPacket() {
|
|||
}
|
||||
}
|
||||
|
||||
void AudioClient::addReceivedAudioToStream(const QByteArray& audioByteArray) {
|
||||
DependencyManager::get<NodeList>()->flagTimeForConnectionStep(LimitedNodeList::ConnectionStep::ReceiveFirstAudioPacket);
|
||||
|
||||
if (_audioOutput) {
|
||||
|
||||
if (!_hasReceivedFirstPacket) {
|
||||
_hasReceivedFirstPacket = true;
|
||||
|
||||
// have the audio scripting interface emit a signal to say we just connected to mixer
|
||||
emit receivedFirstPacket();
|
||||
}
|
||||
|
||||
// Audio output must exist and be correctly set up if we're going to process received audio
|
||||
_receivedAudioStream.parseData(audioByteArray);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioClient::parseAudioEnvironmentData(const QByteArray &packet) {
|
||||
int numBytesPacketHeader = numBytesForPacketHeader(packet);
|
||||
const char* dataAt = packet.constData() + numBytesPacketHeader;
|
||||
|
||||
char bitset;
|
||||
memcpy(&bitset, dataAt, sizeof(char));
|
||||
dataAt += sizeof(char);
|
||||
|
||||
bool hasReverb = oneAtBit(bitset, HAS_REVERB_BIT);;
|
||||
if (hasReverb) {
|
||||
float reverbTime, wetLevel;
|
||||
memcpy(&reverbTime, dataAt, sizeof(float));
|
||||
dataAt += sizeof(float);
|
||||
memcpy(&wetLevel, dataAt, sizeof(float));
|
||||
dataAt += sizeof(float);
|
||||
_receivedAudioStream.setReverb(reverbTime, wetLevel);
|
||||
} else {
|
||||
_receivedAudioStream.clearReverb();
|
||||
}
|
||||
}
|
||||
|
||||
void AudioClient::toggleMute() {
|
||||
_muted = !_muted;
|
||||
emit muteToggled();
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#define hifi_AudioClient_h
|
||||
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <QtCore/QByteArray>
|
||||
|
@ -32,8 +33,10 @@
|
|||
#include <AudioSourceTone.h>
|
||||
#include <AudioSourceNoise.h>
|
||||
#include <AudioStreamStats.h>
|
||||
#include <DependencyManager.h>
|
||||
|
||||
#include <DependencyManager.h>
|
||||
#include <HifiSockAddr.h>
|
||||
#include <NLPacket.h>
|
||||
#include <MixedProcessedAudioStream.h>
|
||||
#include <RingBufferHistory.h>
|
||||
#include <SettingHandle.h>
|
||||
|
@ -197,6 +200,8 @@ signals:
|
|||
|
||||
void audioFinished();
|
||||
|
||||
void muteEnvironmentRequested(glm::vec3 position, float radius);
|
||||
|
||||
protected:
|
||||
AudioClient();
|
||||
~AudioClient();
|
||||
|
|
Loading…
Reference in a new issue