blob: a09afeab9dc6c4e18c7cb3e0f47a743aa445c418 [file] [log] [blame]
<!doctype html>
<html>
<head>
<script src="../resources/js-test.js"></script>
<script src="resources/compatibility.js"></script>
<script src="resources/audio-testing.js"></script>
<script src="resources/panner-formulas.js"></script>
<title>Test setValueCurveAtTime Copies the Curve Data</title>
</head>
<body>
<script>
description("Test setValueCurveAtTime Copies the Curve Data");
window.jsTestIsAsync = true;
var sampleRate = 48000;
var renderFrames = 1024;
var renderDuration = renderFrames / sampleRate;
var audit = Audit.createTaskRunner();
// Test that changing the curve array to setValueCurveAtTime doesn't
// change the automation output.
audit.defineTask("test-copy", function (done) {
// Two-channel context; channel 0 is the test result, and channel 1 is
// the expected result.
var context = new OfflineAudioContext(2, renderFrames, sampleRate);
var source = context.createBufferSource();
source.buffer = createConstantBuffer(context, 1, 1);
source.loop = true;
// Create two gain nodes. gainRef is the reference with the expected
// automation results. gainTest is the test which will have the curve
// modified.
var gainTest = context.createGain();
var gainRef = context.createGain();
var merger = context.createChannelMerger(2);
// The actual curve data can be anything, but we use this for
// simplicity.
var curveData = [1, 0];
var curveRef = Float32Array.from(curveData);
var curveTest = Float32Array.from(curveData);
// Create the graph.
source.connect(gainTest);
source.connect(gainRef);
gainTest.connect(merger, 0, 0);
gainRef.connect(merger, 0, 1);
merger.connect(context.destination);
// Initialize the gains.
gainTest.gain.setValueAtTime(0, 0);
gainRef.gain.setValueAtTime(0, 0);
// Set up the value curve. At this point curveTest and curveRef are the
// same.
gainTest.gain.setValueCurveAtTime(curveTest, 0, renderDuration);
gainRef.gain.setValueCurveAtTime(curveRef, 0, renderDuration);
// After rendering has started, modify curveTest.
context.suspend(128 / sampleRate).then(function () {
// Change the values of curve now. Any transformation is ok as long
// as curveTest changes. We do this to make it really obvious.
for (var k = 0; k < curveTest.length; ++k)
curveTest[k] = 100 * curveTest[k] + 1;
}).then(context.resume.bind(context));
// Start the test!
source.start();
context.startRendering().then(function (resultBuffer) {
var testData = resultBuffer.getChannelData(0);
var refData = resultBuffer.getChannelData(1);
// The test result and the reference should be identical since
// changing the curve data should not affect the automation.
var success = Should("setValueCurve output", testData).beEqualToArray(refData);
if (success)
testPassed("Changing the curve data did not change the result.");
else
testFailed("Changing the curve data unexpectedly changed the result.");
}).then(done);
});
audit.defineTask("finish", function (done) {
finishJSTest();
done();
});
audit.runTasks();
</script>
</body>
</html>