Title: [266570] trunk
Revision
266570
Author
cdu...@apple.com
Date
2020-09-03 19:00:00 -0700 (Thu, 03 Sep 2020)

Log Message

Tests using OscillatorNode are flaky
https://bugs.webkit.org/show_bug.cgi?id=216152

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Rebaseline WPT tests.

* web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/k-rate-oscillator-connections-expected.txt:
* web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/detune-limiting-expected.txt:
* web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/osc-basic-waveform-expected.txt:

Source/WebCore:

OscillatorNode was caching the different kind of PeriodicWaves in global static
variables. However, the PeriodicWaves are specific to a given sample rate.
As a result, we would sometimes use a cached periodic wave that was using the
wrong sample rate, leading to flaky failures. To address the issue, we now
cache the periodic waves per audio context instead.

No new tests, rebaselined existing tests and unskip them.

* Modules/webaudio/BaseAudioContext.cpp:
(WebCore::BaseAudioContext::periodicWave):
* Modules/webaudio/BaseAudioContext.h:
* Modules/webaudio/OscillatorNode.cpp:
(WebCore::OscillatorNode::setType):
* Modules/webaudio/OscillatorNode.h:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (266569 => 266570)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-09-04 01:54:05 UTC (rev 266569)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-09-04 02:00:00 UTC (rev 266570)
@@ -1,5 +1,18 @@
 2020-09-03  Chris Dumez  <cdu...@apple.com>
 
+        Tests using OscillatorNode are flaky
+        https://bugs.webkit.org/show_bug.cgi?id=216152
+
+        Reviewed by Darin Adler.
+
+        Rebaseline WPT tests.
+
+        * web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/k-rate-oscillator-connections-expected.txt:
+        * web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/detune-limiting-expected.txt:
+        * web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/osc-basic-waveform-expected.txt:
+
+2020-09-03  Chris Dumez  <cdu...@apple.com>
+
         AudioDestinationNode.maxChannelCount always returns 0
         https://bugs.webkit.org/show_bug.cgi?id=216127
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/k-rate-oscillator-connections-expected.txt (266569 => 266570)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/k-rate-oscillator-connections-expected.txt	2020-09-04 01:54:05 UTC (rev 266569)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-audioparam-interface/k-rate-oscillator-connections-expected.txt	2020-09-04 02:00:00 UTC (rev 266570)
@@ -24,7 +24,7 @@
 PASS   Test 2: modDetune.offset.setValueAtTime(0, 0) did not throw an exception. 
 PASS   Test 2: modDetune.offset.linearRampToValueAtTime(2000, 0.078125) did not throw an exception. 
 PASS   Test 2: modDetune.connect(srcTest.detune) did not throw an exception. 
-PASS   k-rate detune with input equals [0,0.3387378752231598,0.6374238729476929,0.8607419729232788,0.9822871685028076,0.9876880645751953,0.8763062953948975,0.6613117456436157,0.3681243062019348,0.03141050040721893,-0.3090170621871948,-0.6129071116447449,-0.8443278074264526,-0.9759165644645691,-0.9921145439147949,-0.8910062313079834...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}. 
+PASS   k-rate detune with input equals [0,0.3311063051223755,0.6248595118522644,0.8481203317642212,0.9757022261619568,0.9932120442390442,0.898674488067627,0.7027547955513,0.4275550842285156,0.10412158071994781,-0.23105812072753906,-0.5401715040206909,-0.7883464097976685,-0.9475855827331543,-0.9999247789382935,-0.9394593238830566...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}. 
 PASS < [Test 2] All assertions passed. (total 8 assertions) 
 PASS > [Test 3] k-rate frequency input with a-rate detune 
 PASS   Test 3: srcRef.frequency.automationRate = 'k-rate' did not throw an exception. 
@@ -38,7 +38,7 @@
 PASS   Test 3: modFreq.offset.setValueAtTime(100, 0) did not throw an exception. 
 PASS   Test 3: modFreq.offset.linearRampToValueAtTime(2000, 0.078125) did not throw an exception. 
 PASS   Test 3: modFreq.connect(srcTest.frequency) did not throw an exception. 
