mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 12:37:51 +02:00
Merge pull request #3768 from Atlante45/mute_when_noisy
Mute when noisy / Pulsing mute button
This commit is contained in:
commit
dbc1ba7925
5 changed files with 56 additions and 13 deletions
|
@ -141,11 +141,6 @@ int AudioMixer::addStreamToMixForListeningNodeWithStream(AudioMixerClientData* l
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the stream should be muted, bail
|
|
||||||
if (shouldMute(streamToAdd->getQuietestFrameLoudness())) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
float bearingRelativeAngleToSource = 0.0f;
|
float bearingRelativeAngleToSource = 0.0f;
|
||||||
float attenuationCoefficient = 1.0f;
|
float attenuationCoefficient = 1.0f;
|
||||||
int numSamplesDelay = 0;
|
int numSamplesDelay = 0;
|
||||||
|
@ -722,6 +717,29 @@ void AudioMixer::run() {
|
||||||
// That's how the popped audio data will be read for mixing (but only if the pop was successful)
|
// That's how the popped audio data will be read for mixing (but only if the pop was successful)
|
||||||
nodeData->checkBuffersBeforeFrameSend();
|
nodeData->checkBuffersBeforeFrameSend();
|
||||||
|
|
||||||
|
// if the stream should be muted, send mute packet
|
||||||
|
if (shouldMute(nodeData->getAvatarAudioStream()->getQuietestFrameLoudness())) {
|
||||||
|
static const int TIME_BETWEEN_MUTES = 5; // in secs
|
||||||
|
if (usecTimestampNow() - nodeData->getAvatarAudioStream()->getLastMuted() >
|
||||||
|
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()
|
||||||
&& nodeData->getAvatarAudioStream()) {
|
&& nodeData->getAvatarAudioStream()) {
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
#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())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,18 @@
|
||||||
class AvatarAudioStream : public PositionalAudioStream {
|
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
|
||||||
|
|
|
@ -97,6 +97,9 @@ Audio::Audio(QObject* parent) :
|
||||||
_muted(false),
|
_muted(false),
|
||||||
_reverb(false),
|
_reverb(false),
|
||||||
_reverbOptions(&_scriptReverbOptions),
|
_reverbOptions(&_scriptReverbOptions),
|
||||||
|
_gverb(NULL),
|
||||||
|
_iconColor(1.0f),
|
||||||
|
_iconPulseTimeReference(usecTimestampNow()),
|
||||||
_processSpatialAudio(false),
|
_processSpatialAudio(false),
|
||||||
_spatialAudioStart(0),
|
_spatialAudioStart(0),
|
||||||
_spatialAudioFinish(0),
|
_spatialAudioFinish(0),
|
||||||
|
@ -1390,23 +1393,37 @@ void Audio::renderToolBox(int x, int y, bool boxed) {
|
||||||
_iconBounds = QRect(x, y, MUTE_ICON_SIZE, MUTE_ICON_SIZE);
|
_iconBounds = QRect(x, y, MUTE_ICON_SIZE, MUTE_ICON_SIZE);
|
||||||
if (!_muted) {
|
if (!_muted) {
|
||||||
glBindTexture(GL_TEXTURE_2D, _micTextureId);
|
glBindTexture(GL_TEXTURE_2D, _micTextureId);
|
||||||
|
_iconColor = 1.0f;
|
||||||
} else {
|
} else {
|
||||||
glBindTexture(GL_TEXTURE_2D, _muteTextureId);
|
glBindTexture(GL_TEXTURE_2D, _muteTextureId);
|
||||||
|
|
||||||
|
// Make muted icon pulsate
|
||||||
|
static const float PULSE_MIN = 0.4f;
|
||||||
|
static const float PULSE_MAX = 1.0f;
|
||||||
|
static const float PULSE_FREQUENCY = 1.0f; // in Hz
|
||||||
|
qint64 now = usecTimestampNow();
|
||||||
|
if (now - _iconPulseTimeReference > USECS_PER_SECOND) {
|
||||||
|
// Prevents t from getting too big, which would diminish glm::cos precision
|
||||||
|
_iconPulseTimeReference = now - ((now - _iconPulseTimeReference) % USECS_PER_SECOND);
|
||||||
|
}
|
||||||
|
float t = (float)(now - _iconPulseTimeReference) / (float)USECS_PER_SECOND;
|
||||||
|
float pulseFactor = (glm::cos(t * PULSE_FREQUENCY * 2.0f * PI) + 1.0f) / 2.0f;
|
||||||
|
_iconColor = PULSE_MIN + (PULSE_MAX - PULSE_MIN) * pulseFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
glColor3f(1,1,1);
|
glColor3f(_iconColor, _iconColor, _iconColor);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
|
|
||||||
glTexCoord2f(1, 1);
|
glTexCoord2f(1.0f, 1.0f);
|
||||||
glVertex2f(_iconBounds.left(), _iconBounds.top());
|
glVertex2f(_iconBounds.left(), _iconBounds.top());
|
||||||
|
|
||||||
glTexCoord2f(0, 1);
|
glTexCoord2f(0.0f, 1.0f);
|
||||||
glVertex2f(_iconBounds.right(), _iconBounds.top());
|
glVertex2f(_iconBounds.right(), _iconBounds.top());
|
||||||
|
|
||||||
glTexCoord2f(0, 0);
|
glTexCoord2f(0.0f, 0.0f);
|
||||||
glVertex2f(_iconBounds.right(), _iconBounds.bottom());
|
glVertex2f(_iconBounds.right(), _iconBounds.bottom());
|
||||||
|
|
||||||
glTexCoord2f(1, 0);
|
glTexCoord2f(1.0f, 0.0f);
|
||||||
glVertex2f(_iconBounds.left(), _iconBounds.bottom());
|
glVertex2f(_iconBounds.left(), _iconBounds.bottom());
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
|
@ -248,11 +248,13 @@ private:
|
||||||
AudioEffectOptions _scriptReverbOptions;
|
AudioEffectOptions _scriptReverbOptions;
|
||||||
AudioEffectOptions _zoneReverbOptions;
|
AudioEffectOptions _zoneReverbOptions;
|
||||||
AudioEffectOptions* _reverbOptions;
|
AudioEffectOptions* _reverbOptions;
|
||||||
ty_gverb *_gverb;
|
ty_gverb* _gverb;
|
||||||
GLuint _micTextureId;
|
GLuint _micTextureId;
|
||||||
GLuint _muteTextureId;
|
GLuint _muteTextureId;
|
||||||
GLuint _boxTextureId;
|
GLuint _boxTextureId;
|
||||||
QRect _iconBounds;
|
QRect _iconBounds;
|
||||||
|
float _iconColor;
|
||||||
|
qint64 _iconPulseTimeReference;
|
||||||
|
|
||||||
/// Audio callback in class context.
|
/// Audio callback in class context.
|
||||||
inline void performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* outputRight);
|
inline void performIO(int16_t* inputLeft, int16_t* outputLeft, int16_t* outputRight);
|
||||||
|
|
Loading…
Reference in a new issue