diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/webaudio/the-audio-api/the-periodicwave-interface | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webaudio/the-audio-api/the-periodicwave-interface')
2 files changed, 152 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-periodicwave-interface/createPeriodicWaveInfiniteValuesThrows.html b/testing/web-platform/tests/webaudio/the-audio-api/the-periodicwave-interface/createPeriodicWaveInfiniteValuesThrows.html new file mode 100644 index 0000000000..928f45bd8f --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-periodicwave-interface/createPeriodicWaveInfiniteValuesThrows.html @@ -0,0 +1,22 @@ +<!doctype html> +<meta charset=utf-8> +<title>Test AudioContext.createPeriodicWave when inputs contain Infinite values</title> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script> +let ctx; +setup(() => { + ctx = new OfflineAudioContext({length: 1, sampleRate: 24000}); +}); +test(() => { + const real = new Float32Array([0, Infinity]); + const imag = new Float32Array([0, 1]); + assert_throws_js(TypeError, () => ctx.createPeriodicWave(real, imag)); +}, "createPeriodicWave with Infinity real values should throw"); + +test(() => { + const real = new Float32Array([0, 1]); + const imag = new Float32Array([1, Infinity]); + assert_throws_js(TypeError, () => ctx.createPeriodicWave(real, imag)); +}, "createPeriodicWave with Infinity imag values should throw"); +</script> diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-periodicwave-interface/periodicWave.html b/testing/web-platform/tests/webaudio/the-audio-api/the-periodicwave-interface/periodicWave.html new file mode 100644 index 0000000000..fe42f8ad50 --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-periodicwave-interface/periodicWave.html @@ -0,0 +1,130 @@ +<!DOCTYPE html> +<html> + <head> + <title> + Test Constructor: PeriodicWave + </title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/webaudio/resources/audit-util.js"></script> + <script src="/webaudio/resources/audit.js"></script> + </head> + <body> + <script id="layout-test-code"> + // real and imag are used in separate PeriodicWaves to make their peak values + // easy to determine. + const realMax = 99; + var real = new Float32Array(realMax + 1); + real[1] = 2.0; // fundamental + real[realMax] = 3.0; + const realPeak = real[1] + real[realMax]; + const realFundamental = 19.0; + var imag = new Float32Array(4); + imag[0] = 6.0; // should be ignored. + imag[3] = 0.5; + const imagPeak = imag[3]; + const imagFundamental = 551.0; + + const testLength = 8192; + let context = new AudioContext(); + + let audit = Audit.createTaskRunner(); + + // Create with the factory method + + audit.define('create with factory method', (task, should) => { + should(() => { + context.createPeriodicWave(new Float32Array(testLength), new Float32Array(testLength)); + }, 'context.createPeriodicWave(new Float32Array(' + testLength + '), ' + + 'new Float32Array(' + testLength + '))').notThrow(); + task.done(); + }); + + audit.define('different length with factory method', (task, should) => { + should(() => { + context.createPeriodicWave(new Float32Array(512), new Float32Array(4)); + }, 'context.createPeriodicWave(new Float32Array(512), ' + + 'new Float32Array(4))').throw(DOMException, "IndexSizeError"); + task.done(); + }); + + audit.define('too small with factory method', (task, should) => { + should(() => { + context.createPeriodicWave(new Float32Array(1), new Float32Array(1)); + }, 'context.createPeriodicWave(new Float32Array(1), ' + + 'new Float32Array(1))').throw(DOMException, "IndexSizeError"); + task.done(); + }); + + // Create with the constructor + + audit.define('create with constructor', (task, should) => { + should(() => { + new PeriodicWave(context, { real: new Float32Array(testLength), imag: new Float32Array(testLength) }); + }, 'new PeriodicWave(context, { real : new Float32Array(' + testLength + '), ' + + 'imag : new Float32Array(' + testLength + ') })').notThrow(); + task.done(); + }); + + audit.define('different length with constructor', (task, should) => { + should(() => { + new PeriodicWave(context, { real: new Float32Array(testLength), imag: new Float32Array(4) }); + }, 'new PeriodicWave(context, { real : new Float32Array(' + testLength + '), ' + + 'imag : new Float32Array(4) })').throw(DOMException, "IndexSizeError"); + task.done(); + }); + + audit.define('too small with constructor', (task, should) => { + should(() => { + new PeriodicWave(context, { real: new Float32Array(1), imag: new Float32Array(1) }); + }, 'new PeriodicWave(context, { real : new Float32Array(1), ' + + 'imag : new Float32Array(1) })').throw(DOMException, "IndexSizeError"); + task.done(); + }); + + audit.define('output test', (task, should) => { + let context = new OfflineAudioContext(2, testLength, 44100); + // Create the expected output buffer + let expectations = context.createBuffer(2, testLength, context.sampleRate); + for (var i = 0; i < expectations.length; ++i) { + + expectations.getChannelData(0)[i] = 1.0 / realPeak * + (real[1] * Math.cos(2 * Math.PI * realFundamental * i / + context.sampleRate) + + real[realMax] * Math.cos(2 * Math.PI * realMax * realFundamental * i / + context.sampleRate)); + + expectations.getChannelData(1)[i] = 1.0 / imagPeak * + imag[3] * Math.sin(2 * Math.PI * 3 * imagFundamental * i / + context.sampleRate); + } + + // Create the real output buffer + let merger = context.createChannelMerger(); + + let osc1 = context.createOscillator(); + let osc2 = context.createOscillator(); + + osc1.setPeriodicWave(context.createPeriodicWave( + real, new Float32Array(real.length))); + osc2.setPeriodicWave(context.createPeriodicWave( + new Float32Array(imag.length), imag)); + osc1.frequency.value = realFundamental; + osc2.frequency.value = imagFundamental; + + osc1.start(); + osc2.start(); + + osc1.connect(merger, 0, 0); + osc2.connect(merger, 0, 1); + + context.startRendering().then(reality => { + should(reality, 'rendering PeriodicWave').beEqualToArray(expectations); + task.done(); + }); + }); + + audit.run(); + </script> + </body> +</html> |