diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/media/webaudio/test/test_channelSplitterNodeWithVolume.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dom/media/webaudio/test/test_channelSplitterNodeWithVolume.html | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/dom/media/webaudio/test/test_channelSplitterNodeWithVolume.html b/dom/media/webaudio/test/test_channelSplitterNodeWithVolume.html new file mode 100644 index 0000000000..c03f6deeaf --- /dev/null +++ b/dom/media/webaudio/test/test_channelSplitterNodeWithVolume.html @@ -0,0 +1,76 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test ChannelSplitterNode</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <script type="text/javascript" src="webaudio.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> +</head> +<body> +<pre id="test"> +<script class="testbody" type="text/javascript"> + +// We do not use our generic graph test framework here because +// the splitter node is special in that it creates multiple +// output ports. + +SimpleTest.waitForExplicitFinish(); +addLoadEvent(function() { + var context = new AudioContext(); + var buffer = context.createBuffer(4, 2048, context.sampleRate); + var expectedBuffer = context.createBuffer(4, 2048, context.sampleRate); + for (var j = 0; j < 4; ++j) { + for (var i = 0; i < 2048; ++i) { + buffer.getChannelData(j)[i] = Math.sin(440 * 2 * (j + 1) * Math.PI * i / context.sampleRate); + expectedBuffer.getChannelData(j)[i] = buffer.getChannelData(j)[i] / 2; + } + } + var emptyBuffer = context.createBuffer(1, 2048, context.sampleRate); + + var destination = context.destination; + + var source = context.createBufferSource(); + + var splitter = context.createChannelSplitter(); + is(splitter.channelCount, 6, "splitter node has 2 input channels by default"); + is(splitter.channelCountMode, "explicit", "Correct channelCountMode for the splitter node"); + is(splitter.channelInterpretation, "discrete", "Correct channelCountInterpretation for the splitter node"); + + source.buffer = buffer; + var gain = context.createGain(); + gain.gain.value = 0.5; + source.connect(gain); + gain.connect(splitter); + + var channelsSeen = 0; + function createHandler(i) { + return function(e) { + is(e.inputBuffer.numberOfChannels, 1, "Correct input channel count"); + if (i < 4) { + compareBuffers(e.inputBuffer.getChannelData(0), expectedBuffer.getChannelData(i)); + } else { + compareBuffers(e.inputBuffer.getChannelData(0), emptyBuffer.getChannelData(0)); + } + e.target.onaudioprocess = null; + ++channelsSeen; + + if (channelsSeen == 6) { + SimpleTest.finish(); + } + }; + } + + for (var i = 0; i < 6; ++i) { + var sp = context.createScriptProcessor(2048, 1); + splitter.connect(sp, i); + sp.onaudioprocess = createHandler(i); + sp.connect(destination); + } + + source.start(0); +}); + +</script> +</pre> +</body> +</html> |