-PASS   k-rate frequency input with a-rate detune equals [0,0.07845915853977203,0.15629452466964722,0.23303230106830597,0.3082095980644226,0.38137686252593994,0.452100932598114,0.5199676156044006,0.5845836400985718,0.6455783843994141,0.7026070952415466,0.7553509473800659,0.8035199642181396,0.8468540906906128,0.8851238489151001,0.9181316494941711...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}. 
+PASS   k-rate frequency input with a-rate detune equals [0,0.0766238272190094,0.15266045928001404,0.22766828536987305,0.3012154698371887,0.37288329005241394,0.4422665238380432,0.5089780688285828,0.5726485848426819,0.6329304575920105,0.6894980669021606,0.7420494556427002,0.7903093695640564,0.8340283632278442,0.8729850649833679,0.9069870710372925...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}. 
 PASS < [Test 3] All assertions passed. (total 12 assertions) 
 PASS > [Test 4] a-rate frequency with k-rate detune input 
 PASS   Test 4: srcRef.frequency.setValueAtTime(100, 0) did not throw an exception. 
@@ -52,7 +52,7 @@
 PASS   Test 4: modDetune.offset.setValueAtTime(0, 0) did not throw an exception. 
 PASS   Test 4: modDetune.offset.linearRampToValueAtTime(-2000, 0.078125) did not throw an exception. 
 PASS   Test 4: modDetune.connect(srcTest.detune) did not throw an exception. 
-PASS   k-rate detune input with a-rate frequency equals [0,0.07845915853977203,0.1587369441986084,0.24024122953414917,0.3222914934158325,0.404119074344635,0.48486924171447754,0.5636047124862671,0.6393131017684937,0.7109143733978271,0.777274489402771,0.8372192978858948,0.8895531892776489,0.9330809116363525,0.966631293296814,0.9890860319137573...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}. 
+PASS   k-rate detune input with a-rate frequency equals [0,0.0766238272190094,0.15504702925682068,0.23471763730049133,0.3150014281272888,0.39518117904663086,0.47445887327194214,0.5519577264785767,0.6267287731170654,0.6977580785751343,0.7639774084091187,0.8242770433425903,0.8775221705436707,0.9225715398788452,0.9583002328872681,0.9836233854293823...] with an element-wise tolerance of {"absoluteThreshold":0,"relativeThreshold":0}. 
 PASS < [Test 4] All assertions passed. (total 12 assertions) 
 PASS > [Test 5] k-rate inputs for frequency and detune 
 PASS   Test 5: srcRef.frequency.automationRate = 'k-rate' did not throw an exception. 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/detune-limiting-expected.txt (266569 => 266570)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/detune-limiting-expected.txt	2020-09-04 01:54:05 UTC (rev 266569)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/detune-limiting-expected.txt	2020-09-04 02:00:00 UTC (rev 266570)
@@ -14,10 +14,10 @@
 PASS   osc[0:4] is not constantly 0 (contains 4 different values). 
 FAIL X osc[5:]: Expected 0 for all values but found 5506 unexpected values: 
 	Index	Actual
-	[0]	0.0006545003270730376
-	[1]	0.0007854003342799842
-	[2]	0.0009163003996945918
-	[3]	0.0010472005233168602
+	[0]	0.0007123813265934587
+	[1]	0.0008548574987798929
+	[2]	0.000997333787381649
+	[3]	0.0011398100759834051
 	...and 5502 more errors. assert_true: expected true got false
 FAIL < [detune automation] 1 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

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/osc-basic-waveform-expected.txt (266569 => 266570)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/osc-basic-waveform-expected.txt	2020-09-04 01:54:05 UTC (rev 266569)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/webaudio/the-audio-api/the-oscillatornode-interface/osc-basic-waveform-expected.txt	2020-09-04 02:00:00 UTC (rev 266570)
@@ -8,69 +8,21 @@
 PASS Executing "Test 5" 
 PASS Audit report 
 PASS > [Test 0] Sine wave: 100 Hz 
