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-channelmergernode-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-channelmergernode-interface')
6 files changed, 546 insertions, 0 deletions
diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/active-processing.https.html b/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/active-processing.https.html new file mode 100644 index 0000000000..9012526bdc --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/active-processing.https.html @@ -0,0 +1,93 @@ +<!doctype html> +<html> + <head> + <title> + Test Active Processing for ChannelMergerNode + </title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> + <script src="/webaudio/resources/audit.js"></script> + </head> + + <body> + <script id="layout-test-code"> + // AudioProcessor that sends a message to its AudioWorkletNode whenver the + // number of channels on its input changes. + let filePath = + '../the-audioworklet-interface/processors/active-processing.js'; + + const audit = Audit.createTaskRunner(); + + let context; + + audit.define('initialize', (task, should) => { + // Create context and load the module + context = new AudioContext(); + should( + context.audioWorklet.addModule(filePath), + 'AudioWorklet module loading') + .beResolved() + .then(() => task.done()); + }); + + audit.define('test', (task, should) => { + const src = new OscillatorNode(context); + + // Number of inputs for the ChannelMergerNode. Pretty arbitrary, but + // should not be 1. + const numberOfInputs = 7; + const merger = + new ChannelMergerNode(context, {numberOfInputs: numberOfInputs}); + + const testerNode = + new AudioWorkletNode(context, 'active-processing-tester', { + // Use as short a duration as possible to keep the test from + // taking too much time. + processorOptions: {testDuration: .5}, + }); + + // Expected number of output channels from the merger node. We should + // start with the number of inputs, because the source (oscillator) is + // actively processing. When the source stops, the number of channels + // should change to 0. + const expectedValues = [numberOfInputs, 0]; + let index = 0; + + testerNode.port.onmessage = event => { + let count = event.data.channelCount; + let finished = event.data.finished; + + // If we're finished, end testing. + if (finished) { + // Verify that we got the expected number of changes. + should(index, 'Number of distinct values') + .beEqualTo(expectedValues.length); + + task.done(); + return; + } + + if (index < expectedValues.length) { + // Verify that the number of channels matches the expected number of + // channels. + should(count, `Test ${index}: Number of convolver output channels`) + .beEqualTo(expectedValues[index]); + } + + ++index; + }; + + // Create the graph and go + src.connect(merger).connect(testerNode).connect(context.destination); + src.start(); + + // Stop the source after a short time so we can test that the channel + // merger changes to not actively processing and thus produces a single + // channel of silence. + src.stop(context.currentTime + .1); + }); + + audit.run(); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-basic.html b/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-basic.html new file mode 100644 index 0000000000..71a62f176f --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-basic.html @@ -0,0 +1,67 @@ +<!DOCTYPE html> +<html> + <head> + <title> + audiochannelmerger-basic.html + </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"> + let audit = Audit.createTaskRunner(); + + // Task: Checking constraints in ChannelMergerNode. + audit.define('exceptions-channels', (task, should) => { + let context = new OfflineAudioContext(2, 128, 44100); + let merger; + + should(function() { + merger = context.createChannelMerger(); + }, 'context.createChannelMerger()').notThrow(); + + should(function() { + merger = context.createChannelMerger(0); + }, 'context.createChannelMerger(0)').throw(DOMException, 'IndexSizeError'); + + should(function() { + merger = context.createChannelMerger(32); + }, 'context.createChannelMerger(32)').notThrow(); + + // Can't create a channel merger with 33 channels because the audio + // context has a 32-channel-limit in Chrome. + should(function() { + merger = context.createChannelMerger(33); + }, 'context.createChannelMerger(33)').throw(DOMException, 'IndexSizeError'); + + task.done(); + }); + + // Task: checking the channel-related properties have the correct value + // and can't be changed. + audit.define('exceptions-properties', (task, should) => { + let context = new OfflineAudioContext(2, 128, 44100); + let merger = context.createChannelMerger(); + + should(merger.channelCount, 'merger.channelCount').beEqualTo(1); + + should(function() { + merger.channelCount = 3; + }, 'merger.channelCount = 3').throw(DOMException, 'InvalidStateError'); + + should(merger.channelCountMode, 'merger.channelCountMode') + .beEqualTo('explicit'); + + should(function() { + merger.channelCountMode = 'max'; + }, 'merger.channelCountMode = "max"').throw(DOMException, 'InvalidStateError'); + + task.done(); + }); + + audit.run(); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-disconnect.html b/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-disconnect.html new file mode 100644 index 0000000000..ad74d5e004 --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-disconnect.html @@ -0,0 +1,82 @@ +<!DOCTYPE html> +<html> + <head> + <title> + audiochannelmerger-disconnect.html + </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"> + let renderQuantum = 128; + + let numberOfChannels = 2; + let sampleRate = 44100; + let renderDuration = 0.5; + let disconnectTime = 0.5 * renderDuration; + + let audit = Audit.createTaskRunner(); + + // Task: Check if the merger outputs a silent channel when an input is + // disconnected. + audit.define('silent-disconnect', (task, should) => { + let context = new OfflineAudioContext( + numberOfChannels, renderDuration * sampleRate, sampleRate); + let merger = context.createChannelMerger(); + let source1 = context.createBufferSource(); + let source2 = context.createBufferSource(); + + // Create and assign a constant buffer. + let bufferDCOffset = createConstantBuffer(context, 1, 1); + source1.buffer = source2.buffer = bufferDCOffset; + source1.loop = source2.loop = true; + + // Connect the output of source into the 4th input of merger. The merger + // should produce 6 channel output. + source1.connect(merger, 0, 0); + source2.connect(merger, 0, 1); + merger.connect(context.destination); + source1.start(); + source2.start(); + + // Schedule the disconnection of |source2| at the half of render + // duration. + context.suspend(disconnectTime).then(function() { + source2.disconnect(); + context.resume(); + }); + + context.startRendering() + .then(function(buffer) { + // The entire first channel of the output should be 1. + should(buffer.getChannelData(0), 'Channel #0') + .beConstantValueOf(1); + + // Calculate the first zero index in the second channel. + let channel1 = buffer.getChannelData(1); + let disconnectIndex = disconnectTime * sampleRate; + disconnectIndex = renderQuantum * + Math.floor( + (disconnectIndex + renderQuantum - 1) / renderQuantum); + let firstZeroIndex = channel1.findIndex(function(element, index) { + if (element === 0) + return index; + }); + + // The second channel should contain 1, and 0 after the + // disconnection. + should(channel1, 'Channel #1').containValues([1, 0]); + should( + firstZeroIndex, 'The index of first zero in the channel #1') + .beEqualTo(disconnectIndex); + }) + .then(() => task.done()); + }); + + audit.run(); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-input-non-default.html b/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-input-non-default.html new file mode 100644 index 0000000000..6fe77ab763 --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-input-non-default.html @@ -0,0 +1,79 @@ +<!DOCTYPE html> +<html> + <head> + <title> + audiochannelmerger-input-non-default.html + </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> + <script src="/webaudio/resources/merger-testing.js"></script> + </head> + <body> + <script id="layout-test-code"> + let audit = Audit.createTaskRunner(); + + + // Task: Check if an inactive input renders a silent mono channel in the + // output. + audit.define('silent-channel', (task, should) => { + testMergerInput(should, { + numberOfChannels: 7, + + // Create a mono source buffer filled with '1'. + testBufferContent: [1], + + // Connect the output of source into the 7th input of merger. + mergerInputIndex: 6, + + // 7th channel should be '1'. + expected: [0, 0, 0, 0, 0, 0, 1], + }).then(() => task.done()); + }); + + + // Task: Check if a stereo input is being down-mixed to mono channel + // correctly based on the mixing rule. + audit.define('stereo-down-mixing', (task, should) => { + testMergerInput(should, { + numberOfChannels: 7, + + // Create a stereo buffer filled with '1' and '2' for left and right + // channels respectively. + testBufferContent: [1, 2], + + // Connect the output of source into the 7th input of merger. + mergerInputIndex: 6, + + // The result of summed and down-mixed stereo audio should be 1.5. + // (= 1 * 0.5 + 2 * 0.5) + expected: [0, 0, 0, 0, 0, 0, 1.5], + }).then(() => task.done()); + }); + + + // Task: Check if 3-channel input gets processed by the 'discrete' mixing + // rule. + audit.define('undefined-channel-layout', (task, should) => { + testMergerInput(should, { + numberOfChannels: 7, + + // Create a 3-channel buffer filled with '1', '2', and '3' + // respectively. + testBufferContent: [1, 2, 3], + + // Connect the output of source into the 7th input of merger. + mergerInputIndex: 6, + + // The result of summed stereo audio should be 1 because 3-channel is + // not a canonical layout, so the input channel 2 and 3 should be + // dropped by 'discrete' mixing rule. + expected: [0, 0, 0, 0, 0, 0, 1], + }).then(() => task.done()); + }); + + audit.run(); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-input.html b/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-input.html new file mode 100644 index 0000000000..66a70dcb3b --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-input.html @@ -0,0 +1,113 @@ +<!DOCTYPE html> +<html> + <head> + <title> + audiochannelmerger-input.html + </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> + <script src="/webaudio/resources/merger-testing.js"></script> + </head> + <body> + <script id="layout-test-code"> + let audit = Audit.createTaskRunner(); + + // Task: Check if an inactive input renders a silent mono channel in the + // output. + audit.define('silent-channel', (task, should) => { + testMergerInput(should, { + numberOfChannels: 6, + + // Create a mono source buffer filled with '1'. + testBufferContent: [1], + + // Connect the output of source into the 4th input of merger. + mergerInputIndex: 3, + + // All channels should contain 0, except channel 4 which should be 1. + expected: [0, 0, 0, 1, 0, 0], + }).then(() => task.done()); + }); + + + // Task: Check if a stereo input is being down-mixed to mono channel + // correctly based on the mixing rule. + audit.define('stereo-down-mixing', (task, should) => { + testMergerInput(should, { + numberOfChannels: 6, + + // Create a stereo buffer filled with '1' and '2' for left and right + // channels respectively. + testBufferContent: [1, 2], + + // Connect the output of source into the 1st input of merger. + mergerInputIndex: undefined, + + // The result of summed and down-mixed stereo audio should be 1.5. + // (= 1 * 0.5 + 2 * 0.5) + expected: [1.5, 0, 0, 0, 0, 0], + }).then(() => task.done()); + }); + + + // Task: Check if 3-channel input gets processed by the 'discrete' mixing + // rule. + audit.define('undefined-channel-layout', (task, should) => { + testMergerInput(should, { + numberOfChannels: 6, + + // Create a 3-channel buffer filled with '1', '2', and '3' + // respectively. + testBufferContent: [1, 2, 3], + + // Connect the output of source into the 1st input of merger. + mergerInputIndex: undefined, + + // The result of summed stereo audio should be 1 because 3-channel is + // not a canonical layout, so the input channel 2 and 3 should be + // dropped by 'discrete' mixing rule. + expected: [1, 0, 0, 0, 0, 0], + }).then(() => task.done()); + }); + + + // Task: Merging two inputs into a single stereo stream. + audit.define('merging-to-stereo', (task, should) => { + + // For this test, the number of channel should be 2. + let context = new OfflineAudioContext(2, 128, 44100); + let merger = context.createChannelMerger(); + let source1 = context.createBufferSource(); + let source2 = context.createBufferSource(); + + // Create a DC offset buffer (mono) filled with 1 and assign it to BS + // nodes. + let positiveDCOffset = createConstantBuffer(context, 128, 1); + let negativeDCOffset = createConstantBuffer(context, 128, -1); + source1.buffer = positiveDCOffset; + source2.buffer = negativeDCOffset; + + // Connect: BS#1 => merger_input#0, BS#2 => Inverter => merger_input#1 + source1.connect(merger, 0, 0); + source2.connect(merger, 0, 1); + merger.connect(context.destination); + source1.start(); + source2.start(); + + context.startRendering().then(function(buffer) { + + // Channel#0 = 1, Channel#1 = -1 + should(buffer.getChannelData(0), 'Channel #0').beConstantValueOf(1); + should(buffer.getChannelData(1), 'Channel #1').beConstantValueOf(-1); + + task.done(); + }); + }); + + + audit.run(); + </script> + </body> +</html> diff --git a/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/ctor-channelmerger.html b/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/ctor-channelmerger.html new file mode 100644 index 0000000000..0d6b45c56d --- /dev/null +++ b/testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/ctor-channelmerger.html @@ -0,0 +1,112 @@ +<!DOCTYPE html> +<html> + <head> + <title> + Test Constructor: ChannelMerger + </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> + <script src="/webaudio/resources/audionodeoptions.js"></script> + </head> + <body> + <script id="layout-test-code"> + let context; + + let audit = Audit.createTaskRunner(); + + audit.define('initialize', (task, should) => { + context = initializeContext(should); + task.done(); + }); + + audit.define('invalid constructor', (task, should) => { + testInvalidConstructor(should, 'ChannelMergerNode', context); + task.done(); + }); + + audit.define('default constructor', (task, should) => { + let prefix = 'node0'; + let node = + testDefaultConstructor(should, 'ChannelMergerNode', context, { + prefix: prefix, + numberOfInputs: 6, + numberOfOutputs: 1, + channelCount: 1, + channelCountMode: 'explicit', + channelInterpretation: 'speakers' + }); + + task.done(); + }); + + audit.define('test AudioNodeOptions', (task, should) => { + testAudioNodeOptions(should, context, 'ChannelMergerNode', { + channelCount: { + value: 1, + isFixed: true, + exceptionType: 'InvalidStateError' + }, + channelCountMode: { + value: 'explicit', + isFixed: true, + exceptionType: 'InvalidStateError' + } + }); + task.done(); + }); + + audit.define('constructor options', (task, should) => { + let node; + let options = { + numberOfInputs: 3, + numberOfOutputs: 9, + channelInterpretation: 'discrete' + }; + + should( + () => { + node = new ChannelMergerNode(context, options); + }, + 'node1 = new ChannelMergerNode(context, ' + + JSON.stringify(options) + ')') + .notThrow(); + + should(node.numberOfInputs, 'node1.numberOfInputs') + .beEqualTo(options.numberOfInputs); + should(node.numberOfOutputs, 'node1.numberOfOutputs').beEqualTo(1); + should(node.channelInterpretation, 'node1.channelInterpretation') + .beEqualTo(options.channelInterpretation); + + options = {numberOfInputs: 99}; + should( + () => { + node = new ChannelMergerNode(context, options); + }, + 'new ChannelMergerNode(c, ' + JSON.stringify(options) + ')') + .throw(DOMException, 'IndexSizeError'); + + options = {channelCount: 3}; + should( + () => { + node = new ChannelMergerNode(context, options); + }, + 'new ChannelMergerNode(c, ' + JSON.stringify(options) + ')') + .throw(DOMException, 'InvalidStateError'); + + options = {channelCountMode: 'max'}; + should( + () => { + node = new ChannelMergerNode(context, options); + }, + 'new ChannelMergerNode(c, ' + JSON.stringify(options) + ')') + .throw(DOMException, 'InvalidStateError'); + + task.done(); + }); + + audit.run(); + </script> + </body> +</html> |