Title: [265517] trunk
Revision
265517
Author
cdu...@apple.com
Date
2020-08-11 14:18:27 -0700 (Tue, 11 Aug 2020)

Log Message

Fix BiquadFilterNode's lowpass filter
https://bugs.webkit.org/show_bug.cgi?id=215381

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Rebaseline WPT test now that more checks are passing.

* web-platform-tests/webaudio/the-audio-api/the-biquadfilternode-interface/biquad-lowpass-expected.txt:

Source/WebCore:

Fix BiquadFilterNode's lowpass filter as it was causing us to fail a WPT test:
- https://www.w3.org/TR/webaudio/#dom-biquadfiltertype-lowpass

No new tests, rebaselined existing test.

* Modules/webaudio/BiquadProcessor.cpp:
(WebCore::BiquadProcessor::BiquadProcessor):
* platform/audio/Biquad.cpp:
(WebCore::Biquad::setLowpassParams):

LayoutTests:

* webaudio/biquad-lowpass.html:
Update test to work in other browsers (which do not support prefixed API).

* webaudio/resources/biquad-testing.js:
(createLowpassFilter):
Update test to reflect behavior change. Note that this test was failing in both
Chrome and Firefox before I updated the test. Now that I updated the test to
match the new behavior we implemented, it passes in both Chrome and Firefox.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (265516 => 265517)


--- trunk/LayoutTests/ChangeLog	2020-08-11 21:11:11 UTC (rev 265516)
+++ trunk/LayoutTests/ChangeLog	2020-08-11 21:18:27 UTC (rev 265517)
@@ -1,3 +1,19 @@
+2020-08-11  Chris Dumez  <cdu...@apple.com>
+
+        Fix BiquadFilterNode's lowpass filter
+        https://bugs.webkit.org/show_bug.cgi?id=215381
+
+        Reviewed by Darin Adler.
+
+        * webaudio/biquad-lowpass.html:
+        Update test to work in other browsers (which do not support prefixed API).
+
+        * webaudio/resources/biquad-testing.js:
+        (createLowpassFilter):
+        Update test to reflect behavior change. Note that this test was failing in both
+        Chrome and Firefox before I updated the test. Now that I updated the test to
+        match the new behavior we implemented, it passes in both Chrome and Firefox.
+
 2020-08-11  Hector Lopez  <hector_i_lo...@apple.com>
 
         [ macOS wk1 ] webaudio/oscillator-sawtooth.html is a flaky failure

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (265516 => 265517)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-08-11 21:11:11 UTC (rev 265516)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-08-11 21:18:27 UTC (rev 265517)
@@ -1,3 +1,14 @@
+2020-08-11  Chris Dumez  <cdu...@apple.com>
+
+        Fix BiquadFilterNode's lowpass filter
+        https://bugs.webkit.org/show_bug.cgi?id=215381
+
+        Reviewed by Darin Adler.
+
+        Rebaseline WPT test now that more checks are passing.
+
+        * web-platform-tests/webaudio/the-audio-api/the-biquadfilternode-interface/biquad-lowpass-expected.txt:
+
 2020-08-11  Sergio Villar Senin  <svil...@igalia.com>
 
         [css-flexbox] Only update the intrinsic height if we don't have override height

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-biquadfilternode-interface/biquad-lowpass-expected.txt (265516 => 265517)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-biquadfilternode-interface/biquad-lowpass-expected.txt	2020-08-11 21:11:11 UTC (rev 265516)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-biquadfilternode-interface/biquad-lowpass-expected.txt	2020-08-11 21:18:27 UTC (rev 265517)
@@ -5,7 +5,7 @@
 PASS > [test] Biquad lowpass filter 
 PASS   Number of filters tested is equal to 5. 
 PASS   Number of non-finite values in the rendered output is equal to 0. 
-FAIL X Max error in Lowpass filter response is not less than or equal to 9.7869e-8. Got 0.035169170780036424. assert_true: expected true got false
-FAIL < [test] 1 out of 3 assertions were failed. assert_true: expected true got false
-FAIL # AUDIT TASK RUNNER FINISHED: 1 out of 1 tasks were failed. assert_true: expected true got false
+PASS   Max error in Lowpass filter response is less than or equal to 9.7869e-8. 
+PASS < [test] All assertions passed. (total 3 assertions) 
+PASS # AUDIT TASK RUNNER FINISHED: 1 tasks ran successfully. 
 

Added: trunk/LayoutTests/webaudio/BiquadFilterNode-limits-expected.txt (0 => 265517)


