| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 | 3 |
| 4 <head> | 4 <head> |
| 5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 8 <script src="../resources/audit.js"></script> | 8 <script src="../resources/audit.js"></script> |
| 9 <script src="../resources/late-start-testing.js"></script> | |
| 10 </head> | 9 </head> |
| 11 | 10 |
| 12 <body> | 11 <body> |
| 13 <script> | 12 <script> |
| 14 var audit = Audit.createTaskRunner(); | 13 let audit = Audit.createTaskRunner(); |
| 15 | 14 |
| 16 var sampleRate = 44100; | 15 let sampleRate = 44100; |
| 16 let renderLength = 1; |
| 17 | 17 |
| 18 var renderLength = 1; | 18 let context; |
| 19 | 19 let node; |
| 20 var context = new OfflineAudioContext(1, sampleRate * renderLength, sampleRa
te); | |
| 21 var osc = context.createOscillator(); | |
| 22 | 20 |
| 23 // Test the oscillator node is rendered correctly when the start time of sta
rt() | 21 // Test the oscillator node is rendered correctly when the start time of |
| 24 // call is in the past in terms of the context time. | 22 // start() call is in the past in terms of the context time. |
| 25 runLateStartTest(audit, context, osc); | 23 audit.define('initialize', (task, should) => { |
| 24 should( |
| 25 () => context = |
| 26 new OfflineAudioContext(1, sampleRate * renderLength, sampleRate), |
| 27 'Creating offline context for testing') |
| 28 .notThrow(); |
| 29 should(() => { |
| 30 // Set up a dummy signal path to keep the audio context running and |
| 31 // spend processing time before calling start(0). |
| 32 let osc = context.createOscillator(); |
| 33 let silent = context.createGain(); |
| 34 |
| 35 osc.connect(silent); |
| 36 silent.connect(context.destination); |
| 37 silent.gain.setValueAtTime(0.0, 0); |
| 38 osc.start(); |
| 39 |
| 40 node = context.createOscillator(); |
| 41 node.connect(context.destination); |
| 42 }, 'Creating graph for testing').notThrow(); |
| 43 task.done(); |
| 44 }); |
| 45 |
| 46 audit.define('test-late-start', (task, should) => { |
| 47 // The node's start time will be clamped to the render quantum boundary |
| 48 // >0.1 sec. Thus the rendered buffer will have non-zero frames. |
| 49 // See issue: crbug.com/462167 |
| 50 let suspendTime = 0.1; |
| 51 let suspendFrame = 128 * Math.floor(0.1 * context.sampleRate / 128); |
| 52 |
| 53 context.suspend(suspendTime).then(() => { |
| 54 node.start(0); |
| 55 context.resume(); |
| 56 }); |
| 57 |
| 58 // Start rendering and verify result: this verifies if 1) the rendered |
| 59 // buffer contains at least one non-zero value and 2) the non-zero value |
| 60 // is found later than the first output sample. |
| 61 context.startRendering() |
| 62 .then(buffer => { |
| 63 let channelData = buffer.getChannelData(0); |
| 64 let nonZeroValueIndex = channelData.findIndex(x => x != 0); |
| 65 |
| 66 should( |
| 67 nonZeroValueIndex, |
| 68 'The index (' + nonZeroValueIndex + |
| 69 ') of first non-zero output value') |
| 70 .beGreaterThanOrEqualTo(suspendFrame); |
| 71 |
| 72 should( |
| 73 channelData.slice(0, suspendFrame), |
| 74 'Output[0:' + (suspendFrame - 1) + ']') |
| 75 .beConstantValueOf(0); |
| 76 }) |
| 77 .then(() => task.done()); |
| 78 ; |
| 79 }); |
| 80 |
| 81 audit.run(); |
| 26 </script> | 82 </script> |
| 27 </body> | 83 </body> |
| 28 | 84 |
| 29 </html> | 85 </html> |
| OLD | NEW |