Bug 1265408 - Add buffersAreZero to IIRFilter; r=karlt
☠☠ backed out by 9870ee9198c8 ☠ ☠
authorDan Minor <dminor@mozilla.com>
Tue, 31 May 2016 09:28:06 -0400
changeset 325782 9ab327850c5fc9e21b41a29d091ba35ee69e454e
parent 325781 388a95b0520288b8377092a8e21dd1eebdf3a4e0
child 325783 784521a9cc94ad399d1405ada007f06d255c6c29
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1265408
milestone49.0a1
Bug 1265408 - Add buffersAreZero to IIRFilter; r=karlt MozReview-Commit-ID: CM5x62GMXcj
dom/media/webaudio/blink/IIRFilter.cpp
dom/media/webaudio/blink/IIRFilter.h
--- a/dom/media/webaudio/blink/IIRFilter.cpp
+++ b/dom/media/webaudio/blink/IIRFilter.cpp
@@ -124,9 +124,29 @@ void IIRFilter::getFrequencyResponse(int
         std::complex<double> numerator = evaluatePolynomial(m_feedforward->Elements(), zRecip, m_feedforward->Length() - 1);
         std::complex<double> denominator = evaluatePolynomial(m_feedback->Elements(), zRecip, m_feedback->Length() - 1);
         std::complex<double> response = numerator / denominator;
         magResponse[k] = static_cast<float>(abs(response));
         phaseResponse[k] = static_cast<float>(atan2(imag(response), real(response)));
     }
 }
 
+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
--- a/dom/media/webaudio/blink/IIRFilter.h
+++ b/dom/media/webaudio/blink/IIRFilter.h
@@ -21,16 +21,18 @@ public:
 
     void reset();
 
     void getFrequencyResponse(int nFrequencies,
         const float* frequency,
         float* magResponse,
         float* phaseResponse);
 
+    bool buffersAreZero();
+
 private:
     // Filter memory
     //
     // For simplicity, we assume |m_xBuffer| and |m_yBuffer| have the same length, and the length is
     // a power of two.  Since the number of coefficients has a fixed upper length, the size of
     // xBuffer and yBuffer is fixed. |m_xBuffer| holds the old input values and |m_yBuffer| holds
     // the old output values needed to compute the new output value.
     //