content/media/webaudio/test/test_delayNodeTailWithDisconnect.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/test/test_delayNodeTailWithDisconnect.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,97 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test tail time lifetime of DelayNode after input is disconnected</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="webaudio.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +</head>
    1.12 +<body>
    1.13 +<pre id="test">
    1.14 +<script class="testbody" type="text/javascript">
    1.15 +
    1.16 +// Web Audio doesn't provide a means to precisely time disconnect()s but we
    1.17 +// can test that the output of delay nodes matches the output from their
    1.18 +// sources before they are disconnected.
    1.19 +
    1.20 +SimpleTest.waitForExplicitFinish();
    1.21 +
    1.22 +const signalLength = 128;
    1.23 +const bufferSize = 4096;
    1.24 +const sourceCount = bufferSize / signalLength;
    1.25 +// Delay should be long enough to allow CC to run
    1.26 +var delayBufferCount = 20;
    1.27 +const delayLength = delayBufferCount * bufferSize;
    1.28 +
    1.29 +var sourceOutput = new Float32Array(bufferSize);
    1.30 +var delayOutputCount = 0;
    1.31 +var sources = [];
    1.32 +
    1.33 +function onDelayOutput(e) {
    1.34 +  if (delayOutputCount < delayBufferCount) {
    1.35 +    delayOutputCount++;
    1.36 +    return;
    1.37 +  }
    1.38 +
    1.39 +  compareChannels(e.inputBuffer.getChannelData(0), sourceOutput);
    1.40 +  e.target.onaudioprocess = null;
    1.41 +  SimpleTest.finish();
    1.42 +}
    1.43 +
    1.44 +function onSourceOutput(e) {
    1.45 +  // Record the first buffer
    1.46 +  e.inputBuffer.copyFromChannel(sourceOutput, 0);
    1.47 +  e.target.onaudioprocess = null;
    1.48 +}
    1.49 +
    1.50 +function disconnectSources() {
    1.51 +  for (var i = 0; i < sourceCount; ++i) {
    1.52 +    sources[i].disconnect();
    1.53 +  }
    1.54 +
    1.55 +  SpecialPowers.forceGC();
    1.56 +  SpecialPowers.forceCC();
    1.57 +}
    1.58 +
    1.59 +function startTest() {
    1.60 +  var ctx = new AudioContext();
    1.61 +
    1.62 +  var sourceProcessor = ctx.createScriptProcessor(bufferSize, 1, 0);
    1.63 +  sourceProcessor.onaudioprocess = onSourceOutput;
    1.64 +  // Keep audioprocess events going after source disconnect.
    1.65 +  sourceProcessor.connect(ctx.destination);
    1.66 +
    1.67 +  var delayProcessor = ctx.createScriptProcessor(bufferSize, 1, 0);
    1.68 +  delayProcessor.onaudioprocess = onDelayOutput;
    1.69 +  // Work around bug 916387.
    1.70 +  delayProcessor.connect(ctx.destination);
    1.71 +
    1.72 +  var delayDuration = delayLength / ctx.sampleRate;
    1.73 +  for (var i = 0; i < sourceCount; ++i) {
    1.74 +    var delay = ctx.createDelay(delayDuration);
    1.75 +    delay.delayTime.value = delayDuration;
    1.76 +    delay.connect(delayProcessor);
    1.77 +
    1.78 +    var source = ctx.createOscillator();
    1.79 +    source.frequency.value = 440 + 10 * i
    1.80 +    source.start(i * signalLength / ctx.sampleRate);
    1.81 +    source.stop((i + 1) * signalLength / ctx.sampleRate);
    1.82 +    source.connect(delay);
    1.83 +    source.connect(sourceProcessor);
    1.84 +
    1.85 +    sources[i] = source;
    1.86 +  }
    1.87 +
    1.88 +  // Assuming the above Web Audio operations have already scheduled an event
    1.89 +  // to run in stable state and start the graph thread, schedule a subsequent
    1.90 +  // event to disconnect the sources, which will remove main thread connection
    1.91 +  // references before it knows the graph thread has started using the source
    1.92 +  // streams.
    1.93 +  SimpleTest.executeSoon(disconnectSources);
    1.94 +};
    1.95 +
    1.96 +startTest();
    1.97 +</script>
    1.98 +</pre>
    1.99 +</body>
   1.100 +</html>

mercurial