| OLD | NEW |
| 1 <!doctype html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title> |
| 5 Test setValueCurveAtTime with Huge Duration |
| 6 </title> |
| 4 <script src="../../resources/testharness.js"></script> | 7 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> | 8 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="../resources/audit-util.js"></script> | 9 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audit.js"></script> | 10 <script src="../resources/audit.js"></script> |
| 8 <script src="../resources/audioparam-testing.js"></script> | 11 <script src="../resources/audioparam-testing.js"></script> |
| 9 <title>Test setValueCurveAtTime with Huge Duration</title> | |
| 10 </head> | 12 </head> |
| 13 <body> |
| 14 <script id="layout-test-code"> |
| 15 let sampleRate = 48000; |
| 16 let renderFrames = 1000; |
| 11 | 17 |
| 12 <body> | 18 let audit = Audit.createTaskRunner(); |
| 13 <script> | |
| 14 | 19 |
| 15 var sampleRate = 48000; | 20 audit.define('long duration', (task, should) => { |
| 16 var renderFrames = 1000; | |
| 17 | |
| 18 var audit = Audit.createTaskRunner(); | |
| 19 | |
| 20 audit.define("long duration", (task, should) => { | |
| 21 // We only need to generate a small number of frames for this test. | 21 // We only need to generate a small number of frames for this test. |
| 22 var context = new OfflineAudioContext(1, renderFrames, sampleRate); | 22 let context = new OfflineAudioContext(1, renderFrames, sampleRate); |
| 23 var src = context.createBufferSource(); | 23 let src = context.createBufferSource(); |
| 24 | 24 |
| 25 // Constant source of amplitude 1, looping. | 25 // Constant source of amplitude 1, looping. |
| 26 src.buffer = createConstantBuffer(context, 1, 1); | 26 src.buffer = createConstantBuffer(context, 1, 1); |
| 27 src.loop = true; | 27 src.loop = true; |
| 28 | 28 |
| 29 // Automate the gain with a setValueCurve with a very long duration. Th
e duration should | 29 // Automate the gain with a setValueCurve with a very long duration. |
| 30 // produce a frame number greater than 2^64 (larger than the largest siz
e_t value). | 30 // The duration should produce a frame number greater than 2^64 (larger |
| 31 var gain = context.createGain(); | 31 // than the largest size_t value). |
| 32 var duration = Math.pow(2, 64); | 32 let gain = context.createGain(); |
| 33 var curve = Float32Array.from([0, 1]); | 33 let duration = Math.pow(2, 64); |
| 34 let curve = Float32Array.from([0, 1]); |
| 34 gain.gain.setValueCurveAtTime(curve, 0, duration); | 35 gain.gain.setValueCurveAtTime(curve, 0, duration); |
| 35 | 36 |
| 36 // Create the graph and go! | 37 // Create the graph and go! |
| 37 src.connect(gain); | 38 src.connect(gain); |
| 38 gain.connect(context.destination); | 39 gain.connect(context.destination); |
| 39 src.start(); | 40 src.start(); |
| 40 | 41 |
| 41 context.startRendering().then(function (result) { | 42 context.startRendering() |
| 42 // Find the maximum value of the buffer. | 43 .then(function(result) { |
| 43 var max = Math.max.apply(null, result.getChannelData(0)); | 44 // Find the maximum value of the buffer. |
| 45 let max = Math.max.apply(null, result.getChannelData(0)); |
| 44 | 46 |
| 45 // The automation does linear interpolation between 0 and 1 from time
0 to duration. | 47 // The automation does linear interpolation between 0 and 1 from |
| 46 // Hence the max value of the interpolation occurs at the end of the
rendering. Compute | 48 // time 0 to duration. Hence the max value of the interpolation |
| 47 // this value. | 49 // occurs at the end of the rendering. Compute this value. |
| 48 | 50 |
| 49 var expectedMax = (renderFrames / sampleRate) * (1 / duration); | 51 let expectedMax = (renderFrames / sampleRate) * (1 / duration); |
| 50 | 52 |
| 51 var message = "setValueCurve([" + curve + "], 0, " + duration + ")"; | 53 let message = |
| 54 'setValueCurve([' + curve + '], 0, ' + duration + ')'; |
| 52 | 55 |
| 53 should(max, "Max amplitude of " + message) | 56 should(max, 'Max amplitude of ' + message) |
| 54 .beLessThanOrEqualTo(expectedMax); | 57 .beLessThanOrEqualTo(expectedMax); |
| 55 }).then(() => task.done()); | 58 }) |
| 59 .then(() => task.done()); |
| 56 }); | 60 }); |
| 57 | 61 |
| 58 audit.run(); | 62 audit.run(); |
| 59 </script> | 63 </script> |
| 60 </body> | 64 </body> |
| 61 </html> | 65 </html> |
| OLD | NEW |