--- trunk/LayoutTests/webaudio/BiquadFilterNode-limits-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webaudio/BiquadFilterNode-limits-expected.txt	2020-08-11 21:18:27 UTC (rev 265517)
@@ -0,0 +1,21 @@
+Tests the limits of BiquadFilterNode's AudioParam attributes
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS node.frequency.defaultValue is 350
+PASS node.frequency.minValue is 0
+PASS node.frequency.maxValue is 0.5 * context.sampleRate
+PASS node.detune.defaultValue is 0
+PASS node.detune.minValue is -153600
+PASS node.detune.maxValue is 153600
+PASS node.Q.defaultValue is 1
+PASS diff(node.Q.minValue, -FLT_MAX) < 1e31 is true
+PASS diff(node.Q.maxValue, FLT_MAX) < 1e31 is true
+PASS node.gain.defaultValue is 0
+PASS diff(node.gain.minValue, -FLT_MAX) < 1e31 is true
+PASS diff(node.gain.maxValue, 1541) < 1 is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/webaudio/BiquadFilterNode-limits.html (0 => 265517)


--- trunk/LayoutTests/webaudio/BiquadFilterNode-limits.html	                        (rev 0)
+++ trunk/LayoutTests/webaudio/BiquadFilterNode-limits.html	2020-08-11 21:18:27 UTC (rev 265517)
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description("Tests the limits of BiquadFilterNode's AudioParam attributes");
+
+context = new OfflineAudioContext({ sampleRate: 44100, length: 100 });
+node = new BiquadFilterNode(context);
+
+const FLT_MAX = 3.4028235e38;
+
+function diff(a, b)
+{
+    if (a > b)
+        return a - b;
+    return b - a;
+}
+
+shouldBe("node.frequency.defaultValue", "350");
+shouldBe("node.frequency.minValue", "0");
+shouldBe("node.frequency.maxValue", "0.5 * context.sampleRate");
+
+shouldBe("node.detune.defaultValue", "0");
+shouldBe("node.detune.minValue", "-153600");
+shouldBe("node.detune.maxValue", "153600");
+
+shouldBe("node.Q.defaultValue", "1");
+shouldBeTrue("diff(node.Q.minValue, -FLT_MAX) < 1e31");
+shouldBeTrue("diff(node.Q.maxValue, FLT_MAX) < 1e31");
+
+shouldBe("node.gain.defaultValue", "0");
+shouldBeTrue("diff(node.gain.minValue, -FLT_MAX) < 1e31");
+shouldBeTrue("diff(node.gain.maxValue, 1541) < 1");
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/webaudio/biquad-lowpass.html (265516 => 265517)


--- trunk/LayoutTests/webaudio/biquad-lowpass.html	2020-08-11 21:11:11 UTC (rev 265516)
+++ trunk/LayoutTests/webaudio/biquad-lowpass.html	2020-08-11 21:18:27 UTC (rev 265517)
@@ -15,11 +15,13 @@
 <script>
 description("Tests Biquad lowpass filter.");
 
