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