-FAIL X Sine: 100 Hz does not equal [0,0.014247103594243526,0.028491314500570297,0.04272974282503128,0.056959498673677444,0.07117769122123718,0.08538143336772919,0.09956784546375275,0.11373404413461685,0.1278771609067917,0.14199431240558624,0.1560826450586319,0.17013929784297943,0.18416140973567963,0.19814614951610565,0.2120906561613083...] with an element-wise tolerance of {"absoluteThreshold":0.0000018045,"relativeThreshold":0}.
-	Index	Actual			Expected		AbsError		RelError		Test threshold
-	[1]	1.3089643791317940e-2	1.4247103594243526e-2	1.1574598029255867e-3	8.1241762247959842e-2	1.8045000000000000e-6
-	[2]	2.6176968589425087e-2	2.8491314500570297e-2	2.3143459111452103e-3	8.1229874848311581e-2	1.8045000000000000e-6
-	[3]	3.9259806275367737e-2	4.2729742825031281e-2	3.4699365496635437e-3	8.1206586331964509e-2	1.8045000000000000e-6
-	[4]	5.2335985004901886e-2	5.6959498673677444e-2	4.6235136687755585e-3	8.1171951587281285e-2	1.8045000000000000e-6
-	[5]	6.5403074026107788e-2	7.1177691221237183e-2	5.7746171951293945e-3	8.1129594063124519e-2	1.8045000000000000e-6
-	...and 250 more errors.
-	Max AbsError of 2.7751174569129944e-1 at index of 250.
-	[250]	-1.3052606582641602e-1	-4.0803781151771545e-1	2.7751174569129944e-1	6.8011281763099773e-1	1.8045000000000000e-6
-	Max RelError of 3.5554003082343762e+1 at index of 221.
-	[221]	2.4615347385406494e-1	-7.1237324737012386e-3	2.5327720632776618e-1	3.5554003082343762e+1	1.8045000000000000e-6
- assert_true: expected true got false
-FAIL X Sine: SNR (db) is not greater than or equal to 118.91. Got 13.507687016951706. assert_true: expected true got false
-FAIL < [Test 0] 2 out of 2 assertions were failed. assert_true: expected true got false
+PASS   Sine: 100 Hz equals [0,0.014247103594243526,0.028491314500570297,0.04272974282503128,0.056959498673677444,0.07117769122123718,0.08538143336772919,0.09956784546375275,0.11373404413461685,0.1278771609067917,0.14199431240558624,0.1560826450586319,0.17013929784297943,0.18416140973567963,0.19814614951610565,0.2120906561613083...] with an element-wise tolerance of {"absoluteThreshold":0.0000018045,"relativeThreshold":0}. 
+PASS   Sine: SNR (db) is greater than or equal to 118.91. 
+PASS < [Test 0] All assertions passed. (total 2 assertions) 
 PASS > [Test 1] Sine wave: -100 Hz 
-FAIL X Sine: -100 Hz does not equal [0,-0.014247103594243526,-0.028491314500570297,-0.04272974282503128,-0.056959498673677444,-0.07117769122123718,-0.08538143336772919,-0.09956784546375275,-0.11373404413461685,-0.1278771609067917,-0.14199431240558624,-0.1560826450586319,-0.17013929784297943,-0.18416140973567963,-0.19814614951610565,-0.2120906561613083...] with an element-wise tolerance of {"absoluteThreshold":4.7684e-7,"relativeThreshold":0}.
-	Index	Actual			Expected		AbsError		RelError		Test threshold
-	[1]	-1.3089818879961967e-2	-1.4247103594243526e-2	1.1572847142815590e-3	8.1229472827666835e-2	4.7683999999999997e-7
-	[2]	-2.6176968589425087e-2	-2.8491314500570297e-2	2.3143459111452103e-3	8.1229874848311581e-2	4.7683999999999997e-7
-	[3]	-3.9259962737560272e-2	-4.2729742825031281e-2	3.4697800874710083e-3	8.1202924662546652e-2	4.7683999999999997e-7
-	[4]	-5.2335936576128006e-2	-5.6959498673677444e-2	4.6235620975494385e-3	8.1172801819025031e-2	4.7683999999999997e-7
-	[5]	-6.5403178334236145e-2	-7.1177691221237183e-2	5.7745128870010376e-3	8.1128128602155403e-2	4.7683999999999997e-7
-	...and 250 more errors.
-	Max AbsError of 2.7751179039478302e-1 at index of 250.
-	[250]	1.3052602112293243e-1	4.0803781151771545e-1	2.7751179039478302e-1	6.8011292718820626e-1	4.7683999999999997e-7
-	Max RelError of 3.5554019816449092e+1 at index of 221.
-	[221]	-2.4615359306335449e-1	7.1237324737012386e-3	2.5327732553705573e-1	3.5554019816449092e+1	4.7683999999999997e-7
- assert_true: expected true got false
-FAIL X Sine: SNR (db) is not greater than or equal to 130.95. Got 13.507686089555154. assert_true: expected true got false
-FAIL < [Test 1] 2 out of 2 assertions were failed. assert_true: expected true got false
+PASS   Sine: -100 Hz equals [0,-0.014247103594243526,-0.028491314500570297,-0.04272974282503128,-0.056959498673677444,-0.07117769122123718,-0.08538143336772919,-0.09956784546375275,-0.11373404413461685,-0.1278771609067917,-0.14199431240558624,-0.1560826450586319,-0.17013929784297943,-0.18416140973567963,-0.19814614951610565,-0.2120906561613083...] with an element-wise tolerance of {"absoluteThreshold":4.7684e-7,"relativeThreshold":0}. 
+PASS   Sine: SNR (db) is greater than or equal to 130.95. 
+PASS < [Test 1] All assertions passed. (total 2 assertions) 
 PASS > [Test 2] Sine wave: 2 Hz 
