Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix BiquadFilterNode's lowpass & highpass filters
https://bugs.webkit.org/show_bug.cgi?id=216852

Reviewed by Eric Carlson.

Source/WebCore:

Fix BiquadFilterNode's lowpass & highpass filters. They incorrectly clamp the
resonance to make it positive.

Formulas for the filters are specified here:
- https://www.w3.org/TR/webaudio/#filters-characteristics

No new tests, rebaselined existing tests.

* platform/audio/Biquad.cpp:
(WebCore::pow10):
(WebCore::Biquad::setLowpassParams):
(WebCore::Biquad::setHighpassParams):

LayoutTests:

Rebaseline tests that are now passing.

* webaudio/BiquadFilter/tail-time-highpass-expected.txt:
* webaudio/BiquadFilter/tail-time-lowpass-expected.txt:

Canonical link: https://commits.webkit.org/229641@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@267444 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Sep 22, 2020
1 parent 4b3d294 commit 3b52e4c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 30 deletions.
12 changes: 12 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
2020-09-22 Chris Dumez <cdumez@apple.com>

Fix BiquadFilterNode's lowpass & highpass filters
https://bugs.webkit.org/show_bug.cgi?id=216852

Reviewed by Eric Carlson.

Rebaseline tests that are now passing.

* webaudio/BiquadFilter/tail-time-highpass-expected.txt:
* webaudio/BiquadFilter/tail-time-lowpass-expected.txt:

2020-09-22 Chris Dumez <cdumez@apple.com>

