check for silent samples befor limiting

This commit is contained in:
Zach Pomerantz 2017-03-08 02:59:48 -05:00
parent e69d6d8b5f
commit 7e2f1a6455

View file

@ -222,17 +222,19 @@ bool AudioMixerSlave::prepareMix(const SharedNodePointer& listener) {
stats.mixTime += mixTime.count(); stats.mixTime += mixTime.count();
#endif #endif
// use the per listener AudioLimiter to render the mixed data... // check for silent audio before limiting
listenerData->audioLimiter.render(_mixSamples, _bufferSamples, AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL); // limiting uses a dither and can only guarantee abs(sample) <= 1
// check for silent audio after the peak limiter has converted the samples
bool hasAudio = false; bool hasAudio = false;
for (int i = 0; i < AudioConstants::NETWORK_FRAME_SAMPLES_STEREO; ++i) { for (int i = 0; i < AudioConstants::NETWORK_FRAME_SAMPLES_STEREO; ++i) {
if (_bufferSamples[i] != 0) { if (_mixSamples[i] != 0.0f) {
hasAudio = true; hasAudio = true;
break; break;
} }
} }
// use the per listener AudioLimiter to render the mixed data
listenerData->audioLimiter.render(_mixSamples, _bufferSamples, AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL);
return hasAudio; return hasAudio;
} }