-FAIL X Sine: 2 Hz does not equal [0,0.0002849517040885985,0.000569903408177197,0.0008548550540581346,0.0011398065835237503,0.001424758112989366,0.0017097094096243382,0.0019946605898439884,0.0022796117700636387,0.0025645627174526453,0.0028495131991803646,0.003134463680908084,0.0034194139298051596,0.003704363713040948,0.003989313263446093,0.004274262581020594...] with an element-wise tolerance of {"absoluteThreshold":1.4516e-7,"relativeThreshold":0}.
-	Index	Actual			Expected		AbsError		RelError		Test threshold
-	[1]	2.6180013082921505e-4	2.8495170408859849e-4	2.3151573259383440e-5	8.1247358507408843e-2	1.4516000000000001e-7
-	[2]	5.2360026165843010e-4	5.6990340817719698e-4	4.6303146518766880e-5	8.1247358507408843e-2	1.4516000000000001e-7
-	[3]	7.8540033427998424e-4	8.5485505405813456e-4	6.9454719778150320e-5	8.1247364039596634e-2	1.4516000000000001e-7
-	[4]	1.0472005233168602e-3	1.1398065835237503e-3	9.2606060206890106e-5	8.1247170831910243e-2	1.4516000000000001e-7
-	[5]	1.3090006541460752e-3	1.4247581129893661e-3	1.1575745884329081e-4	8.1247095761689328e-2	1.4516000000000001e-7
-	...and 250 more errors.
-	Max AbsError of 5.8895498514175415e-3 at index of 255.
-	[255]	6.6709212958812714e-2	7.2598762810230255e-2	5.8895498514175415e-3	8.1124658650348458e-2	1.4516000000000001e-7
-	Max RelError of 8.1253450445387218e-2 at index of 23.
-	[23]	6.0213203541934490e-3	6.5538426861166954e-3	5.3252233192324638e-4	8.1253450445387218e-2	1.4516000000000001e-7
- assert_true: expected true got false
-FAIL X Sine: SNR (db) is not greater than or equal to 119.93. Got 21.811635596188825. assert_true: expected true got false
-FAIL < [Test 2] 2 out of 2 assertions were failed. assert_true: expected true got false
+PASS   Sine: 2 Hz equals [0,0.0002849517040885985,0.000569903408177197,0.0008548550540581346,0.0011398065835237503,0.001424758112989366,0.0017097094096243382,0.0019946605898439884,0.0022796117700636387,0.0025645627174526453,0.0028495131991803646,0.003134463680908084,0.0034194139298051596,0.003704363713040948,0.003989313263446093,0.004274262581020594...] with an element-wise tolerance of {"absoluteThreshold":1.4516e-7,"relativeThreshold":0}. 
+PASS   Sine: SNR (db) is greater than or equal to 119.93. 
+PASS < [Test 2] All assertions passed. (total 2 assertions) 
 PASS > [Test 3] Sine wave: 1 Hz 
