diff --git a/dom/media/webaudio/blink/IIRFilter.cpp b/dom/media/webaudio/blink/IIRFilter.cpp index 6d23825b581b..cc5273dc140c 100644 --- a/dom/media/webaudio/blink/IIRFilter.cpp +++ b/dom/media/webaudio/blink/IIRFilter.cpp @@ -129,4 +129,24 @@ void IIRFilter::getFrequencyResponse(int nFrequencies, const float* frequency, f } } +bool IIRFilter::buffersAreZero() +{ + double* xBuffer = m_xBuffer.Elements(); + double* yBuffer = m_yBuffer.Elements(); + + for (size_t k = 0; k < m_feedforward->Length(); ++k) { + if (xBuffer[(m_bufferIndex - k) & (kBufferLength - 1)] != 0.0) { + return false; + } + } + + for (size_t k = 0; k < m_feedback->Length(); ++k) { + if (fabs(yBuffer[(m_bufferIndex - k) & (kBufferLength - 1)]) >= FLT_MIN) { + return false; + } + } + + return true; +} + } // namespace blink diff --git a/dom/media/webaudio/blink/IIRFilter.h b/dom/media/webaudio/blink/IIRFilter.h index a3fdf55a5316..5656d959a473 100644 --- a/dom/media/webaudio/blink/IIRFilter.h +++ b/dom/media/webaudio/blink/IIRFilter.h @@ -26,6 +26,8 @@ public: float* magResponse, float* phaseResponse); + bool buffersAreZero(); + private: // Filter memory //