mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-05-16 12:21:28 +02:00
commit
c2e80aed70
6 changed files with 27 additions and 34 deletions
|
@ -776,25 +776,8 @@ void AudioMixer::run() {
|
||||||
// if the stream should be muted, send mute packet
|
// if the stream should be muted, send mute packet
|
||||||
if (nodeData->getAvatarAudioStream()
|
if (nodeData->getAvatarAudioStream()
|
||||||
&& shouldMute(nodeData->getAvatarAudioStream()->getQuietestFrameLoudness())) {
|
&& shouldMute(nodeData->getAvatarAudioStream()->getQuietestFrameLoudness())) {
|
||||||
static const int TIME_BETWEEN_MUTES = 5; // in secs
|
QByteArray packet = byteArrayWithPopulatedHeader(PacketTypeNoisyMute);
|
||||||
if (usecTimestampNow() - nodeData->getAvatarAudioStream()->getLastMuted() >
|
nodeList->writeDatagram(packet, node);
|
||||||
TIME_BETWEEN_MUTES * USECS_PER_SECOND) {
|
|
||||||
int headerSize = numBytesForPacketHeaderGivenPacketType(PacketTypeMuteEnvironment);
|
|
||||||
int packetSize = headerSize + sizeof(glm::vec3) + sizeof(float);
|
|
||||||
|
|
||||||
// Fake data to force mute
|
|
||||||
glm::vec3 position = nodeData->getAvatarAudioStream()->getPosition();
|
|
||||||
float radius = 1.0f;
|
|
||||||
|
|
||||||
char* packet = (char*)malloc(packetSize);
|
|
||||||
populatePacketHeader(packet, PacketTypeMuteEnvironment);
|
|
||||||
memcpy(packet + headerSize, &position, sizeof(glm::vec3));
|
|
||||||
memcpy(packet + headerSize + sizeof(glm::vec3), &radius, sizeof(float));
|
|
||||||
|
|
||||||
nodeList->writeDatagram(packet, packetSize, node);
|
|
||||||
nodeData->getAvatarAudioStream()->setLastMutedNow();
|
|
||||||
free(packet);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->getType() == NodeType::Agent && node->getActiveSocket()
|
if (node->getType() == NodeType::Agent && node->getActiveSocket()
|
||||||
|
|
|
@ -14,8 +14,7 @@
|
||||||
#include "AvatarAudioStream.h"
|
#include "AvatarAudioStream.h"
|
||||||
|
|
||||||
AvatarAudioStream::AvatarAudioStream(bool isStereo, const InboundAudioStream::Settings& settings) :
|
AvatarAudioStream::AvatarAudioStream(bool isStereo, const InboundAudioStream::Settings& settings) :
|
||||||
PositionalAudioStream(PositionalAudioStream::Microphone, isStereo, settings),
|
PositionalAudioStream(PositionalAudioStream::Microphone, isStereo, settings)
|
||||||
_lastMuted(usecTimestampNow())
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,17 +20,12 @@ class AvatarAudioStream : public PositionalAudioStream {
|
||||||
public:
|
public:
|
||||||
AvatarAudioStream(bool isStereo, const InboundAudioStream::Settings& settings);
|
AvatarAudioStream(bool isStereo, const InboundAudioStream::Settings& settings);
|
||||||
|
|
||||||
qint64 getLastMuted() const { return _lastMuted; }
|
|
||||||
void setLastMutedNow() { _lastMuted = usecTimestampNow(); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// disallow copying of AvatarAudioStream objects
|
// disallow copying of AvatarAudioStream objects
|
||||||
AvatarAudioStream(const AvatarAudioStream&);
|
AvatarAudioStream(const AvatarAudioStream&);
|
||||||
AvatarAudioStream& operator= (const AvatarAudioStream&);
|
AvatarAudioStream& operator= (const AvatarAudioStream&);
|
||||||
|
|
||||||
int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples);
|
int parseStreamProperties(PacketType type, const QByteArray& packetAfterSeqNum, int& numAudioSamples);
|
||||||
|
|
||||||
qint64 _lastMuted;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AvatarAudioStream_h
|
#endif // hifi_AvatarAudioStream_h
|
||||||
|
|
|
@ -141,17 +141,29 @@ void DatagramProcessor::processDatagrams() {
|
||||||
AccountManager::getInstance().checkAndSignalForAccessToken();
|
AccountManager::getInstance().checkAndSignalForAccessToken();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case PacketTypeNoisyMute:
|
||||||
case PacketTypeMuteEnvironment: {
|
case PacketTypeMuteEnvironment: {
|
||||||
glm::vec3 position;
|
bool mute = !Application::getInstance()->getAudio()->getMuted();
|
||||||
float radius;
|
|
||||||
|
|
||||||
int headerSize = numBytesForPacketHeaderGivenPacketType(PacketTypeMuteEnvironment);
|
if (incomingType == PacketTypeMuteEnvironment) {
|
||||||
memcpy(&position, incomingPacket.constData() + headerSize, sizeof(glm::vec3));
|
glm::vec3 position;
|
||||||
memcpy(&radius, incomingPacket.constData() + headerSize + sizeof(glm::vec3), sizeof(float));
|
float radius, distance;
|
||||||
|
|
||||||
if (glm::distance(Application::getInstance()->getAvatar()->getPosition(), position) < radius
|
int headerSize = numBytesForPacketHeaderGivenPacketType(PacketTypeMuteEnvironment);
|
||||||
&& !Application::getInstance()->getAudio()->getMuted()) {
|
memcpy(&position, incomingPacket.constData() + headerSize, sizeof(glm::vec3));
|
||||||
|
memcpy(&radius, incomingPacket.constData() + headerSize + sizeof(glm::vec3), sizeof(float));
|
||||||
|
distance = glm::distance(Application::getInstance()->getAvatar()->getPosition(), position);
|
||||||
|
|
||||||
|
mute = mute && (distance < radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mute) {
|
||||||
Application::getInstance()->getAudio()->toggleMute();
|
Application::getInstance()->getAudio()->toggleMute();
|
||||||
|
if (incomingType == PacketTypeMuteEnvironment) {
|
||||||
|
AudioScriptingInterface::getInstance().environmentMuted();
|
||||||
|
} else {
|
||||||
|
AudioScriptingInterface::getInstance().mutedByMixer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,10 @@ public slots:
|
||||||
|
|
||||||
void injectorStopped();
|
void injectorStopped();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void mutedByMixer();
|
||||||
|
void environmentMuted();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AudioScriptingInterface();
|
AudioScriptingInterface();
|
||||||
QList< QPointer<AudioInjector> > _activeInjectors;
|
QList< QPointer<AudioInjector> > _activeInjectors;
|
||||||
|
|
|
@ -54,7 +54,7 @@ enum PacketType {
|
||||||
UNUSED_2,
|
UNUSED_2,
|
||||||
UNUSED_3,
|
UNUSED_3,
|
||||||
UNUSED_4,
|
UNUSED_4,
|
||||||
UNUSED_5,
|
PacketTypeNoisyMute,
|
||||||
PacketTypeMetavoxelData,
|
PacketTypeMetavoxelData,
|
||||||
PacketTypeAvatarIdentity,
|
PacketTypeAvatarIdentity,
|
||||||
PacketTypeAvatarBillboard,
|
PacketTypeAvatarBillboard,
|
||||||
|
|
Loading…
Reference in a new issue