-FAIL X Sine: 1 Hz does not equal [0,0.00014247585204429924,0.0002849517040885985,0.00042742755613289773,0.000569903408177197,0.0007123792311176658,0.0008548550540581346,0.0009973308769986033,0.0011398065835237503,0.001282282406464219,0.001424758112989366,0.001567233819514513,0.0017097094096243382,0.0018521851161494851,0.0019946605898439884,0.0021371361799538136...] with an element-wise tolerance of {"absoluteThreshold":1.4157e-7,"relativeThreshold":0}.
-	Index	Actual			Expected		AbsError		RelError		Test threshold
-	[1]	1.3090006541460752e-4	1.4247585204429924e-4	1.1575786629691720e-5	8.1247358507408843e-2	1.4156999999999999e-7
-	[2]	2.6180013082921505e-4	2.8495170408859849e-4	2.3151573259383440e-5	8.1247358507408843e-2	1.4156999999999999e-7
-	[3]	3.9270016713999212e-4	4.2742755613289773e-4	3.4727388992905617e-5	8.1247426598083011e-2	1.4156999999999999e-7
-	[4]	5.2360026165843010e-4	5.6990340817719698e-4	4.6303146518766880e-5	8.1247358507408843e-2	1.4156999999999999e-7
-	[5]	6.5450032707303762e-4	7.1237923111766577e-4	5.7878904044628143e-5	8.1247320972315254e-2	1.4156999999999999e-7
-	...and 250 more errors.
-	Max AbsError of 2.9500462114810944e-3 at index of 255.
-	[255]	3.3373303711414337e-2	3.6323349922895432e-2	2.9500462114810944e-3	8.1216248439178601e-2	1.4156999999999999e-7
-	Max RelError of 8.1253793837885863e-2 at index of 47.
-	[47]	6.1522140167653561e-3	6.6963150165975094e-3	5.4410099983215332e-4	8.1253793837885863e-2	1.4156999999999999e-7
- assert_true: expected true got false
-FAIL X Sine: SNR (db) is not greater than or equal to 112.22. Got 21.80559297189769. assert_true: expected true got false
-FAIL < [Test 3] 2 out of 2 assertions were failed. assert_true: expected true got false
+PASS   Sine: 1 Hz equals [0,0.00014247585204429924,0.0002849517040885985,0.00042742755613289773,0.000569903408177197,0.0007123792311176658,0.0008548550540581346,0.0009973308769986033,0.0011398065835237503,0.001282282406464219,0.001424758112989366,0.001567233819514513,0.0017097094096243382,0.0018521851161494851,0.0019946605898439884,0.0021371361799538136...] with an element-wise tolerance of {"absoluteThreshold":1.4157e-7,"relativeThreshold":0}. 
+PASS   Sine: SNR (db) is greater than or equal to 112.22. 
+PASS < [Test 3] All assertions passed. (total 2 assertions) 
 PASS > [Test 4] Custom wave: 100 Hz 
 PASS   Custom: 100 Hz equals [1,1.0141456127166748,1.0280853509902954,1.0418163537979126,1.0553359985351562,1.0686413049697876,1.081729769706726,1.094598650932312,1.1072453260421753,1.1196671724319458,1.1318618059158325,1.1438266038894653,1.1555593013763428,1.1670573949813843,1.1783186197280884,1.189340591430664...] with an element-wise tolerance of {"absoluteThreshold":0.0000018478,"relativeThreshold":0}. 
 PASS   Custom: SNR (db) is greater than or equal to 122.43. 
@@ -86,5 +38,5 @@
  assert_true: expected true got false
 FAIL X Custom: SNR (db) is not greater than or equal to 138.76. Got 131.46607450774167. assert_true: expected true got false
 FAIL < [Test 5] 2 out of 2 assertions were failed. assert_true: expected true got false
-FAIL # AUDIT TASK RUNNER FINISHED: 5 out of 6 tasks were failed. assert_true: expected true got false
+FAIL # AUDIT TASK RUNNER FINISHED: 1 out of 6 tasks were failed. assert_true: expected true got false
 

Modified: trunk/Source/WebCore/ChangeLog (266569 => 266570)


