Title: [267453] trunk
Revision
267453
Author
[email protected]
Date
2020-09-22 18:49:31 -0700 (Tue, 22 Sep 2020)

Log Message

Slightly improve AudioBufferSourceNode resampling
https://bugs.webkit.org/show_bug.cgi?id=216859

Reviewed by Eric Carlson.

LayoutTests/imported/w3c:

Rebaseline WPT tests that are now passing.

* web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/buffer-resampling-expected.txt:
* web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/sub-sample-buffer-stitching-expected.txt:

Source/WebCore:

Slightly improve AudioBufferSourceNode resampling. Use simple linear extrapolation
to resample the data when we reach the end of the buffer. Previously, the last
sample would just be repeated enough times.

This is a merge of the following Blink change by Raymond Toy:
- https://chromium-review.googlesource.com/c/chromium/src/+/1211910/

No new tests, rebaselined existing tests.

* Modules/webaudio/AudioBufferSourceNode.cpp:
(WebCore::AudioBufferSourceNode::renderFromBuffer):

LayoutTests:

* webaudio/AudioBufferSource/audiobuffersource-detune-modulation-expected.txt:
* webaudio/AudioBufferSource/audiobuffersource-playbackrate-modulation-expected.txt:
* webaudio/gain-expected.wav:
Rebaseline tests that have slightly different output.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (267452 => 267453)


--- trunk/LayoutTests/ChangeLog	2020-09-23 00:44:18 UTC (rev 267452)
+++ trunk/LayoutTests/ChangeLog	2020-09-23 01:49:31 UTC (rev 267453)
@@ -1,5 +1,17 @@
 2020-09-22  Chris Dumez  <[email protected]>
 
+        Slightly improve AudioBufferSourceNode resampling
+        https://bugs.webkit.org/show_bug.cgi?id=216859
+
+        Reviewed by Eric Carlson.
+
+        * webaudio/AudioBufferSource/audiobuffersource-detune-modulation-expected.txt:
+        * webaudio/AudioBufferSource/audiobuffersource-playbackrate-modulation-expected.txt:
+        * webaudio/gain-expected.wav:
+        Rebaseline tests that have slightly different output.
+
+2020-09-22  Chris Dumez  <[email protected]>
+
         Fix BiquadFilterNode's lowpass & highpass filters
         https://bugs.webkit.org/show_bug.cgi?id=216852
 

Modified: trunk/LayoutTests/TestExpectations (267452 => 267453)


--- trunk/LayoutTests/TestExpectations	2020-09-23 00:44:18 UTC (rev 267452)
+++ trunk/LayoutTests/TestExpectations	2020-09-23 01:49:31 UTC (rev 267453)
@@ -326,9 +326,10 @@
 # Webaudio tests that are flaky.
 imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/k-rate-stereo-panner.html [ Pass Failure ]
 
+# This test is passing but the printed SNR value differs from machine to machine.
+imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/sub-sample-buffer-stitching.html [ Pass Failure ]
+
 # Values in FAIL lines differ from machine to machine, we should be able to unskip them once they pass.
-imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/buffer-resampling.html [ Pass Failure ]
-imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/sub-sample-buffer-stitching.html [ Pass Failure ]
 webaudio/AudioBufferSource/audiobuffersource-detune-modulation.html [ Pass Failure ]
 webaudio/AudioBufferSource/audiobuffersource-playbackrate-modulation.html [ Pass Failure ]
 

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (267452 => 267453)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-09-23 00:44:18 UTC (rev 267452)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-09-23 01:49:31 UTC (rev 267453)
@@ -1,3 +1,15 @@
+2020-09-22  Chris Dumez  <[email protected]>
+
+        Slightly improve AudioBufferSourceNode resampling
+        https://bugs.webkit.org/show_bug.cgi?id=216859
+
+        Reviewed by Eric Carlson.
+
+        Rebaseline WPT tests that are now passing.
+
+        * web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/buffer-resampling-expected.txt:
+        * web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/sub-sample-buffer-stitching-expected.txt:
+
 2020-09-22  Sam Sneddon  <[email protected]>
 
         REGRESSION(r267354): Only import resource module on Darwin

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/buffer-resampling-expected.txt (267452 => 267453)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/buffer-resampling-expected.txt	2020-09-23 00:44:18 UTC (rev 267452)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/buffer-resampling-expected.txt	2020-09-23 01:49:31 UTC (rev 267453)
@@ -3,16 +3,8 @@
 PASS Executing "interpolate" 
 PASS Audit report 
 PASS > [interpolate] Interpolation of AudioBuffers to context sample rate 
