mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 20:31:29 +02:00
added dirty fix for NaN _nextOutputTrailingLoudness
This commit is contained in:
parent
c5e0da0477
commit
d369435240
2 changed files with 40 additions and 7 deletions
|
@ -366,6 +366,11 @@ void AudioMixer::addBufferToMixForListeningNodeWithBuffer(PositionalAudioRingBuf
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioMixer::prepareMixForListeningNode(Node* node) {
|
void AudioMixer::prepareMixForListeningNode(Node* node) {
|
||||||
|
|
||||||
|
static int k = 0;
|
||||||
|
k++;
|
||||||
|
bool debug = (k % 20) == 0;
|
||||||
|
|
||||||
AvatarAudioRingBuffer* nodeRingBuffer = ((AudioMixerClientData*) node->getLinkedData())->getAvatarAudioRingBuffer();
|
AvatarAudioRingBuffer* nodeRingBuffer = ((AudioMixerClientData*) node->getLinkedData())->getAvatarAudioRingBuffer();
|
||||||
|
|
||||||
// zero out the client mix for this node
|
// zero out the client mix for this node
|
||||||
|
@ -381,11 +386,30 @@ void AudioMixer::prepareMixForListeningNode(Node* node) {
|
||||||
for (int i = 0; i < otherNodeClientData->getRingBuffers().size(); i++) {
|
for (int i = 0; i < otherNodeClientData->getRingBuffers().size(); i++) {
|
||||||
PositionalAudioRingBuffer* otherNodeBuffer = otherNodeClientData->getRingBuffers()[i];
|
PositionalAudioRingBuffer* otherNodeBuffer = otherNodeClientData->getRingBuffers()[i];
|
||||||
|
|
||||||
|
|
||||||
if ((*otherNode != *node
|
if ((*otherNode != *node
|
||||||
|| otherNodeBuffer->shouldLoopbackForNode())
|
|| otherNodeBuffer->shouldLoopbackForNode())
|
||||||
&& otherNodeBuffer->willBeAddedToMix()
|
&& otherNodeBuffer->willBeAddedToMix()
|
||||||
&& otherNodeBuffer->getNextOutputTrailingLoudness() > 0) {
|
&& otherNodeBuffer->getNextOutputTrailingLoudness() > 0.0f) {
|
||||||
addBufferToMixForListeningNodeWithBuffer(otherNodeBuffer, nodeRingBuffer);
|
addBufferToMixForListeningNodeWithBuffer(otherNodeBuffer, nodeRingBuffer);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
//if (debug) {
|
||||||
|
printf("\nWILL NOT MIX!!!\n");
|
||||||
|
printf("listening node = %s\n", node->getUUID().toString().toLatin1().data());
|
||||||
|
printf("other node = %s\n", otherNode->getUUID().toString().toLatin1().data());
|
||||||
|
|
||||||
|
if (otherNodeBuffer->getType() == PositionalAudioRingBuffer::Microphone)
|
||||||
|
printf("\t avatar buffer...\n");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("\t inj buffer %s\n", ((InjectedAudioRingBuffer*)otherNodeBuffer)->getStreamIdentifier().toString().toLatin1().data());
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\t\t other==listening || shouldLoopBack: %d\n", (*otherNode != *node || otherNodeBuffer->shouldLoopbackForNode()));
|
||||||
|
printf("\t\t other will be added to mix: %d\n", otherNodeBuffer->willBeAddedToMix());
|
||||||
|
printf("\t\t other trailing loudess: %f\n", otherNodeBuffer->getNextOutputTrailingLoudness());
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ PositionalAudioRingBuffer::PositionalAudioRingBuffer(PositionalAudioRingBuffer::
|
||||||
_shouldLoopbackForNode(false),
|
_shouldLoopbackForNode(false),
|
||||||
_shouldOutputStarveDebug(true),
|
_shouldOutputStarveDebug(true),
|
||||||
_isStereo(isStereo),
|
_isStereo(isStereo),
|
||||||
|
_nextOutputTrailingLoudness(0.0f),
|
||||||
_listenerUnattenuatedZone(NULL),
|
_listenerUnattenuatedZone(NULL),
|
||||||
_lastFrameReceivedTime(0),
|
_lastFrameReceivedTime(0),
|
||||||
_interframeTimeGapStatsForJitterCalc(TIME_GAPS_FOR_JITTER_CALC_INTERVAL_SAMPLES, TIME_GAPS_FOR_JITTER_CALC_WINDOW_INTERVALS),
|
_interframeTimeGapStatsForJitterCalc(TIME_GAPS_FOR_JITTER_CALC_INTERVAL_SAMPLES, TIME_GAPS_FOR_JITTER_CALC_WINDOW_INTERVALS),
|
||||||
|
@ -121,27 +122,35 @@ void PositionalAudioRingBuffer::updateNextOutputTrailingLoudness() {
|
||||||
// ForBoundarySamples means that we expect the number of samples not to roll of the end of the ring buffer
|
// ForBoundarySamples means that we expect the number of samples not to roll of the end of the ring buffer
|
||||||
float nextLoudness = 0;
|
float nextLoudness = 0;
|
||||||
|
|
||||||
for (int i = 0; i < _numFrameSamples; ++i) {
|
if (samplesAvailable() >= _numFrameSamples) {
|
||||||
nextLoudness += fabsf(_nextOutput[i]);
|
for (int i = 0; i < _numFrameSamples; ++i) {
|
||||||
|
nextLoudness += fabsf(_nextOutput[i]);
|
||||||
|
}
|
||||||
|
nextLoudness /= _numFrameSamples;
|
||||||
|
nextLoudness /= MAX_SAMPLE_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
nextLoudness /= _numFrameSamples;
|
|
||||||
nextLoudness /= MAX_SAMPLE_VALUE;
|
|
||||||
|
|
||||||
const int TRAILING_AVERAGE_FRAMES = 100;
|
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;
|
||||||
const float LOUDNESS_EPSILON = 0.000001f;
|
const float LOUDNESS_EPSILON = 0.000001f;
|
||||||
|
|
||||||
|
float oldNextOutputTrailingLoudness = _nextOutputTrailingLoudness;
|
||||||
if (nextLoudness >= _nextOutputTrailingLoudness) {
|
if (nextLoudness >= _nextOutputTrailingLoudness) {
|
||||||
_nextOutputTrailingLoudness = nextLoudness;
|
_nextOutputTrailingLoudness = nextLoudness;
|
||||||
} else {
|
} else {
|
||||||
_nextOutputTrailingLoudness = (_nextOutputTrailingLoudness * PREVIOUS_FRAMES_RATIO) + (CURRENT_FRAME_RATIO * nextLoudness);
|
_nextOutputTrailingLoudness = (_nextOutputTrailingLoudness * PREVIOUS_FRAMES_RATIO) + (CURRENT_FRAME_RATIO * nextLoudness);
|
||||||
|
|
||||||
if (_nextOutputTrailingLoudness < LOUDNESS_EPSILON) {
|
if (_nextOutputTrailingLoudness < LOUDNESS_EPSILON) {
|
||||||
_nextOutputTrailingLoudness = 0;
|
_nextOutputTrailingLoudness = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fixes bug on Windows where _nextOutputTrailingLoudness sometimes becomes NaN. In that case,
|
||||||
|
// revert _nextOutputTrailingLoudness to its previous value
|
||||||
|
if (isNaN(_nextOutputTrailingLoudness)) {
|
||||||
|
_nextOutputTrailingLoudness = oldNextOutputTrailingLoudness;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PositionalAudioRingBuffer::shouldBeAddedToMix() {
|
bool PositionalAudioRingBuffer::shouldBeAddedToMix() {
|
||||||
|
|
Loading…
Reference in a new issue