audionode-connect-order.html (2062B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title> 5 AudioNode: Connection Order Robustness 6 </title> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="/webaudio/resources/audit-util.js"></script> 10 </head> 11 <body> 12 <script> 13 const sampleRate = 44100.0; 14 const renderLengthSeconds = 0.125; 15 const delayTimeSeconds = 0.1; 16 17 const createSinWaveBuffer = (lengthInSeconds, frequency) => { 18 const audioBuffer = new AudioBuffer({ 19 numberOfChannels: 1, 20 length: Math.floor(lengthInSeconds * sampleRate), 21 sampleRate 22 }); 23 24 let channelData = audioBuffer.getChannelData(0); 25 26 for (let i = 0; i < audioBuffer.length; ++i) { 27 channelData[i] = Math.sin(frequency * 2 * Math.PI * i / sampleRate); 28 } 29 30 return audioBuffer; 31 } 32 33 promise_test(async () => { 34 const context = new OfflineAudioContext( 35 1, sampleRate * renderLengthSeconds, sampleRate); 36 37 const bufferSource = new AudioBufferSourceNode(context, { 38 buffer: createSinWaveBuffer(renderLengthSeconds, 880) 39 }); 40 bufferSource.connect(context.destination); 41 42 const delay = new DelayNode(context, { 43 delayTime: delayTimeSeconds 44 }); 45 46 // We connect delay node to gain node before anything is connected 47 // to delay node itself. We do this because we try to trigger the 48 // ASSERT which might be fired due to AudioNode connection order, 49 // especially when gain node and delay node is involved e.g. 50 // https://bugs.webkit.org/show_bug.cgi?id=76685. 51 52 // This should not throw an exception. 53 const gain = new GainNode(context); 54 gain.connect(context.destination); 55 delay.connect(gain); 56 57 bufferSource.start(); 58 59 await context.startRendering(); 60 }, `Test connections: AudioNode connection order doesn't `+ 61 `trigger assertion errors`); 62 </script> 63 </body> 64 </html>