+window.OfflineAudioContext = window.OfflineAudioContext || window.webkitOfflineAudioContext;
+
 function runTest() {
     window.jsTestIsAsync = true;
         
     // Create offline audio context.
-    var context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
+    var context = new OfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
 
     // Dummy filter to get filter type constant
     var f = context.createBiquadFilter();

Modified: trunk/LayoutTests/webaudio/resources/biquad-testing.js (265516 => 265517)


--- trunk/LayoutTests/webaudio/resources/biquad-testing.js	2020-08-11 21:11:11 UTC (rev 265516)
+++ trunk/LayoutTests/webaudio/resources/biquad-testing.js	2020-08-11 21:18:27 UTC (rev 265517)
@@ -46,28 +46,24 @@
     if (freq == 1) {
         // The formula below works, except for roundoff.  When freq = 1,
         // the filter is just a wire, so hardwire the coefficients.
-        b0 = 1;
-        b1 = 0;
-        b2 = 0;
-        a1 = 0;
-        a2 = 0;
+        return {b0: 1, b1: 0, b2: 0, a1: 0, a2: 0};
     } else {
-        var g = Math.pow(10, q / 20);
-        var d = Math.sqrt((4 - Math.sqrt(16 - 16 / (g * g))) / 2);
+        var resonance = Math.pow(10, q / 20);
         var theta = Math.PI * freq;
-        var sn = d * Math.sin(theta) / 2;
-        var beta = 0.5 * (1 - sn) / (1 + sn);
-        var gamma = (0.5 + beta) * Math.cos(theta);
-        var alpha = 0.25 * (0.5 + beta - gamma);
+        var alpha = Math.sin(theta) / (2 * resonance);
+        var cosw = Math.cos(theta);
+        var beta = (1 - cosw) / 2;
 
-        b0 = 2 * alpha;
-        b1 = 4 * alpha;
-        b2 = 2 * alpha;
-        a1 = 2 * (-gamma);
-        a2 = 2 * beta;
+        b0 = beta;
+        b1 = 2 * beta;
+        b2 = beta;
+
+        a0 = 1 + alpha;
+        a1 = -2 * cosw;
+        a2 = 1 - alpha;
+
+        return normalizeFilterCoefficients(b0, b1, b2, a0, a1, a2);
     }
-
-    return {b0 : b0, b1 : b1, b2 : b2, a1 : a1, a2 : a2};
 }
 
 function createHighpassFilter(freq, q, gain) {

Modified: trunk/Source/WebCore/ChangeLog (265516 => 265517)


--- trunk/Source/WebCore/ChangeLog	2020-08-11 21:11:11 UTC (rev 265516)
+++ trunk/Source/WebCore/ChangeLog	2020-08-11 21:18:27 UTC (rev 265517)
@@ -1,3 +1,20 @@
+2020-08-11  Chris Dumez  <cdu...@apple.com>
+
+        Fix BiquadFilterNode's lowpass filter
+        https://bugs.webkit.org/show_bug.cgi?id=215381
+
+        Reviewed by Darin Adler.
+
+        Fix BiquadFilterNode's lowpass filter as it was causing us to fail a WPT test:
+        - https://www.w3.org/TR/webaudio/#dom-biquadfiltertype-lowpass
+
+        No new tests, rebaselined existing test.
+
+        * Modules/webaudio/BiquadProcessor.cpp:
+        (WebCore::BiquadProcessor::BiquadProcessor):
+        * platform/audio/Biquad.cpp:
+        (WebCore::Biquad::setLowpassParams):
+
 2020-08-11  Darin Adler  <da...@apple.com>
 
         LayoutTest accessibility/mac/select-element-selection-with-optgroups.html is a flaky failure

Modified: trunk/Source/WebCore/Modules/webaudio/BiquadProcessor.cpp (265516 => 265517)


--- trunk/Source/WebCore/Modules/webaudio/BiquadProcessor.cpp	2020-08-11 21:11:11 UTC (rev 265516)
+++ trunk/Source/WebCore/Modules/webaudio/BiquadProcessor.cpp	2020-08-11 21:18:27 UTC (rev 265517)
@@ -35,10 +35,10 @@
 BiquadProcessor::BiquadProcessor(BaseAudioContext& context, float sampleRate, size_t numberOfChannels, bool autoInitialize)
     : AudioDSPKernelProcessor(sampleRate, numberOfChannels)
     , m_type(BiquadFilterType::Lowpass)
-    , m_parameter1(AudioParam::create(context, "frequency", 350.0, 10.0, 0.5 * sampleRate))
-    , m_parameter2(AudioParam::create(context, "Q", 1, 0.0001, 1000.0))
-    , m_parameter3(AudioParam::create(context, "gain", 0.0, -40, 40))
-    , m_parameter4(AudioParam::create(context, "detune", 0.0, -4800, 4800))
+    , m_parameter1(AudioParam::create(context, "frequency", 350.0, 0.0, 0.5 * sampleRate))
+    , m_parameter2(AudioParam::create(context, "Q", 1, -FLT_MAX, FLT_MAX))
+    , m_parameter3(AudioParam::create(context, "gain", 0.0, -FLT_MAX, 1541))
+    , m_parameter4(AudioParam::create(context, "detune", 0.0, -153600, 153600))
     , m_filterCoefficientsDirty(true)
     , m_hasSampleAccurateValues(false)
 {

Modified: trunk/Source/WebCore/platform/audio/Biquad.cpp (265516 => 265517)


--- trunk/Source/WebCore/platform/audio/Biquad.cpp	2020-08-11 21:11:11 UTC (rev 265516)
+++ trunk/Source/WebCore/platform/audio/Biquad.cpp	2020-08-11 21:18:27 UTC (rev 265517)
@@ -202,22 +202,22 @@
     } else if (cutoff > 0) {
         // Compute biquad coefficients for lowpass filter
         resonance = std::max(0.0, resonance); // can't go negative
-        double g = pow(10.0, 0.05 * resonance);
-        double d = sqrt((4 - sqrt(16 - 16 / (g * g))) / 2);
+        resonance = pow(10.0, 0.05 * resonance);
 
         double theta = piDouble * cutoff;
-        double sn = 0.5 * d * sin(theta);
-        double beta = 0.5 * (1 - sn) / (1 + sn);
-        double gamma = (0.5 + beta) * cos(theta);
-        double alpha = 0.25 * (0.5 + beta - gamma);
+        double alpha = sin(theta) / (2 * resonance);
+        double cosw = cos(theta);
+        double beta = (1 - cosw) / 2;
 
-        double b0 = 2 * alpha;
-        double b1 = 2 * 2 * alpha;
-        double b2 = 2 * alpha;
-        double a1 = 2 * -gamma;
-        double a2 = 2 * beta;
+        double b0 = beta;
+        double b1 = 2 * beta;
+        double b2 = beta;
 
-        setNormalizedCoefficients(b0, b1, b2, 1, a1, a2);
+        double a0 = 1 + alpha;
+        double a1 = -2 * cosw;
+        double a2 = 1 - alpha;
+
+        setNormalizedCoefficients(b0, b1, b2, a0, a1, a2);
     } else {
         // When cutoff is zero, nothing gets through the filter, so set
         // coefficients up correctly.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to