<!DOCTYPE html>
<html>
<head>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../resources/audit-util.js"></script>
</head>
<body>
<script>
const sampleRate = 48000;
const renderLength = 2048;
// Test k-rate AudioBufferSourceNode AudioParams.
promise_test(async (t) => {
const context = new OfflineAudioContext(1, renderLength, sampleRate);
const buffer = createConstantBuffer(context, renderLength, 1);
const node = new AudioBufferSourceNode(context, {buffer: buffer});
node.connect(context.destination);
// Initialize detune and playbackRate to some non-zero value (because
// we're using exponential ramps. Then add exponential ramp to some
// non-zero end value. The actual values don't matter as long as
// they're strictly positive.
node.detune.setValueAtTime(0.125, 0);
node.playbackRate.setValueAtTime(1, 0);
node.detune.exponentialRampToValueAtTime(0.75, 0.015);
node.playbackRate.exponentialRampToValueAtTime(0.5, 0.015);
node.start();
await context.startRendering();
// The final values for each attribute should be the expected final
// value.
assert_equals(node.detune.value, 0.75);
assert_equals(node.playbackRate.value, 0.5);
}, 'Test k-rate AudioBufferSourceNode AudioParams');
// Test k-rate PannerNode and AudioListenerNode AudioParams.
promise_test(async (t) => {
const context = new OfflineAudioContext(1, renderLength, sampleRate);
const buffer = createConstantBuffer(context, renderLength, 1);
const source = new AudioBufferSourceNode(context, {buffer: buffer});
const panner = new PannerNode(context, {panningModel: 'HRTF'});
source.connect(panner).connect(context.destination);
// Initialize the k-rate parameters to some positive value. Then add
// exponential ramp to some non-zero end value. The actual values don't
// matter as long as they're strictly positive.
panner.orientationX.setValueAtTime(1, 0);
panner.orientationY.setValueAtTime(1, 0);
panner.orientationZ.setValueAtTime(1, 0);
panner.positionX.setValueAtTime(5, 0);
panner.positionY.setValueAtTime(5, 0);
panner.positionZ.setValueAtTime(5, 0);
context.listener.forwardX.setValueAtTime(1, 0);
context.listener.forwardY.setValueAtTime(1, 0);
context.listener.forwardZ.setValueAtTime(1, 0);
context.listener.positionX.setValueAtTime(.5, 0);
context.listener.positionY.setValueAtTime(.5, 0);
context.listener.positionZ.setValueAtTime(.5, 0);
context.listener.upX.setValueAtTime(1, 0);
context.listener.upY.setValueAtTime(1, 0);
context.listener.upZ.setValueAtTime(1, 0);
panner.orientationX.exponentialRampToValueAtTime(2.5, 0.015);
panner.orientationY.exponentialRampToValueAtTime(2.5, 0.015);
panner.orientationZ.exponentialRampToValueAtTime(2.5, 0.015);
panner.positionX.exponentialRampToValueAtTime(11, 0.015);
panner.positionY.exponentialRampToValueAtTime(11, 0.015);
panner.positionZ.exponentialRampToValueAtTime(11, 0.015);
context.listener.forwardX.exponentialRampToValueAtTime(3, 0.015);
context.listener.forwardY.exponentialRampToValueAtTime(3, 0.015);
context.listener.forwardZ.exponentialRampToValueAtTime(3, 0.015);
context.listener.positionX.exponentialRampToValueAtTime(0.5, 0.015);
context.listener.positionY.exponentialRampToValueAtTime(0.5, 0.015);
context.listener.positionZ.exponentialRampToValueAtTime(0.5, 0.015);
context.listener.upX.exponentialRampToValueAtTime(4, 0.015);
context.listener.upY.exponentialRampToValueAtTime(4, 0.015);
context.listener.upZ.exponentialRampToValueAtTime(4, 0.015);
source.start();
await context.startRendering();
assert_equals(panner.orientationX.value, 2.5);
assert_equals(panner.orientationY.value, 2.5);
assert_equals(panner.orientationZ.value, 2.5);
assert_equals(panner.positionX.value, 11);
assert_equals(panner.positionY.value, 11);
assert_equals(panner.positionZ.value, 11);
assert_equals(context.listener.forwardX.value, 3);
assert_equals(context.listener.forwardY.value, 3);
assert_equals(context.listener.forwardZ.value, 3);
assert_equals(context.listener.positionX.value, 0.5);
assert_equals(context.listener.positionY.value, 0.5);
assert_equals(context.listener.positionZ.value, 0.5);
assert_equals(context.listener.upX.value, 4);
assert_equals(context.listener.upY.value, 4);
assert_equals(context.listener.upZ.value, 4);
}, 'Test k-rate PannerNode and AudioListenerNode AudioParams');
</script>
</body>
</html>