-FAIL X Interpolated sine wave does not equal [0,0.057564035058021545,0.1149371787905693,0.17192906141281128,0.22835084795951843,0.2840152382850647,0.3387378752231598,0.39233696460723877,0.4446350038051605,0.4954586327075958,0.5446387529373169,0.5920131206512451,0.6374238133430481,0.6807207465171814,0.7217600345611572,0.7604058980941772...] with an element-wise tolerance of {"absoluteThreshold":0.090348,"relativeThreshold":0}.
-	Index	Actual			Expected		AbsError		RelError		Test threshold
-	[176]	-5.6208336353302002e-1	-6.5342026948928833e-1	9.1336905956268311e-2	1.3978278639512823e-1	9.0347999999999998e-2
-	[177]	-5.6208336353302002e-1	-6.9591242074966431e-1	1.3382905721664429e-1	1.9230732664963551e-1	9.0347999999999998e-2
-	[178]	-5.6208336353302002e-1	-7.3609656095504761e-1	1.7401319742202759e-1	2.3639995980453213e-1	9.0347999999999998e-2
-	[179]	-5.6208336353302002e-1	-7.7383983135223389e-1	2.1175646781921387e-1	2.7364379454231952e-1	9.0347999999999998e-2
-	Max AbsError of 2.1175646781921387e-1 at index of 179.
-	Max RelError of 2.7364379454231952e-1 at index of 179.
- assert_true: expected true got false
-FAIL X SNR (32.76 dB) is not greater than or equal to 37.17. Got 32.76242434165858. assert_true: expected true got false
-FAIL < [interpolate] 2 out of 2 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   Interpolated sine wave equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0.090348,"relativeThreshold":0}. 
+PASS   SNR (37.18 dB) is greater than or equal to 37.17. 
+PASS < [interpolate] All assertions passed. (total 2 assertions) 
+PASS # AUDIT TASK RUNNER FINISHED: 1 tasks ran successfully. 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/sub-sample-buffer-stitching-expected.txt (267452 => 267453)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/sub-sample-buffer-stitching-expected.txt	2020-09-23 00:44:18 UTC (rev 267452)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audiobuffersourcenode-interface/sub-sample-buffer-stitching-expected.txt	2020-09-23 01:49:31 UTC (rev 267453)
@@ -10,20 +10,8 @@
 PASS < [buffer-stitching-1] All assertions passed. (total 3 assertions) 
 PASS > [buffer-stitching-2] Subsample buffer stitching, different rates 
 PASS   Test 2: context.sampleRate is equal to 44100. 
