diff options
Diffstat (limited to 'testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface')
4 files changed, 173 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/.gitkeep b/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/.gitkeep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/.gitkeep diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/retrospective-setValueAtTime.html b/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/retrospective-setValueAtTime.html new file mode 100644 index 000000000..dde8c27b9 --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/retrospective-setValueAtTime.html @@ -0,0 +1,71 @@ +<!DOCTYPE html> +<title>Test setValueAtTime with startTime in the past</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +function do_test(t, context) { + var source = context.createBufferSource(); + source.buffer = + function() { + var buffer = context.createBuffer(1, 1, context.sampleRate); + buffer.getChannelData(0)[0] = 1.0; + return buffer; + }(); + source.loop = true; + source.start(); + + // Use a ramp of slope 1/sample to measure time. + // The end value is the extent of exact precision in single precision float. + const rampEnd = Math.pow(2, 24); + const rampEndSeconds = rampEnd / context.sampleRate; + var test = context.createGain(); + test.gain.setValueAtTime(0.0, 0.0); + test.gain.linearRampToValueAtTime(rampEnd, rampEndSeconds); + + // With a different starting point on the same line, the result should be + // the same. |currentTime| may include double precision floating point + // rounding errors, so round to nearest integer sample to ignore these. + var scheduledSample = Math.round(context.currentTime * context.sampleRate); + assert_equals(scheduledSample % 128, 0, + "currentTime advances in blocks of 128 samples"); + var reference = context.createGain(); + reference.gain.setValueAtTime(scheduledSample, context.currentTime); + reference.gain.linearRampToValueAtTime(rampEnd, rampEndSeconds); + + source.connect(test); + source.connect(reference); + + var merger = context.createChannelMerger(); + test.connect(merger, 0, 0); + reference.connect(merger, 0, 1); + + var processor = context.createScriptProcessor(0, 2, 0); + merger.connect(processor); + processor.onaudioprocess = + t.step_func_done((e) => { + source.stop(); + processor.onaudioprocess = null; + + var testValue = e.inputBuffer.getChannelData(0)[0]; + var referenceValue = e.inputBuffer.getChannelData(1)[0]; + + assert_equals(testValue, referenceValue, + "ramp value matches expected"); + assert_greater_than_equal(testValue, scheduledSample, + "time does not retreat"); + assert_equals(testValue % 128, 0, + "ScriptProcessor blocks align on 128-sample blocks"); + }); +} + +async_test(function(t) { + var context = new AudioContext; + (function waitForTimeAdvance() { + if (context.currentTime == 0) { + t.step_timeout(waitForTimeAdvance, 0); + } else { + do_test(t, context); + } + })(); +}); +</script> diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/setTargetAtTime-after-event-within-block.html b/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/setTargetAtTime-after-event-within-block.html new file mode 100644 index 000000000..827aeeabd --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/setTargetAtTime-after-event-within-block.html @@ -0,0 +1,54 @@ +<!DOCTYPE html> +<title>Test setTargetAtTime after an event in the same processing block</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +promise_test(function() { + const bufferSize = 179; + const valueStartOffset = 42; + const targetStartOffset = 53; + const sampleRate = 48000; + const scheduledValue = -0.5; + + var context = new OfflineAudioContext(1, bufferSize, sampleRate); + + var gain = context.createGain(); + gain.gain.setValueAtTime(scheduledValue, valueStartOffset/sampleRate); + gain.gain.setTargetAtTime(scheduledValue, targetStartOffset/sampleRate, + 128/sampleRate); + gain.connect(context.destination); + + // Apply unit DC signal to gain node. + var source = context.createBufferSource(); + source.buffer = + function() { + var buffer = context.createBuffer(1, 1, context.sampleRate); + buffer.getChannelData(0)[0] = 1.0; + return buffer; + }(); + source.loop = true; + source.start(); + source.connect(gain); + + return context.startRendering(). + then(function(buffer) { + assert_equals(buffer.length, bufferSize, "output buffer length"); + var output = buffer.getChannelData(0); + var i = 0; + for (; i < valueStartOffset; ++i) { + // "Its default value is 1." + assert_equals(output[i], 1.0, "default gain at sample " + i); + } + for (; i < buffer.length; ++i) { + // "If the next event (having time T1) after this SetValue event is + // not of type LinearRampToValue or ExponentialRampToValue, then, for + // T0≤t<T1: v(t)=V". + // "Start exponentially approaching the target value at the given time + // with a rate having the given time constant." + // The target is the same value, and so the SetValue value continues. + assert_equals(output[i], scheduledValue, + "scheduled value at sample " + i); + } + }); +}); +</script> diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/setValueAtTime-within-block.html b/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/setValueAtTime-within-block.html new file mode 100644 index 000000000..36fde2b99 --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/setValueAtTime-within-block.html @@ -0,0 +1,48 @@ +<!DOCTYPE html> +<title>Test setValueAtTime with start time not on a block boundary</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +promise_test(function() { + const bufferSize = 200; + const offset = 65; + const sampleRate = 48000; + const scheduledValue = -2.0; + + var context = new OfflineAudioContext(1, bufferSize, sampleRate); + + var gain = context.createGain(); + gain.gain.setValueAtTime(scheduledValue, offset/sampleRate); + gain.connect(context.destination); + + // Apply unit DC signal to gain node. + var source = context.createBufferSource(); + source.buffer = + function() { + var buffer = context.createBuffer(1, 1, context.sampleRate); + buffer.getChannelData(0)[0] = 1.0; + return buffer; + }(); + source.loop = true; + source.start(); + source.connect(gain); + + return context.startRendering(). + then(function(buffer) { + assert_equals(buffer.length, bufferSize, "output buffer length"); + var output = buffer.getChannelData(0); + var i = 0; + for (; i < offset; ++i) { + // "Its default value is 1." + assert_equals(output[i], 1.0, "default gain at sample " + i); + } + for (; i < buffer.length; ++i) { + // "If there are no more events after this SetValue event, then for + // t≥T0, v(t)=V, where T0 is the startTime parameter and V is the + // value parameter." + assert_equals(output[i], scheduledValue, + "scheduled value at sample " + i); + } + }); +}); +</script> |