Merge AudioBufferSourceNode loop fixes from Blink
Expand Down
Expand Up @@ -27,22 +27,22 @@ PASS HPF complex roots: Biquad({"type":"highpass","Q":40,"frequency":4096}): o
PASS HPF complex roots: Biquad({"type":"highpass","Q":40,"frequency":4096}): output[2432:] equals [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
PASS < [hpf-complex-roots] All assertions passed. (total 19 assertions)
PASS > [hpf-real-distinct-roots] real distinct roots
FAIL X HPF real distinct roots: Biquad({"type":"highpass","Q":-50,"frequency":2048}): Actual Tail Frame 236 is not greater than or equal to 408. Got 236. assert_true: expected true got false
PASS HPF real distinct roots: Biquad({"type":"highpass","Q":-50,"frequency":2048}): Actual Tail Frame 2560 is greater than or equal to 408.
PASS HPF real distinct roots: Biquad({"type":"highpass","Q":-50,"frequency":2048}): output[0:127] is not constantly 0 (contains 128 different values).
PASS HPF real distinct roots: Biquad({"type":"highpass","Q":-50,"frequency":2048}): output[128:255] is not constantly 0 (contains 107 different values).
FAIL X HPF real distinct roots: Biquad({"type":"highpass","Q":-50,"frequency":2048}): output[256:383] should have contain at least one value different from 0. assert_true: expected true got false
FAIL X HPF real distinct roots: Biquad({"type":"highpass","Q":-50,"frequency":2048}): output[384:511] should have contain at least one value different from 0. assert_true: expected true got false
PASS HPF real distinct roots: Biquad({"type":"highpass","Q":-50,"frequency":2048}): output[128:255] is not constantly 0 (contains 128 different values).
PASS HPF real distinct roots: Biquad({"type":"highpass","Q":-50,"frequency":2048}): output[256:383] is not constantly 0 (contains 128 different values).
PASS HPF real distinct roots: Biquad({"type":"highpass","Q":-50,"frequency":2048}): output[384:511] is not constantly 0 (contains 128 different values).
PASS HPF real distinct roots: Biquad({"type":"highpass","Q":-50,"frequency":2048}): output[768:] equals [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...] with an element-wise tolerance of {"absoluteThreshold":0.000030517578125,"relativeThreshold":0}.
FAIL < [hpf-real-distinct-roots] 3 out of 6 assertions were failed. assert_true: expected true got false
PASS < [hpf-real-distinct-roots] All assertions passed. (total 6 assertions)
PASS > [hpf-repeated-root] repeated real root
PASS HPF repeated roots (approximately): Biquad({"type":"highpass","Q":-6.020599913279624,"frequency":4096}): Actual Tail Frame 160 is greater than or equal to 3.
PASS HPF repeated roots (approximately): Biquad({"type":"highpass","Q":-6.020599913279624,"frequency":4096}): output[0:127] is not constantly 0 (contains 128 different values).
PASS HPF repeated roots (approximately): Biquad({"type":"highpass","Q":-6.020599913279624,"frequency":4096}): Actual Tail Frame 11 is greater than or equal to 3.
PASS HPF repeated roots (approximately): Biquad({"type":"highpass","Q":-6.020599913279624,"frequency":4096}): output[0:127] is not constantly 0 (contains 11 different values).
PASS HPF repeated roots (approximately): Biquad({"type":"highpass","Q":-6.020599913279624,"frequency":4096}): output[384:] equals [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
PASS < [hpf-repeated-root] All assertions passed. (total 3 assertions)
PASS > [hpf-real-roots-2] complex roots
PASS HPF repeated roots 2: Biquad({"type":"highpass","Q":-100,"frequency":4096}): Actual Tail Frame 160 is greater than or equal to 0.
PASS HPF repeated roots 2: Biquad({"type":"highpass","Q":-100,"frequency":4096}): Actual Tail Frame 256 is greater than or equal to 0.
PASS HPF repeated roots 2: Biquad({"type":"highpass","Q":-100,"frequency":4096}): output[0:127] is not constantly 0 (contains 128 different values).
PASS HPF repeated roots 2: Biquad({"type":"highpass","Q":-100,"frequency":4096}): output[384:] equals [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
PASS < [hpf-real-roots-2] All assertions passed. (total 3 assertions)
FAIL # AUDIT TASK RUNNER FINISHED: 1 out of 4 tasks were failed. assert_true: expected true got false
PASS # AUDIT TASK RUNNER FINISHED: 4 tasks ran successfully.

38 changes: 19 additions & 19 deletions LayoutTests/webaudio/BiquadFilter/tail-time-lowpass-expected.txt
Expand Up @@ -29,30 +29,30 @@ PASS LPF complex roots: Biquad({"type":"lowpass","Q":40,"frequency":4096}): ou
PASS LPF complex roots: Biquad({"type":"lowpass","Q":40,"frequency":4096}): output[2432:] equals [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
PASS < [lpf-complex-roots] All assertions passed. (total 19 assertions)
PASS > [lpf-real-distinct-roots] real distinct roots
FAIL X LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): Actual Tail Frame 236 is not greater than or equal to 1700. Got 236. assert_true: expected true got false
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): Actual Tail Frame 1920 is greater than or equal to 1700.
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[0:127] is not constantly 0 (contains 128 different values).
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[128:255] is not constantly 0 (contains 106 different values).
FAIL X LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[256:383] should have contain at least one value different from 0. assert_true: expected true got false
FAIL X LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[384:511] should have contain at least one value different from 0. assert_true: expected true got false
FAIL X LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[512:639] should have contain at least one value different from 0. assert_true: expected true got false
FAIL X LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[640:767] should have contain at least one value different from 0. assert_true: expected true got false
FAIL X LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[768:895] should have contain at least one value different from 0. assert_true: expected true got false
FAIL X LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[896:1023] should have contain at least one value different from 0. assert_true: expected true got false
FAIL X LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[1024:1151] should have contain at least one value different from 0. assert_true: expected true got false
FAIL X LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[1152:1279] should have contain at least one value different from 0. assert_true: expected true got false
FAIL X LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[1280:1407] should have contain at least one value different from 0. assert_true: expected true got false
FAIL X LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[1408:1535] should have contain at least one value different from 0. assert_true: expected true got false
FAIL X LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[1536:1663] should have contain at least one value different from 0. assert_true: expected true got false
FAIL X LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[1664:1791] should have contain at least one value different from 0. assert_true: expected true got false
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[128:255] is not constantly 0 (contains 128 different values).
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[256:383] is not constantly 0 (contains 128 different values).
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[384:511] is not constantly 0 (contains 128 different values).
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[512:639] is not constantly 0 (contains 128 different values).
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[640:767] is not constantly 0 (contains 128 different values).
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[768:895] is not constantly 0 (contains 128 different values).
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[896:1023] is not constantly 0 (contains 128 different values).
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[1024:1151] is not constantly 0 (contains 128 different values).
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[1152:1279] is not constantly 0 (contains 128 different values).
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[1280:1407] is not constantly 0 (contains 128 different values).
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[1408:1535] is not constantly 0 (contains 128 different values).
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[1536:1663] is not constantly 0 (contains 128 different values).
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[1664:1791] is not constantly 0 (contains 128 different values).
PASS LPF real distinct roots: Biquad({"type":"lowpass","Q":-50,"frequency":2048}): output[2048:] equals [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
FAIL < [lpf-real-distinct-roots] 13 out of 16 assertions were failed. assert_true: expected true got false
PASS < [lpf-real-distinct-roots] All assertions passed. (total 16 assertions)
PASS > [lpf-repeated-root] repeated real root
PASS LPF repeated roots (approximately): Biquad({"type":"lowpass","Q":-6.020599913279624,"frequency":4096}): Actual Tail Frame 160 is greater than or equal to 3.
PASS LPF repeated roots (approximately): Biquad({"type":"lowpass","Q":-6.020599913279624,"frequency":4096}): output[0:127] is not constantly 0 (contains 128 different values).
PASS LPF repeated roots (approximately): Biquad({"type":"lowpass","Q":-6.020599913279624,"frequency":4096}): Actual Tail Frame 11 is greater than or equal to 3.
PASS LPF repeated roots (approximately): Biquad({"type":"lowpass","Q":-6.020599913279624,"frequency":4096}): output[0:127] is not constantly 0 (contains 11 different values).
PASS LPF repeated roots (approximately): Biquad({"type":"lowpass","Q":-6.020599913279624,"frequency":4096}): output[384:] equals [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
PASS < [lpf-repeated-root] All assertions passed. (total 3 assertions)
PASS > [lpf-real-roots-2] complex roots
PASS LPF repeated roots 2: Biquad({"type":"lowpass","Q":-100,"frequency":4096}): Actual Tail Frame 160 is greater than or equal to 0.
PASS LPF repeated roots 2: Biquad({"type":"lowpass","Q":-100,"frequency":4096}): Actual Tail Frame 256 is greater than or equal to 0.
PASS LPF repeated roots 2: Biquad({"type":"lowpass","Q":-100,"frequency":4096}): output[0:127] is not constantly 0 (contains 128 different values).
PASS LPF repeated roots 2: Biquad({"type":"lowpass","Q":-100,"frequency":4096}): output[384:] equals [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
PASS < [lpf-real-roots-2] All assertions passed. (total 3 assertions)
Expand Down Expand Up @@ -774,5 +774,5 @@ PASS LPF repeated roots (approximately): Biquad({"type":"lowpass","Q":500,"fre
PASS LPF repeated roots (approximately): Biquad({"type":"lowpass","Q":500,"frequency":100}): output[640:767] is not constantly 0 (contains 110 different values).
PASS LPF repeated roots (approximately): Biquad({"type":"lowpass","Q":500,"frequency":100}): output[1024:] equals [] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}.
PASS < [ginormous tail] All assertions passed. (total 8 assertions)
FAIL # AUDIT TASK RUNNER FINISHED: 1 out of 6 tasks were failed. assert_true: expected true got false
PASS # AUDIT TASK RUNNER FINISHED: 6 tasks ran successfully.

20 changes: 20 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,23 @@
2020-09-22 Chris Dumez <cdumez@apple.com>

Fix BiquadFilterNode's lowpass & highpass filters
https://bugs.webkit.org/show_bug.cgi?id=216852

Reviewed by Eric Carlson.

Fix BiquadFilterNode's lowpass & highpass filters. They incorrectly clamp the
resonance to make it positive.

Formulas for the filters are specified here:
- https://www.w3.org/TR/webaudio/#filters-characteristics

No new tests, rebaselined existing tests.

* platform/audio/Biquad.cpp:
(WebCore::pow10):
(WebCore::Biquad::setLowpassParams):
(WebCore::Biquad::setHighpassParams):

2020-09-22 Chris Dumez <cdumez@apple.com>

Merge AudioBufferSourceNode loop fixes from Blink
Expand Down
2 changes: 0 additions & 2 deletions Source/WebCore/platform/audio/Biquad.cpp
Expand Up @@ -271,7 +271,6 @@ void Biquad::setLowpassParams(size_t index, double cutoff, double resonance)
setNormalizedCoefficients(index, 1, 0, 0, 1, 0, 0);
} else if (cutoff > 0) {
// Compute biquad coefficients for lowpass filter
resonance = std::max(0.0, resonance); // can't go negative
resonance = pow(10.0, 0.05 * resonance);

double theta = piDouble * cutoff;
Expand Down Expand Up @@ -305,7 +304,6 @@ void Biquad::setHighpassParams(size_t index, double cutoff, double resonance)
setNormalizedCoefficients(index, 0, 0, 0, 1, 0, 0);
} else if (cutoff > 0) {
// Compute biquad coefficients for highpass filter
resonance = std::max(0.0, resonance); // can't go negative
resonance = pow(10.0, 0.05 * resonance);

double theta = piDouble * cutoff;
Expand Down

0 comments on commit 3b52e4c

Please sign in to comment.