| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title> |
| 5 audionode-connect-order.html |
| 6 </title> |
| 7 <script src="../../resources/testharness.js"></script> |
| 8 <script src="../../resources/testharnessreport.js"></script> |
| 9 <script src="../resources/audit-util.js"></script> |
| 10 <script src="../resources/audit.js"></script> |
| 11 </head> |
| 12 <body> |
| 13 <script id="layout-test-code"> |
| 14 let audit = Audit.createTaskRunner(); |
| 15 let sampleRate = 44100.0; |
| 16 let renderLengthSeconds = 0.125; |
| 17 let delayTimeSeconds = 0.1; |
| 2 | 18 |
| 3 <html> | 19 function createSinWaveBuffer(context, lengthInSeconds, frequency) { |
| 4 <head> | 20 let audioBuffer = |
| 5 <script src="../../resources/testharness.js"></script> | 21 context.createBuffer(1, lengthInSeconds * sampleRate, sampleRate); |
| 6 <script src="../../resources/testharnessreport.js"></script> | |
| 7 <script src="../resources/audit-util.js"></script> | |
| 8 <script src="../resources/audit.js"></script> | |
| 9 </head> | |
| 10 | 22 |
| 11 <body> | 23 let n = audioBuffer.length; |
| 12 <script> | 24 let data = audioBuffer.getChannelData(0); |
| 13 let audit = Audit.createTaskRunner(); | |
| 14 let sampleRate = 44100.0; | |
| 15 let renderLengthSeconds = 0.125; | |
| 16 let delayTimeSeconds = 0.1; | |
| 17 | 25 |
| 18 function createSinWaveBuffer(context, lengthInSeconds, frequency) { | 26 for (let i = 0; i < n; ++i) { |
| 19 let audioBuffer = | 27 data[i] = Math.sin(frequency * 2 * Math.PI * i / sampleRate); |
| 20 context.createBuffer(1, lengthInSeconds * sampleRate, sampleRate); | 28 } |
| 21 | 29 |
| 22 let n = audioBuffer.length; | 30 return audioBuffer; |
| 23 let data = audioBuffer.getChannelData(0); | 31 } |
| 24 | 32 |
| 25 for (let i = 0; i < n; ++i) { | 33 audit.define( |
| 26 data[i] = Math.sin(frequency * 2 * Math.PI * i / sampleRate); | 34 { |
| 27 } | 35 label: 'Test connections', |
| 36 description: |
| 37 'AudioNode connection order doesn\'t trigger assertion errors' |
| 38 }, |
| 39 function(task, should) { |
| 40 // Create offline audio context. |
| 41 let context = new OfflineAudioContext( |
| 42 1, sampleRate * renderLengthSeconds, sampleRate); |
| 43 let toneBuffer = |
| 44 createSinWaveBuffer(context, renderLengthSeconds, 880); |
| 28 | 45 |
| 29 return audioBuffer; | 46 let bufferSource = context.createBufferSource(); |
| 30 } | 47 bufferSource.buffer = toneBuffer; |
| 48 bufferSource.connect(context.destination); |
| 31 | 49 |
| 32 audit.define({ | 50 let delay = context.createDelay(); |
| 33 label: 'Test connections', | 51 delay.delayTime.value = delayTimeSeconds; |
| 34 description: 'AudioNode connection order doesn\'t trigger assertion errors' | |
| 35 }, function(task, should) { | |
| 36 // Create offline audio context. | |
| 37 let context = | |
| 38 new OfflineAudioContext(1, sampleRate * renderLengthSeconds, sampleRate); | |
| 39 let toneBuffer = createSinWaveBuffer(context, renderLengthSeconds, 880); | |
| 40 | 52 |
| 41 let bufferSource = context.createBufferSource(); | 53 // We connect delay node to gain node before anything is connected |
| 42 bufferSource.buffer = toneBuffer; | 54 // to delay node itself. We do this because we try to trigger the |
| 43 bufferSource.connect(context.destination); | 55 // ASSERT which might be fired due to AudioNode connection order, |
| 56 // especially when gain node and delay node is involved e.g. |
| 57 // https://bugs.webkit.org/show_bug.cgi?id=76685. |
| 44 | 58 |
| 45 let delay = context.createDelay(); | 59 should(() => { |
| 46 delay.delayTime.value = delayTimeSeconds; | 60 let gain = context.createGain(); |
| 61 gain.connect(context.destination); |
| 62 delay.connect(gain); |
| 63 }, 'Connecting nodes').notThrow(); |
| 47 | 64 |
| 48 // We connect delay node to gain node before anything is connected to delay | 65 bufferSource.start(0); |
| 49 // node itself. We do this because we try to trigger the ASSERT which might | |
| 50 // be fired due to AudioNode connection order, especially when gain node and | |
| 51 // delay node is involved | |
| 52 // e.g. https://bugs.webkit.org/show_bug.cgi?id=76685. | |
| 53 | 66 |
| 54 should(() => { | 67 let promise = context.startRendering(); |
| 55 let gain = context.createGain(); | |
| 56 gain.connect(context.destination); | |
| 57 delay.connect(gain); | |
| 58 }, 'Connecting nodes').notThrow(); | |
| 59 | 68 |
| 60 bufferSource.start(0); | 69 should(promise, 'OfflineContext startRendering()') |
| 70 .beResolved() |
| 71 .then(task.done.bind(task)); |
| 72 }); |
| 61 | 73 |
| 62 let promise = context.startRendering(); | 74 audit.run(); |
| 63 | 75 </script> |
| 64 should(promise, 'OfflineContext startRendering()') | 76 </body> |
| 65 .beResolved() | |
| 66 .then(task.done.bind(task)); | |
| 67 }); | |
| 68 | |
| 69 audit.run(); | |
| 70 | |
| 71 </script> | |
| 72 | |
| 73 </body> | |
| 74 </html> | 77 </html> |
| OLD | NEW |