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