mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 16:36:54 +02:00
Merge pull request #2439 from birarda/master
check for an audio cutoff change only every TRAILING_AVERAGE_FRAMES
This commit is contained in:
commit
949aefac62
2 changed files with 41 additions and 28 deletions
|
@ -364,6 +364,9 @@ void AudioMixer::run() {
|
||||||
|
|
||||||
int usecToSleep = BUFFER_SEND_INTERVAL_USECS;
|
int usecToSleep = BUFFER_SEND_INTERVAL_USECS;
|
||||||
float audabilityCutoffRatio = 0;
|
float audabilityCutoffRatio = 0;
|
||||||
|
|
||||||
|
const int TRAILING_AVERAGE_FRAMES = 100;
|
||||||
|
int framesSinceCutoffEvent = TRAILING_AVERAGE_FRAMES;
|
||||||
|
|
||||||
while (!_isFinished) {
|
while (!_isFinished) {
|
||||||
|
|
||||||
|
@ -374,10 +377,9 @@ void AudioMixer::run() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const float STRUGGLE_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD = 0.10f;
|
const float STRUGGLE_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD = 0.10f;
|
||||||
const float BACK_OFF_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD = 0.30f;
|
const float BACK_OFF_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD = 0.20f;
|
||||||
const float CUTOFF_EPSILON = 0.0001f;
|
const float CUTOFF_EPSILON = 0.0001f;
|
||||||
|
|
||||||
const int TRAILING_AVERAGE_FRAMES = 100;
|
|
||||||
const float CURRENT_FRAME_RATIO = 1.0f / TRAILING_AVERAGE_FRAMES;
|
const float CURRENT_FRAME_RATIO = 1.0f / TRAILING_AVERAGE_FRAMES;
|
||||||
const float PREVIOUS_FRAMES_RATIO = 1.0f - CURRENT_FRAME_RATIO;
|
const float PREVIOUS_FRAMES_RATIO = 1.0f - CURRENT_FRAME_RATIO;
|
||||||
|
|
||||||
|
@ -391,30 +393,36 @@ void AudioMixer::run() {
|
||||||
float lastCutoffRatio = audabilityCutoffRatio;
|
float lastCutoffRatio = audabilityCutoffRatio;
|
||||||
bool hasRatioChanged = false;
|
bool hasRatioChanged = false;
|
||||||
|
|
||||||
if (_trailingSleepRatio <= STRUGGLE_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD) {
|
if (framesSinceCutoffEvent >= TRAILING_AVERAGE_FRAMES) {
|
||||||
// we're struggling - change our min required loudness to reduce some load
|
if (_trailingSleepRatio <= STRUGGLE_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD) {
|
||||||
audabilityCutoffRatio += (1.0f - audabilityCutoffRatio) / 2.0f;
|
// we're struggling - change our min required loudness to reduce some load
|
||||||
|
audabilityCutoffRatio += (1.0f - audabilityCutoffRatio) / 2.0f;
|
||||||
qDebug() << "Mixer is struggling, sleeping" << _trailingSleepRatio * 100 << "% of frame time. Old cutoff was"
|
|
||||||
<< lastCutoffRatio << "and is now" << audabilityCutoffRatio;
|
qDebug() << "Mixer is struggling, sleeping" << _trailingSleepRatio * 100 << "% of frame time. Old cutoff was"
|
||||||
hasRatioChanged = true;
|
<< lastCutoffRatio << "and is now" << audabilityCutoffRatio;
|
||||||
} else if (_trailingSleepRatio >= BACK_OFF_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD && audabilityCutoffRatio != 0) {
|
hasRatioChanged = true;
|
||||||
// we've recovered and can back off the required loudness
|
} else if (_trailingSleepRatio >= BACK_OFF_TRIGGER_SLEEP_PERCENTAGE_THRESHOLD && audabilityCutoffRatio != 0) {
|
||||||
audabilityCutoffRatio -= audabilityCutoffRatio / 2.0f;
|
// we've recovered and can back off the required loudness
|
||||||
|
audabilityCutoffRatio -= audabilityCutoffRatio / 2.0f;
|
||||||
if (audabilityCutoffRatio < CUTOFF_EPSILON) {
|
|
||||||
audabilityCutoffRatio = 0.0f;
|
if (audabilityCutoffRatio < CUTOFF_EPSILON) {
|
||||||
|
audabilityCutoffRatio = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "Mixer is recovering, sleeping" << _trailingSleepRatio * 100 << "% of frame time. Old cutoff was"
|
||||||
|
<< lastCutoffRatio << "and is now" << audabilityCutoffRatio;
|
||||||
|
hasRatioChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug() << "Mixer is recovering, sleeping" << _trailingSleepRatio * 100 << "% of frame time. Old cutoff was"
|
if (hasRatioChanged) {
|
||||||
<< lastCutoffRatio << "and is now" << audabilityCutoffRatio;
|
// set out min audability threshold from the new ratio
|
||||||
hasRatioChanged = true;
|
_minAudibilityThreshold = LOUDNESS_TO_DISTANCE_RATIO / (2.0f * (1.0f - audabilityCutoffRatio));
|
||||||
}
|
qDebug() << "Minimum audability required to be mixed is now" << _minAudibilityThreshold;
|
||||||
|
|
||||||
if (hasRatioChanged) {
|
framesSinceCutoffEvent = 0;
|
||||||
// set out min required loudness from the new ratio
|
}
|
||||||
_minAudibilityThreshold = LOUDNESS_TO_DISTANCE_RATIO / (2.0f * (1.0f - audabilityCutoffRatio));
|
} else {
|
||||||
qDebug() << "Minimum loudness required to be mixed is now" << _minAudibilityThreshold;
|
framesSinceCutoffEvent++;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (const SharedNodePointer& node, nodeList->getNodeHash()) {
|
foreach (const SharedNodePointer& node, nodeList->getNodeHash()) {
|
||||||
|
@ -446,10 +454,7 @@ void AudioMixer::run() {
|
||||||
|
|
||||||
if (usecToSleep > 0) {
|
if (usecToSleep > 0) {
|
||||||
usleep(usecToSleep);
|
usleep(usecToSleep);
|
||||||
} else {
|
|
||||||
qDebug() << "AudioMixer loop took" << -usecToSleep << "of extra time. Not sleeping.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] clientMixBuffer;
|
delete[] clientMixBuffer;
|
||||||
|
|
|
@ -67,7 +67,15 @@ void AudioRingBuffer::updateAverageLoudnessForBoundarySamples(int numSamples) {
|
||||||
nextLoudness /= numSamples;
|
nextLoudness /= numSamples;
|
||||||
nextLoudness /= MAX_SAMPLE_VALUE;
|
nextLoudness /= MAX_SAMPLE_VALUE;
|
||||||
|
|
||||||
_averageLoudness = nextLoudness;
|
const int TRAILING_AVERAGE_FRAMES = 100;
|
||||||
|
const float CURRENT_FRAME_RATIO = 1 / TRAILING_AVERAGE_FRAMES;
|
||||||
|
const float PREVIOUS_FRAMES_RATIO = 1 - CURRENT_FRAME_RATIO;
|
||||||
|
|
||||||
|
if (nextLoudness >= _averageLoudness) {
|
||||||
|
_averageLoudness = nextLoudness;
|
||||||
|
} else {
|
||||||
|
_averageLoudness = (_averageLoudness * PREVIOUS_FRAMES_RATIO) + (CURRENT_FRAME_RATIO * nextLoudness);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 AudioRingBuffer::readSamples(int16_t* destination, qint64 maxSamples) {
|
qint64 AudioRingBuffer::readSamples(int16_t* destination, qint64 maxSamples) {
|
||||||
|
|
Loading…
Reference in a new issue