mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 14:09:01 +02:00
working on audio mixer muting
This commit is contained in:
parent
4b7eb682b3
commit
f10aeaffab
6 changed files with 57 additions and 1 deletions
|
@ -61,6 +61,7 @@
|
||||||
|
|
||||||
const float LOUDNESS_TO_DISTANCE_RATIO = 0.00001f;
|
const float LOUDNESS_TO_DISTANCE_RATIO = 0.00001f;
|
||||||
const float DEFAULT_ATTENUATION_PER_DOUBLING_IN_DISTANCE = 0.18;
|
const float DEFAULT_ATTENUATION_PER_DOUBLING_IN_DISTANCE = 0.18;
|
||||||
|
const float DEFAULT_NOISE_MUTING_THRESHOLD = 100.0f;
|
||||||
|
|
||||||
const QString AUDIO_MIXER_LOGGING_TARGET_NAME = "audio-mixer";
|
const QString AUDIO_MIXER_LOGGING_TARGET_NAME = "audio-mixer";
|
||||||
const QString AUDIO_ENV_GROUP_KEY = "audio_env";
|
const QString AUDIO_ENV_GROUP_KEY = "audio_env";
|
||||||
|
@ -78,12 +79,18 @@ bool AudioMixer::_printStreamStats = false;
|
||||||
|
|
||||||
bool AudioMixer::_enableFilter = true;
|
bool AudioMixer::_enableFilter = true;
|
||||||
|
|
||||||
|
bool AudioMixer::shouldMute(float quietestFrame, float loudestFrame) {
|
||||||
|
return (quietestFrame > _noiseMutingThreshold);
|
||||||
|
qDebug() << "Muting, quiestest frame = " << quietestFrame;
|
||||||
|
}
|
||||||
|
|
||||||
AudioMixer::AudioMixer(const QByteArray& packet) :
|
AudioMixer::AudioMixer(const QByteArray& packet) :
|
||||||
ThreadedAssignment(packet),
|
ThreadedAssignment(packet),
|
||||||
_trailingSleepRatio(1.0f),
|
_trailingSleepRatio(1.0f),
|
||||||
_minAudibilityThreshold(LOUDNESS_TO_DISTANCE_RATIO / 2.0f),
|
_minAudibilityThreshold(LOUDNESS_TO_DISTANCE_RATIO / 2.0f),
|
||||||
_performanceThrottlingRatio(0.0f),
|
_performanceThrottlingRatio(0.0f),
|
||||||
_attenuationPerDoublingInDistance(DEFAULT_ATTENUATION_PER_DOUBLING_IN_DISTANCE),
|
_attenuationPerDoublingInDistance(DEFAULT_ATTENUATION_PER_DOUBLING_IN_DISTANCE),
|
||||||
|
_noiseMutingThreshold(DEFAULT_NOISE_MUTING_THRESHOLD),
|
||||||
_numStatFrames(0),
|
_numStatFrames(0),
|
||||||
_sumListeners(0),
|
_sumListeners(0),
|
||||||
_sumMixes(0),
|
_sumMixes(0),
|
||||||
|
@ -136,6 +143,11 @@ int AudioMixer::addStreamToMixForListeningNodeWithStream(AudioMixerClientData* l
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if the stream should be muted, bail
|
||||||
|
if (shouldMute(streamToAdd->getQuietestTrailingFrameLoudness(), streamToAdd->getLoudestTrailingFrameLoudness())) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
float bearingRelativeAngleToSource = 0.0f;
|
float bearingRelativeAngleToSource = 0.0f;
|
||||||
float attenuationCoefficient = 1.0f;
|
float attenuationCoefficient = 1.0f;
|
||||||
int numSamplesDelay = 0;
|
int numSamplesDelay = 0;
|
||||||
|
|
|
@ -59,6 +59,8 @@ private:
|
||||||
int16_t _mixSamples[NETWORK_BUFFER_LENGTH_SAMPLES_STEREO + (SAMPLE_PHASE_DELAY_AT_90 * 2)];
|
int16_t _mixSamples[NETWORK_BUFFER_LENGTH_SAMPLES_STEREO + (SAMPLE_PHASE_DELAY_AT_90 * 2)];
|
||||||
|
|
||||||
void perSecondActions();
|
void perSecondActions();
|
||||||
|
|
||||||
|
bool shouldMute(float quietestFrame, float loudestFrame);
|
||||||
|
|
||||||
QString getReadPendingDatagramsCallsPerSecondsStatsString() const;
|
QString getReadPendingDatagramsCallsPerSecondsStatsString() const;
|
||||||
QString getReadPendingDatagramsPacketsPerCallStatsString() const;
|
QString getReadPendingDatagramsPacketsPerCallStatsString() const;
|
||||||
|
@ -71,6 +73,7 @@ private:
|
||||||
float _minAudibilityThreshold;
|
float _minAudibilityThreshold;
|
||||||
float _performanceThrottlingRatio;
|
float _performanceThrottlingRatio;
|
||||||
float _attenuationPerDoublingInDistance;
|
float _attenuationPerDoublingInDistance;
|
||||||
|
float _noiseMutingThreshold;
|
||||||
int _numStatFrames;
|
int _numStatFrames;
|
||||||
int _sumListeners;
|
int _sumListeners;
|
||||||
int _sumMixes;
|
int _sumMixes;
|
||||||
|
|
|
@ -77,6 +77,9 @@ Audio::Audio(QObject* parent) :
|
||||||
_isStereoInput(false),
|
_isStereoInput(false),
|
||||||
_averagedLatency(0.0),
|
_averagedLatency(0.0),
|
||||||
_lastInputLoudness(0),
|
_lastInputLoudness(0),
|
||||||
|
_inputFrameCounter(0),
|
||||||
|
_quietestFrame(std::numeric_limits<float>::max()),
|
||||||
|
_loudestFrame(0.0f),
|
||||||
_timeSinceLastClip(-1.0),
|
_timeSinceLastClip(-1.0),
|
||||||
_dcOffset(0),
|
_dcOffset(0),
|
||||||
_noiseGateMeasuredFloor(0),
|
_noiseGateMeasuredFloor(0),
|
||||||
|
@ -717,6 +720,21 @@ void Audio::handleAudioInput() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_lastInputLoudness = fabs(loudness / NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
|
_lastInputLoudness = fabs(loudness / NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL);
|
||||||
|
|
||||||
|
if (_quietestFrame > _lastInputLoudness) {
|
||||||
|
_quietestFrame = _lastInputLoudness;
|
||||||
|
}
|
||||||
|
if (_loudestFrame < _lastInputLoudness) {
|
||||||
|
_loudestFrame = _lastInputLoudness;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int FRAMES_FOR_NOISE_DETECTION = 300;
|
||||||
|
if (_inputFrameCounter++ > FRAMES_FOR_NOISE_DETECTION) {
|
||||||
|
qDebug() << "Quietest/loudest frame: " << _quietestFrame << " / " << _loudestFrame << " NGfloor: " << _noiseGateMeasuredFloor;
|
||||||
|
_quietestFrame = std::numeric_limits<float>::max();
|
||||||
|
_loudestFrame = 0.0f;
|
||||||
|
_inputFrameCounter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// If Noise Gate is enabled, check and turn the gate on and off
|
// If Noise Gate is enabled, check and turn the gate on and off
|
||||||
if (!_audioSourceInjectEnabled && _noiseGateEnabled) {
|
if (!_audioSourceInjectEnabled && _noiseGateEnabled) {
|
||||||
|
|
|
@ -212,6 +212,9 @@ private:
|
||||||
QElapsedTimer _timeSinceLastReceived;
|
QElapsedTimer _timeSinceLastReceived;
|
||||||
float _averagedLatency;
|
float _averagedLatency;
|
||||||
float _lastInputLoudness;
|
float _lastInputLoudness;
|
||||||
|
int _inputFrameCounter;
|
||||||
|
float _quietestFrame;
|
||||||
|
float _loudestFrame;
|
||||||
float _timeSinceLastClip;
|
float _timeSinceLastClip;
|
||||||
float _dcOffset;
|
float _dcOffset;
|
||||||
float _noiseGateMeasuredFloor;
|
float _noiseGateMeasuredFloor;
|
||||||
|
|
|
@ -30,7 +30,10 @@ PositionalAudioStream::PositionalAudioStream(PositionalAudioStream::Type type, b
|
||||||
_shouldLoopbackForNode(false),
|
_shouldLoopbackForNode(false),
|
||||||
_isStereo(isStereo),
|
_isStereo(isStereo),
|
||||||
_lastPopOutputTrailingLoudness(0.0f),
|
_lastPopOutputTrailingLoudness(0.0f),
|
||||||
_lastPopOutputLoudness(0.0f)
|
_lastPopOutputLoudness(0.0f),
|
||||||
|
_quietestTrailingFrameLoudness(std::numeric_limits<float>::max()),
|
||||||
|
_loudestTrailingFrameLoudness(0.0f),
|
||||||
|
_frameCounter(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +59,17 @@ void PositionalAudioStream::updateLastPopOutputLoudnessAndTrailingLoudness() {
|
||||||
_lastPopOutputTrailingLoudness = 0;
|
_lastPopOutputTrailingLoudness = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (_frameCounter++ == TRAILING_AVERAGE_FRAMES) {
|
||||||
|
_frameCounter = 0;
|
||||||
|
_quietestTrailingFrameLoudness = std::numeric_limits<float>::max();
|
||||||
|
_loudestTrailingFrameLoudness = 0.0f;
|
||||||
|
}
|
||||||
|
if (_lastPopOutputLoudness < _quietestTrailingFrameLoudness) {
|
||||||
|
_quietestTrailingFrameLoudness = _lastPopOutputLoudness;
|
||||||
|
}
|
||||||
|
if (_lastPopOutputLoudness > _loudestTrailingFrameLoudness) {
|
||||||
|
_loudestTrailingFrameLoudness = _lastPopOutputLoudness;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int PositionalAudioStream::parsePositionalData(const QByteArray& positionalByteArray) {
|
int PositionalAudioStream::parsePositionalData(const QByteArray& positionalByteArray) {
|
||||||
|
|
|
@ -36,12 +36,15 @@ public:
|
||||||
void updateLastPopOutputLoudnessAndTrailingLoudness();
|
void updateLastPopOutputLoudnessAndTrailingLoudness();
|
||||||
float getLastPopOutputTrailingLoudness() const { return _lastPopOutputTrailingLoudness; }
|
float getLastPopOutputTrailingLoudness() const { return _lastPopOutputTrailingLoudness; }
|
||||||
float getLastPopOutputLoudness() const { return _lastPopOutputLoudness; }
|
float getLastPopOutputLoudness() const { return _lastPopOutputLoudness; }
|
||||||
|
float getQuietestTrailingFrameLoudness() const { return _quietestTrailingFrameLoudness; }
|
||||||
|
float getLoudestTrailingFrameLoudness() const { return _loudestTrailingFrameLoudness; }
|
||||||
|
|
||||||
bool shouldLoopbackForNode() const { return _shouldLoopbackForNode; }
|
bool shouldLoopbackForNode() const { return _shouldLoopbackForNode; }
|
||||||
bool isStereo() const { return _isStereo; }
|
bool isStereo() const { return _isStereo; }
|
||||||
PositionalAudioStream::Type getType() const { return _type; }
|
PositionalAudioStream::Type getType() const { return _type; }
|
||||||
const glm::vec3& getPosition() const { return _position; }
|
const glm::vec3& getPosition() const { return _position; }
|
||||||
const glm::quat& getOrientation() const { return _orientation; }
|
const glm::quat& getOrientation() const { return _orientation; }
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// disallow copying of PositionalAudioStream objects
|
// disallow copying of PositionalAudioStream objects
|
||||||
|
@ -60,6 +63,9 @@ protected:
|
||||||
|
|
||||||
float _lastPopOutputTrailingLoudness;
|
float _lastPopOutputTrailingLoudness;
|
||||||
float _lastPopOutputLoudness;
|
float _lastPopOutputLoudness;
|
||||||
|
float _quietestTrailingFrameLoudness;
|
||||||
|
float _loudestTrailingFrameLoudness;
|
||||||
|
int _frameCounter;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_PositionalAudioStream_h
|
#endif // hifi_PositionalAudioStream_h
|
||||||
|
|
Loading…
Reference in a new issue