diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-disconnect.html | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-disconnect.html')
-rw-r--r-- | testing/web-platform/tests/webaudio/the-audio-api/the-channelmergernode-interface/audiochannelmerger-disconnect.html | 82 |
1 files changed, 82 insertions, 0 deletions
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> |