|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test tail time lifetime of DelayNode after input is disconnected</title> |
|
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <script type="text/javascript" src="webaudio.js"></script> |
|
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
8 </head> |
|
9 <body> |
|
10 <pre id="test"> |
|
11 <script class="testbody" type="text/javascript"> |
|
12 |
|
13 // Web Audio doesn't provide a means to precisely time disconnect()s but we |
|
14 // can test that the output of delay nodes matches the output from their |
|
15 // sources before they are disconnected. |
|
16 |
|
17 SimpleTest.waitForExplicitFinish(); |
|
18 |
|
19 const signalLength = 128; |
|
20 const bufferSize = 4096; |
|
21 const sourceCount = bufferSize / signalLength; |
|
22 // Delay should be long enough to allow CC to run |
|
23 var delayBufferCount = 20; |
|
24 const delayLength = delayBufferCount * bufferSize; |
|
25 |
|
26 var sourceOutput = new Float32Array(bufferSize); |
|
27 var delayOutputCount = 0; |
|
28 var sources = []; |
|
29 |
|
30 function onDelayOutput(e) { |
|
31 if (delayOutputCount < delayBufferCount) { |
|
32 delayOutputCount++; |
|
33 return; |
|
34 } |
|
35 |
|
36 compareChannels(e.inputBuffer.getChannelData(0), sourceOutput); |
|
37 e.target.onaudioprocess = null; |
|
38 SimpleTest.finish(); |
|
39 } |
|
40 |
|
41 function onSourceOutput(e) { |
|
42 // Record the first buffer |
|
43 e.inputBuffer.copyFromChannel(sourceOutput, 0); |
|
44 e.target.onaudioprocess = null; |
|
45 } |
|
46 |
|
47 function disconnectSources() { |
|
48 for (var i = 0; i < sourceCount; ++i) { |
|
49 sources[i].disconnect(); |
|
50 } |
|
51 |
|
52 SpecialPowers.forceGC(); |
|
53 SpecialPowers.forceCC(); |
|
54 } |
|
55 |
|
56 function startTest() { |
|
57 var ctx = new AudioContext(); |
|
58 |
|
59 var sourceProcessor = ctx.createScriptProcessor(bufferSize, 1, 0); |
|
60 sourceProcessor.onaudioprocess = onSourceOutput; |
|
61 // Keep audioprocess events going after source disconnect. |
|
62 sourceProcessor.connect(ctx.destination); |
|
63 |
|
64 var delayProcessor = ctx.createScriptProcessor(bufferSize, 1, 0); |
|
65 delayProcessor.onaudioprocess = onDelayOutput; |
|
66 // Work around bug 916387. |
|
67 delayProcessor.connect(ctx.destination); |
|
68 |
|
69 var delayDuration = delayLength / ctx.sampleRate; |
|
70 for (var i = 0; i < sourceCount; ++i) { |
|
71 var delay = ctx.createDelay(delayDuration); |
|
72 delay.delayTime.value = delayDuration; |
|
73 delay.connect(delayProcessor); |
|
74 |
|
75 var source = ctx.createOscillator(); |
|
76 source.frequency.value = 440 + 10 * i |
|
77 source.start(i * signalLength / ctx.sampleRate); |
|
78 source.stop((i + 1) * signalLength / ctx.sampleRate); |
|
79 source.connect(delay); |
|
80 source.connect(sourceProcessor); |
|
81 |
|
82 sources[i] = source; |
|
83 } |
|
84 |
|
85 // Assuming the above Web Audio operations have already scheduled an event |
|
86 // to run in stable state and start the graph thread, schedule a subsequent |
|
87 // event to disconnect the sources, which will remove main thread connection |
|
88 // references before it knows the graph thread has started using the source |
|
89 // streams. |
|
90 SimpleTest.executeSoon(disconnectSources); |
|
91 }; |
|
92 |
|
93 startTest(); |
|
94 </script> |
|
95 </pre> |
|
96 </body> |
|
97 </html> |