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