OLD | NEW |
1 <!doctype html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
| 4 <title> |
| 5 Test setValueCurveAtTime Copies the Curve Data |
| 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/panner-formulas.js"></script> | 11 <script src="../resources/panner-formulas.js"></script> |
9 <title>Test setValueCurveAtTime Copies the Curve Data</title> | |
10 </head> | 12 </head> |
| 13 <body> |
| 14 <script id="layout-test-code"> |
| 15 let sampleRate = 48000; |
| 16 let renderFrames = 1024; |
| 17 let renderDuration = renderFrames / sampleRate; |
11 | 18 |
12 <body> | 19 let audit = Audit.createTaskRunner(); |
13 <script> | |
14 | |
15 var sampleRate = 48000; | |
16 var renderFrames = 1024; | |
17 var renderDuration = renderFrames / sampleRate; | |
18 | |
19 var audit = Audit.createTaskRunner(); | |
20 | 20 |
21 // Test that changing the curve array to setValueCurveAtTime doesn't | 21 // Test that changing the curve array to setValueCurveAtTime doesn't |
22 // change the automation output. | 22 // change the automation output. |
23 audit.define("test-copy", (task, should) => { | 23 audit.define('test-copy', (task, should) => { |
24 // Two-channel context; channel 0 is the test result, and channel 1 is | 24 // Two-channel context; channel 0 is the test result, and channel 1 is |
25 // the expected result. | 25 // the expected result. |
26 var context = new OfflineAudioContext(2, renderFrames, sampleRate); | 26 let context = new OfflineAudioContext(2, renderFrames, sampleRate); |
27 | 27 |
28 var source = context.createBufferSource(); | 28 let source = context.createBufferSource(); |
29 source.buffer = createConstantBuffer(context, 1, 1); | 29 source.buffer = createConstantBuffer(context, 1, 1); |
30 source.loop = true; | 30 source.loop = true; |
31 | 31 |
32 // Create two gain nodes. gainRef is the reference with the expected | 32 // Create two gain nodes. gainRef is the reference with the expected |
33 // automation results. gainTest is the test which will have the curve | 33 // automation results. gainTest is the test which will have the curve |
34 // modified. | 34 // modified. |
35 var gainTest = context.createGain(); | 35 let gainTest = context.createGain(); |
36 var gainRef = context.createGain(); | 36 let gainRef = context.createGain(); |
37 | 37 |
38 var merger = context.createChannelMerger(2); | 38 let merger = context.createChannelMerger(2); |
39 | 39 |
40 // The actual curve data can be anything, but we use this for | 40 // The actual curve data can be anything, but we use this for |
41 // simplicity. | 41 // simplicity. |
42 var curveData = [1, 0]; | 42 let curveData = [1, 0]; |
43 var curveRef = Float32Array.from(curveData); | 43 let curveRef = Float32Array.from(curveData); |
44 var curveTest = Float32Array.from(curveData); | 44 let curveTest = Float32Array.from(curveData); |
45 | 45 |
46 // Create the graph. | 46 // Create the graph. |
47 source.connect(gainTest); | 47 source.connect(gainTest); |
48 source.connect(gainRef); | 48 source.connect(gainRef); |
49 gainTest.connect(merger, 0, 0); | 49 gainTest.connect(merger, 0, 0); |
50 gainRef.connect(merger, 0, 1); | 50 gainRef.connect(merger, 0, 1); |
51 merger.connect(context.destination); | 51 merger.connect(context.destination); |
52 | 52 |
53 // Initialize the gains. | 53 // Initialize the gains. |
54 gainTest.gain.setValueAtTime(0, 0); | 54 gainTest.gain.setValueAtTime(0, 0); |
55 gainRef.gain.setValueAtTime(0, 0); | 55 gainRef.gain.setValueAtTime(0, 0); |
56 | 56 |
57 // Set up the value curve. At this point curveTest and curveRef are the | 57 // Set up the value curve. At this point curveTest and curveRef are the |
58 // same. | 58 // same. |
59 gainTest.gain.setValueCurveAtTime(curveTest, 0, renderDuration); | 59 gainTest.gain.setValueCurveAtTime(curveTest, 0, renderDuration); |
60 gainRef.gain.setValueCurveAtTime(curveRef, 0, renderDuration); | 60 gainRef.gain.setValueCurveAtTime(curveRef, 0, renderDuration); |
61 | 61 |
62 // After rendering has started, modify curveTest. | 62 // After rendering has started, modify curveTest. |
63 context.suspend(128 / sampleRate).then(function () { | 63 context.suspend(128 / sampleRate) |
64 // Change the values of curve now. Any transformation is ok as long | 64 .then(function() { |
65 // as curveTest changes. We do this to make it really obvious. | 65 // Change the values of curve now. Any transformation is ok as |
66 for (var k = 0; k < curveTest.length; ++k) | 66 // long as curveTest changes. We do this to make it really |
67 curveTest[k] = 100 * curveTest[k] + 1; | 67 // obvious. |
68 }).then(context.resume.bind(context)); | 68 for (let k = 0; k < curveTest.length; ++k) |
| 69 curveTest[k] = 100 * curveTest[k] + 1; |
| 70 }) |
| 71 .then(context.resume.bind(context)); |
69 | 72 |
70 // Start the test! | 73 // Start the test! |
71 source.start(); | 74 source.start(); |
72 | 75 |
73 context.startRendering().then(function (resultBuffer) { | 76 context.startRendering() |
74 var testData = resultBuffer.getChannelData(0); | 77 .then(function(resultBuffer) { |
75 var refData = resultBuffer.getChannelData(1); | 78 let testData = resultBuffer.getChannelData(0); |
| 79 let refData = resultBuffer.getChannelData(1); |
76 | 80 |
77 // The test result and the reference should be identical since | 81 // The test result and the reference should be identical since |
78 // changing the curve data should not affect the automation. | 82 // changing the curve data should not affect the automation. |
79 should(testData, "setValueCurve output").beEqualToArray(refData); | 83 should(testData, 'setValueCurve output').beEqualToArray(refData); |
80 }).then(() => task.done()); | 84 }) |
| 85 .then(() => task.done()); |
81 }); | 86 }); |
82 | 87 |
83 audit.run(); | 88 audit.run(); |
84 </script> | 89 </script> |
85 </body> | 90 </body> |
86 </html> | 91 </html> |
OLD | NEW |