-FAIL X Stitched sine-wave buffers at sample rate 43800 does not equal [0,0.06264830380678177,0.12505052983760834,0.1869613528251648,0.2481377273797989,0.308339387178421,0.36732959747314453,0.4248766303062439,0.48075437545776367,0.53474360704422,0.5866317749023438,0.6362154483795166,0.6832994818687439,0.7276992797851562,0.7692402005195618,0.8077590465545654...] with an element-wise tolerance of {"absoluteThreshold":0.0038986,"relativeThreshold":0}.
-	Index	Actual			Expected		AbsError		RelError		Test threshold
-	[30]	9.6648049354553223e-1	9.5236855745315552e-1	1.4111936092376709e-2	1.4817725744868301e-2	3.8985999999999999e-3
-	[60]	-5.5004155635833740e-1	-5.8084774017333984e-1	3.0806183815002441e-2	5.3036590631839402e-2	3.8985999999999999e-3
-	[90]	-6.1754375696182251e-1	-5.9811061620712280e-1	1.9433140754699707e-2	3.2490880830595564e-2	3.8985999999999999e-3
-	[151]	2.0081890746951103e-2	-4.1306052356958389e-2	6.1387943103909492e-2	1.4861730812087184e+0	3.8985999999999999e-3
-	[181]	-9.5454013347625732e-1	-9.3895959854125977e-1	1.5580534934997559e-2	1.6593402910202976e-2	3.8985999999999999e-3
-	...and 1222 more errors.
-	Max AbsError of 6.3063371824682690e-2 at index of 6615.
-	[6615]	-6.3076853752136230e-2	-1.3481927453540266e-5	6.3063371824682690e-2	4.6776228430247684e+3	3.8985999999999999e-3
-	Max RelError of 4.6776228430247684e+3 at index of 6615.
-	[6615]	-6.3076853752136230e-2	-1.3481927453540266e-5	6.3063371824682690e-2	4.6776228430247684e+3	3.8985999999999999e-3
- assert_true: expected true got false
-FAIL X SNR (43.58852186686384 dB) is not greater than or equal to 65.737. Got 43.58852186686384. assert_true: expected true got false
-FAIL < [buffer-stitching-2] 2 out of 3 assertions were failed. assert_true: expected true got false
-FAIL # AUDIT TASK RUNNER FINISHED: 1 out of 2 tasks were failed. assert_true: expected true got false
+PASS   Stitched sine-wave buffers at sample rate 43800 equals [expected array] with an element-wise tolerance of {"absoluteThreshold":0.0038986,"relativeThreshold":0}. 
+PASS   SNR (65.73793928980352 dB) is greater than or equal to 65.737. 
+PASS < [buffer-stitching-2] All assertions passed. (total 3 assertions) 
+PASS # AUDIT TASK RUNNER FINISHED: 2 tasks ran successfully. 
 

Modified: trunk/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-detune-modulation-expected.txt (267452 => 267453)


--- trunk/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-detune-modulation-expected.txt	2020-09-23 00:44:18 UTC (rev 267452)
+++ trunk/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-detune-modulation-expected.txt	2020-09-23 01:49:31 UTC (rev 267453)
@@ -6,7 +6,7 @@
 PASS > [load-reference]  
 PASS < [load-reference] All assertions passed. (total 0 assertions) 
 PASS > [generate-verify]  
-FAIL X SNR is not greater than or equal to 93.32. Got 90.27890412800858. assert_true: expected true got false
+FAIL X SNR is not greater than or equal to 93.32. Got 90.27890412768754. assert_true: expected true got false
 PASS   : Maximum difference (in ulp units (16-bits)) is less than or equal to 1.0352. 
 PASS   : Number of differences between results is less than or equal to 0. 
 FAIL < [generate-verify] 1 out of 3 assertions were failed. assert_true: expected true got false

Modified: trunk/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-playbackrate-modulation-expected.txt (267452 => 267453)


--- trunk/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-playbackrate-modulation-expected.txt	2020-09-23 00:44:18 UTC (rev 267452)
+++ trunk/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-playbackrate-modulation-expected.txt	2020-09-23 01:49:31 UTC (rev 267453)
@@ -7,7 +7,7 @@
 PASS   Loaded reference file is true. 
 PASS < [load-reference] All assertions passed. (total 1 assertions) 
 PASS > [generate-verify]  
-FAIL X SNR is not greater than or equal to 93.274. Got 90.24757942295886. assert_true: expected true got false
+FAIL X SNR is not greater than or equal to 93.274. Got 90.24757942510593. assert_true: expected true got false
 PASS   Verify: Maximum difference (in ulp units (16-bits)) is less than or equal to 1.0519. 
 PASS   Verify: Number of differences between results is less than or equal to 0. 
 FAIL < [generate-verify] 1 out of 3 assertions were failed. assert_true: expected true got false

Modified: trunk/LayoutTests/webaudio/gain-expected.wav


(Binary files differ)

Modified: trunk/Source/WebCore/ChangeLog (267452 => 267453)


