5 <script src="../resources/js-test.js"></script>
6 <script src="resources/audio-testing.js"></script>
11 <div id="description"></div>
12 <div id="console"></div>
15 description("This tests that we don't trigger an assertion failure due to AudioNode connection order.");
17 var sampleRate = 44100.0;
18 var renderLengthSeconds = 0.125;
19 var delayTimeSeconds = 0.1;
21 function createSinWaveBuffer(context, lengthInSeconds, frequency) {
22 var audioBuffer = context.createBuffer(1, lengthInSeconds * sampleRate, sampleRate);
24 var n = audioBuffer.length;
25 var data = audioBuffer.getChannelData(0);
27 for (var i = 0; i < n; ++i) {
28 data[i] = Math.sin(frequency * 2 * Math.PI * i / sampleRate);
35 if (window.testRunner) {
36 testRunner.dumpAsText();
37 testRunner.waitUntilDone();
40 window.jsTestIsAsync = true;
42 // Create offline audio context.
43 var context = new webkitOfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate);
44 var toneBuffer = createSinWaveBuffer(context, renderLengthSeconds, 880);
46 var bufferSource = context.createBufferSource();
47 bufferSource.buffer = toneBuffer;
48 bufferSource.connect(context.destination);
50 var delay = context.createDelay();
51 delay.delayTime.value = delayTimeSeconds;
53 // We connect delay node to gain node before anything is connected to delay node itself.
54 // We do this because we try to trigger the ASSERT which might be fired due to AudioNode connection order,
55 // especially when gain node and delay node is involved e.g. https://bugs.webkit.org/show_bug.cgi?id=76685.
57 var gain = context.createGain();
58 gain.connect(context.destination);
61 bufferSource.start(0);
63 context.oncomplete = finishJSTest;
64 context.startRendering();