| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test setTargetAtTime with timeConstant=0</title> | 4 <title>Test setTargetAtTime with timeConstant=0</title> |
| 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/audio-testing.js"></script> | 7 <script src="../resources/audit.js"></script> |
| 8 </head> | 8 </head> |
| 9 | 9 |
| 10 <body> | 10 <body> |
| 11 <script> | 11 <script> |
| 12 // Fairly arbitrary sample rate and number of frames, so choose a low | 12 // Fairly arbitrary sample rate and number of frames, so choose a low |
| 13 // sample rate, and short rendering length. | 13 // sample rate, and short rendering length. |
| 14 var sampleRate = 8000; | 14 var sampleRate = 8000; |
| 15 var renderFrames = 128; | 15 var renderFrames = 128; |
| 16 | 16 |
| 17 // Array specifying parameters for setTargetAtTime. |frame| is the frame | 17 // Array specifying parameters for setTargetAtTime. |frame| is the frame |
| 18 // (not necessarily an integer) at which setTargetAtTime starts, and | 18 // (not necessarily an integer) at which setTargetAtTime starts, and |
| 19 // |value| is the target value. Non-integral values for |frame| tests | 19 // |value| is the target value. Non-integral values for |frame| tests |
| 20 // that we started the setTargetAtTime at the right time. | 20 // that we started the setTargetAtTime at the right time. |
| 21 var targetValueInfo = [{ | 21 var targetValueInfo = [{ |
| 22 frame: 10.1, | 22 frame: 10.1, |
| 23 value: 0 | 23 value: 0 |
| 24 }, { | 24 }, { |
| 25 frame: 20.3, | 25 frame: 20.3, |
| 26 value: 0.5 | 26 value: 0.5 |
| 27 }, { | 27 }, { |
| 28 frame: 100.5, | 28 frame: 100.5, |
| 29 value: 1 | 29 value: 1 |
| 30 }]; | 30 }]; |
| 31 | 31 |
| 32 var audit = Audit.createTaskRunner(); | 32 var audit = Audit.createTaskRunner(); |
| 33 | 33 |
| 34 audit.defineTask("timeconstant-0", function (taskDone) { | 34 audit.define("timeconstant-0", (task, should) => { |
| 35 var context = new OfflineAudioContext(1, renderFrames, sampleRate); | 35 var context = new OfflineAudioContext(1, renderFrames, sampleRate); |
| 36 | 36 |
| 37 // Simple constant source for testing. | 37 // Simple constant source for testing. |
| 38 | 38 |
| 39 var src = new ConstantSourceNode(context); | 39 var src = new ConstantSourceNode(context); |
| 40 | 40 |
| 41 // We're going to automate the gain node to test setTargetAtTime. | 41 // We're going to automate the gain node to test setTargetAtTime. |
| 42 var gain = new GainNode(context, { | 42 var gain = new GainNode(context, { |
| 43 gain: 1 | 43 gain: 1 |
| 44 }); | 44 }); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 60 | 60 |
| 61 // Because the time constant is 0, the automation should instantly | 61 // Because the time constant is 0, the automation should instantly |
| 62 // jump to the target value at the start time. Verify that the output | 62 // jump to the target value at the start time. Verify that the output |
| 63 // has the expected value. | 63 // has the expected value. |
| 64 for (var k = 0; k < targetValueInfo.length; ++k) { | 64 for (var k = 0; k < targetValueInfo.length; ++k) { |
| 65 var startFrame = Math.ceil(targetValueInfo[k].frame); | 65 var startFrame = Math.ceil(targetValueInfo[k].frame); |
| 66 var endFrame = k < targetValueInfo.length - 1 ? | 66 var endFrame = k < targetValueInfo.length - 1 ? |
| 67 Math.ceil(targetValueInfo[k + 1].frame) : renderFrames; | 67 Math.ceil(targetValueInfo[k + 1].frame) : renderFrames; |
| 68 var value = targetValueInfo[k].value; | 68 var value = targetValueInfo[k].value; |
| 69 | 69 |
| 70 success = Should( | 70 should(result.slice(startFrame, endFrame), |
| 71 "Output for frame [" + startFrame + ", " + endFrame + | 71 "Output for frame [" + startFrame + ", " + endFrame + |
| 72 ")", | 72 ")") |
| 73 result.slice(startFrame, endFrame)) | 73 .beConstantValueOf(value); |
| 74 .beConstantValueOf(value) && success; | |
| 75 } | 74 } |
| 76 | 75 |
| 77 Should("setTargetAtTime with timeConstant=0", success) | 76 }).then(() => task.done()); |
| 78 .summarize( | |
| 79 "handled correctly", | |
| 80 "handled incorrectly"); | |
| 81 | |
| 82 }).then(taskDone); | |
| 83 }); | 77 }); |
| 84 | 78 |
| 85 audit.runTasks(); | 79 audit.run(); |
| 86 </script> | 80 </script> |
| 87 </body> | 81 </body> |
| 88 </html> | 82 </html> |
| OLD | NEW |