--- trunk/Source/WebCore/ChangeLog	2020-09-23 00:44:18 UTC (rev 267452)
+++ trunk/Source/WebCore/ChangeLog	2020-09-23 01:49:31 UTC (rev 267453)
@@ -1,3 +1,22 @@
+2020-09-22  Chris Dumez  <[email protected]>
+
+        Slightly improve AudioBufferSourceNode resampling
+        https://bugs.webkit.org/show_bug.cgi?id=216859
+
+        Reviewed by Eric Carlson.
+
+        Slightly improve AudioBufferSourceNode resampling. Use simple linear extrapolation
+        to resample the data when we reach the end of the buffer. Previously, the last
+        sample would just be repeated enough times.
+
+        This is a merge of the following Blink change by Raymond Toy:
+        - https://chromium-review.googlesource.com/c/chromium/src/+/1211910/
+
+        No new tests, rebaselined existing tests.
+
+        * Modules/webaudio/AudioBufferSourceNode.cpp:
+        (WebCore::AudioBufferSourceNode::renderFromBuffer):
+
 2020-09-22  Sam Weinig  <[email protected]>
 
         [WebIDL] Switch to new file name convention for partial interfaces

Modified: trunk/Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp (267452 => 267453)


--- trunk/Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp	2020-09-23 00:44:18 UTC (rev 267452)
+++ trunk/Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp	2020-09-23 01:49:31 UTC (rev 267453)
@@ -52,6 +52,19 @@
 // to minimize linear interpolation aliasing.
 const double MaxRate = 1024;
 
+static float computeSampleUsingLinearInterpolation(const float* source, unsigned readIndex, unsigned readIndex2, float interpolationFactor)
+{
+    if (readIndex == readIndex2 && readIndex >= 1) {
+        // We're at the end of the buffer, so just linearly extrapolate from the last two samples.
+        float sample1 = source[readIndex - 1];
+        float sample2 = source[readIndex];
+        return sample2 + (sample2 - sample1) * interpolationFactor;
+    }
+    float sample1 = source[readIndex];
+    float sample2 = source[readIndex2];
+    return sample1 + interpolationFactor * (sample2 - sample1);
+}
+
 ExceptionOr<Ref<AudioBufferSourceNode>> AudioBufferSourceNode::create(BaseAudioContext& context, AudioBufferSourceOptions&& options)
 {
     if (context.isStopped())
@@ -339,11 +352,11 @@
 
         while (framesToProcess--) {
             unsigned readIndex = static_cast<unsigned>(floorf(virtualReadIndex));
-            double interpolationFactor = virtualReadIndex - readIndex;
+            float interpolationFactor = virtualReadIndex - readIndex;
 
             unsigned readIndex2 = readIndex + 1;
             if (readIndex2 >= maxFrame)
-                readIndex2 = loop() ? minFrame : maxFrame - 1;
+                readIndex2 = loop() ? minFrame : readIndex;
 
             // Linear interpolation.
             for (unsigned i = 0; i < numberOfChannels; ++i) {
@@ -350,11 +363,7 @@
                 float* destination = destinationChannels[i];
                 const float* source = sourceChannels[i];
 
-                double sample1 = source[readIndex];
-                double sample2 = source[readIndex2];
-                double sample = (1.0 - interpolationFactor) * sample1 + interpolationFactor * sample2;
-
-                destination[writeIndex] = narrowPrecisionToFloat(sample);
+                destination[writeIndex] = computeSampleUsingLinearInterpolation(source, readIndex, readIndex2, interpolationFactor);
             }
 
             writeIndex++;
@@ -371,7 +380,7 @@
     } else {
         while (framesToProcess--) {
             unsigned readIndex = static_cast<unsigned>(virtualReadIndex);
-            double interpolationFactor = virtualReadIndex - readIndex;
+            float interpolationFactor = virtualReadIndex - readIndex;
 
             // For linear interpolation we need the next sample-frame too.
             unsigned readIndex2 = readIndex + 1;
@@ -393,11 +402,7 @@
                 float* destination = destinationChannels[i];
                 const float* source = sourceChannels[i];
 
-                double sample1 = source[readIndex];
-                double sample2 = source[readIndex2];
-                double sample = (1.0 - interpolationFactor) * sample1 + interpolationFactor * sample2;
-
-                destination[writeIndex] = narrowPrecisionToFloat(sample);
+                destination[writeIndex] = computeSampleUsingLinearInterpolation(source, readIndex, readIndex2, interpolationFactor);
             }
             writeIndex++;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to