--- trunk/Source/WebCore/ChangeLog	2020-09-04 01:54:05 UTC (rev 266569)
+++ trunk/Source/WebCore/ChangeLog	2020-09-04 02:00:00 UTC (rev 266570)
@@ -1,3 +1,25 @@
+2020-09-03  Chris Dumez  <cdu...@apple.com>
+
+        Tests using OscillatorNode are flaky
+        https://bugs.webkit.org/show_bug.cgi?id=216152
+
+        Reviewed by Darin Adler.
+
+        OscillatorNode was caching the different kind of PeriodicWaves in global static
+        variables. However, the PeriodicWaves are specific to a given sample rate.
+        As a result, we would sometimes use a cached periodic wave that was using the
+        wrong sample rate, leading to flaky failures. To address the issue, we now
+        cache the periodic waves per audio context instead.
+
+        No new tests, rebaselined existing tests and unskip them.
+
+        * Modules/webaudio/BaseAudioContext.cpp:
+        (WebCore::BaseAudioContext::periodicWave):
+        * Modules/webaudio/BaseAudioContext.h:
+        * Modules/webaudio/OscillatorNode.cpp:
+        (WebCore::OscillatorNode::setType):
+        * Modules/webaudio/OscillatorNode.h:
+
 2020-09-03  Patrick Angle  <pan...@apple.com>
 
         Web Inspector fails to preview response from XHR requests

Modified: trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp (266569 => 266570)


--- trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp	2020-09-04 01:54:05 UTC (rev 266569)
+++ trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.cpp	2020-09-04 02:00:00 UTC (rev 266570)
@@ -1298,6 +1298,33 @@
     ref();
 }
 
+PeriodicWave& BaseAudioContext::periodicWave(OscillatorType type)
+{
+    switch (type) {
+    case OscillatorType::Square:
+        if (!m_cachedPeriodicWaveSquare)
+            m_cachedPeriodicWaveSquare = PeriodicWave::createSquare(sampleRate());
+        return *m_cachedPeriodicWaveSquare;
+    case OscillatorType::Sawtooth:
+        if (!m_cachedPeriodicWaveSawtooth)
+            m_cachedPeriodicWaveSawtooth = PeriodicWave::createSawtooth(sampleRate());
+        return *m_cachedPeriodicWaveSawtooth;
+    case OscillatorType::Triangle:
+        if (!m_cachedPeriodicWaveTriangle)
+            m_cachedPeriodicWaveTriangle = PeriodicWave::createTriangle(sampleRate());
+        return *m_cachedPeriodicWaveTriangle;
+    case OscillatorType::Custom:
+        ASSERT_NOT_REACHED();
+#if NDEBUG
+        FALLTHROUGH;
+#endif
+    case OscillatorType::Sine:
+        if (!m_cachedPeriodicWaveSine)
+            m_cachedPeriodicWaveSine = PeriodicWave::createSine(sampleRate());
+        return *m_cachedPeriodicWaveSine;
+    }
+}
+
 #if !RELEASE_LOG_DISABLED
 WTFLogChannel& BaseAudioContext::logChannel() const
 {

Modified: trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h (266569 => 266570)


--- trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h	2020-09-04 01:54:05 UTC (rev 266569)
+++ trunk/Source/WebCore/Modules/webaudio/BaseAudioContext.h	2020-09-04 02:00:00 UTC (rev 266570)
@@ -35,6 +35,7 @@
 #include "JSDOMPromiseDeferred.h"
 #include "MediaCanStartListener.h"
 #include "MediaProducer.h"
+#include "OscillatorType.h"
 #include "PeriodicWaveConstraints.h"
 #include "PlatformMediaSession.h"
 #include "ScriptExecutionContext.h"
@@ -311,6 +312,8 @@
 
     static bool isSupportedSampleRate(float sampleRate);
 
+    PeriodicWave& periodicWave(OscillatorType);
+
 protected:
     explicit BaseAudioContext(Document&, const AudioContextOptions& = { });
     BaseAudioContext(Document&, AudioBuffer* renderTarget);
@@ -459,6 +462,13 @@
     RefPtr<PendingActivity<BaseAudioContext>> m_pendingActivity;
 
     AudioIOPosition m_outputPosition;
+
+    // These are cached per audio context for performance reasons. They cannot be
+    // static because they rely on the sample rate.
+    RefPtr<PeriodicWave> m_cachedPeriodicWaveSine;
+    RefPtr<PeriodicWave> m_cachedPeriodicWaveSquare;
+    RefPtr<PeriodicWave> m_cachedPeriodicWaveSawtooth;
+    RefPtr<PeriodicWave> m_cachedPeriodicWaveTriangle;
 };
 
 } // WebCore

