Bug 1157635 - Use DenormalDisabler.h to automatically flush subnormals; r=karlt

This adds a DenormalDisabler instance at the beginning of each
MediaStreamGraph iteration. On supported platforms, this will cause subnormal
numbers to be flushed automatically.

MozReview-Commit-ID: JGtunsqSirR

--HG--
extra : rebase_source : b051708f5191a267fc2eaef0ae40f438e1a77e4a
This commit is contained in:
Dan Minor 2016-08-05 15:33:08 -04:00
Родитель 7c22a70554
Коммит 46844007d0
5 изменённых файлов: 18 добавлений и 9 удалений

Просмотреть файл

@ -36,6 +36,7 @@
#endif
#include "mtransport/runnable_utils.h"
#include "webaudio/blink/DenormalDisabler.h"
#include "webaudio/blink/HRTFDatabaseLoader.h"
using namespace mozilla::layers;
@ -1400,6 +1401,8 @@ MediaStreamGraphImpl::UpdateMainThreadState()
bool
MediaStreamGraphImpl::OneIteration(GraphTime aStateEnd)
{
WebCore::DenormalDisabler disabler;
// Process graph message from the main thread for this iteration.
RunMessagesInQueue();

Просмотреть файл

@ -28,6 +28,8 @@
#include "Biquad.h"
#include "DenormalDisabler.h"
#include <float.h>
#include <algorithm>
#include <math.h>
@ -76,15 +78,16 @@ void Biquad::process(const float* sourceP, float* destP, size_t framesToProcess)
// Avoid introducing a stream of subnormals when input is silent and the
// tail approaches zero.
// TODO: Remove this code when Bug 1157635 is fixed.
if (x1 == 0.0 && x2 == 0.0 && (y1 != 0.0 || y2 != 0.0) &&
fabs(y1) < FLT_MIN && fabs(y2) < FLT_MIN) {
// Flush future values to zero (until there is new input).
y1 = y2 = 0.0;
// Flush calculated values.
#ifndef HAVE_DENORMAL
for (int i = framesToProcess; i-- && fabsf(destP[i]) < FLT_MIN; ) {
destP[i] = 0.0f;
}
#endif
}
// Local variables back to member.
m_x1 = x1;

Просмотреть файл

@ -165,6 +165,4 @@ public:
#endif
} // namespace WebCore
#undef HAVE_DENORMAL
#endif // DenormalDisabler_h

Просмотреть файл

@ -4,6 +4,10 @@
#include "IIRFilter.h"
#include "DenormalDisabler.h"
#include <mozilla/Assertions.h>
#include <complex>
namespace blink {
@ -99,12 +103,8 @@ void IIRFilter::process(const float* sourceP, float* destP, size_t framesToProce
m_bufferIndex = (m_bufferIndex + 1) & (kBufferLength - 1);
// Avoid introducing a stream of subnormals
// TODO: Remove this code when Bug 1157635 is fixed.
if (fabs(yn) >= FLT_MIN) {
destP[n] = yn;
} else {
destP[n] = 0.0;
}
destP[n] = WebCore::DenormalDisabler::flushDenormalFloatToZero(yn);
MOZ_ASSERT(destP[n] == 0.0 || fabs(destP[n]) > FLT_MIN, "output should not be subnormal");
}
}

Просмотреть файл

@ -28,6 +28,8 @@
#include "ZeroPole.h"
#include "DenormalDisabler.h"
#include <cmath>
#include <float.h>
@ -62,14 +64,17 @@ void ZeroPole::process(const float *source, float *destination, int framesToProc
// Locals to member variables. Flush denormals here so we don't
// slow down the inner loop above.
#ifndef HAVE_DENORMAL
if (lastX == 0.0f && lastY != 0.0f && fabsf(lastY) < FLT_MIN) {
// Flush future values to zero (until there is new input).
lastY = 0.0;
// Flush calculated values.
for (int i = framesToProcess; i-- && fabsf(destination[i]) < FLT_MIN; ) {
destination[i] = 0.0f;
}
}
#endif
m_lastX = lastX;
m_lastY = lastY;