diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/media/webaudio/test/test_delayNodeTailWithDisconnect.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/media/webaudio/test/test_delayNodeTailWithDisconnect.html')
-rw-r--r-- | dom/media/webaudio/test/test_delayNodeTailWithDisconnect.html | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/dom/media/webaudio/test/test_delayNodeTailWithDisconnect.html b/dom/media/webaudio/test/test_delayNodeTailWithDisconnect.html new file mode 100644 index 000000000..fa431d61b --- /dev/null +++ b/dom/media/webaudio/test/test_delayNodeTailWithDisconnect.html @@ -0,0 +1,95 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test tail time lifetime of DelayNode after input is disconnected</title> + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <script type="text/javascript" src="webaudio.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<pre id="test"> +<script class="testbody" type="text/javascript"> + +// Web Audio doesn't provide a means to precisely time disconnect()s but we +// can test that the output of delay nodes matches the output from their +// sources before they are disconnected. + +SimpleTest.waitForExplicitFinish(); + +const signalLength = 128; +const bufferSize = 4096; +const sourceCount = bufferSize / signalLength; +// Delay should be long enough to allow CC to run +var delayBufferCount = 20; +const delayLength = delayBufferCount * bufferSize; + +var sourceOutput = new Float32Array(bufferSize); +var delayOutputCount = 0; +var sources = []; + +function onDelayOutput(e) { + if (delayOutputCount < delayBufferCount) { + delayOutputCount++; + return; + } + + compareChannels(e.inputBuffer.getChannelData(0), sourceOutput); + e.target.onaudioprocess = null; + SimpleTest.finish(); +} + +function onSourceOutput(e) { + // Record the first buffer + e.inputBuffer.copyFromChannel(sourceOutput, 0); + e.target.onaudioprocess = null; +} + +function disconnectSources() { + for (var i = 0; i < sourceCount; ++i) { + sources[i].disconnect(); + } + + SpecialPowers.forceGC(); + SpecialPowers.forceCC(); +} + +function startTest() { + var ctx = new AudioContext(); + + var sourceProcessor = ctx.createScriptProcessor(bufferSize, 1, 0); + sourceProcessor.onaudioprocess = onSourceOutput; + // Keep audioprocess events going after source disconnect. + sourceProcessor.connect(ctx.destination); + + var delayProcessor = ctx.createScriptProcessor(bufferSize, 1, 0); + delayProcessor.onaudioprocess = onDelayOutput; + + var delayDuration = delayLength / ctx.sampleRate; + for (var i = 0; i < sourceCount; ++i) { + var delay = ctx.createDelay(delayDuration); + delay.delayTime.value = delayDuration; + delay.connect(delayProcessor); + + var source = ctx.createOscillator(); + source.frequency.value = 440 + 10 * i + source.start(i * signalLength / ctx.sampleRate); + source.stop((i + 1) * signalLength / ctx.sampleRate); + source.connect(delay); + source.connect(sourceProcessor); + + sources[i] = source; + } + + // Assuming the above Web Audio operations have already scheduled an event + // to run in stable state and start the graph thread, schedule a subsequent + // event to disconnect the sources, which will remove main thread connection + // references before it knows the graph thread has started using the source + // streams. + SimpleTest.executeSoon(disconnectSources); +}; + +startTest(); +</script> +</pre> +</body> +</html> |