Modified: trunk/Source/WebCore/Modules/webaudio/OscillatorNode.cpp (266569 => 266570)


--- trunk/Source/WebCore/Modules/webaudio/OscillatorNode.cpp	2020-09-04 01:54:05 UTC (rev 266569)
+++ trunk/Source/WebCore/Modules/webaudio/OscillatorNode.cpp	2020-09-04 02:00:00 UTC (rev 266570)
@@ -40,11 +40,6 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(OscillatorNode);
 
-PeriodicWave* OscillatorNode::s_periodicWaveSine = nullptr;
-PeriodicWave* OscillatorNode::s_periodicWaveSquare = nullptr;
-PeriodicWave* OscillatorNode::s_periodicWaveSawtooth = nullptr;
-PeriodicWave* OscillatorNode::s_periodicWaveTriangle = nullptr;
-
 ExceptionOr<Ref<OscillatorNode>> OscillatorNode::create(BaseAudioContext& context, const OscillatorOptions& options)
 {
     if (context.isStopped())
@@ -95,38 +90,15 @@
 
 ExceptionOr<void> OscillatorNode::setType(OscillatorType type)
 {
-    PeriodicWave* periodicWave = nullptr;
-
     ALWAYS_LOG(LOGIDENTIFIER, type);
 
-    switch (type) {
-    case OscillatorType::Sine:
-        if (!s_periodicWaveSine)
-            s_periodicWaveSine = &PeriodicWave::createSine(sampleRate()).leakRef();
-        periodicWave = s_periodicWaveSine;
-        break;
-    case OscillatorType::Square:
-        if (!s_periodicWaveSquare)
-            s_periodicWaveSquare = &PeriodicWave::createSquare(sampleRate()).leakRef();
-        periodicWave = s_periodicWaveSquare;
-        break;
-    case OscillatorType::Sawtooth:
-        if (!s_periodicWaveSawtooth)
-            s_periodicWaveSawtooth = &PeriodicWave::createSawtooth(sampleRate()).leakRef();
-        periodicWave = s_periodicWaveSawtooth;
-        break;
-    case OscillatorType::Triangle:
-        if (!s_periodicWaveTriangle)
-            s_periodicWaveTriangle = &PeriodicWave::createTriangle(sampleRate()).leakRef();
-        periodicWave = s_periodicWaveTriangle;
-        break;
-    case OscillatorType::Custom:
+    if (type == OscillatorType::Custom) {
         if (m_type != OscillatorType::Custom)
-            return Exception { InvalidStateError };
+            return Exception { InvalidStateError, "OscillatorNode.type cannot be changed to 'custom'"_s };
         return { };
     }
 
-    setPeriodicWave(*periodicWave);
+    setPeriodicWave(context().periodicWave(type));
     m_type = type;
 
     return { };

Modified: trunk/Source/WebCore/Modules/webaudio/OscillatorNode.h (266569 => 266570)


--- trunk/Source/WebCore/Modules/webaudio/OscillatorNode.h	2020-09-04 01:54:05 UTC (rev 266569)
+++ trunk/Source/WebCore/Modules/webaudio/OscillatorNode.h	2020-09-04 02:00:00 UTC (rev 266570)
@@ -90,12 +90,6 @@
     AudioFloatArray m_detuneValues { AudioNode::ProcessingSizeInFrames };
     
     RefPtr<PeriodicWave> m_periodicWave;
-
-    // Cache the wave tables for different waveform types, except CUSTOM.
-    static PeriodicWave* s_periodicWaveSine;
-    static PeriodicWave* s_periodicWaveSquare;
-    static PeriodicWave* s_periodicWaveSawtooth;
-    static PeriodicWave* s_periodicWaveTriangle;
 };
 
 String convertEnumerationToString(OscillatorType); // In JSOscillatorNode.cpp
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to