diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /dom/media/webaudio/test/test_scriptProcessorNodePassThrough.html | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/webaudio/test/test_scriptProcessorNodePassThrough.html')
-rw-r--r-- | dom/media/webaudio/test/test_scriptProcessorNodePassThrough.html | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/dom/media/webaudio/test/test_scriptProcessorNodePassThrough.html b/dom/media/webaudio/test/test_scriptProcessorNodePassThrough.html new file mode 100644 index 0000000000..5d2d8170e2 --- /dev/null +++ b/dom/media/webaudio/test/test_scriptProcessorNodePassThrough.html @@ -0,0 +1,103 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test ScriptProcessorNode with passthrough</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 testing logic here is sort of complicated, and would +// not be easy to map to OfflineAudioContext, as ScriptProcessorNodes +// can experience delays. + +SimpleTest.waitForExplicitFinish(); +addLoadEvent(function() { + var context = new AudioContext(); + var buffer = null; + + var sourceSP = context.createScriptProcessor(2048); + sourceSP.addEventListener("audioprocess", function(e) { + // generate the audio + for (var i = 0; i < 2048; ++i) { + // Make sure our first sample won't be zero + e.outputBuffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * (i + 1) / context.sampleRate); + e.outputBuffer.getChannelData(1)[i] = Math.sin(880 * 2 * Math.PI * (i + 1) / context.sampleRate); + } + // Remember our generated audio + buffer = e.outputBuffer; + + sourceSP.removeEventListener("audioprocess", arguments.callee); + }); + + function findFirstNonZeroSample(buffer) { + for (var i = 0; i < buffer.length; ++i) { + if (buffer.getChannelData(0)[i] != 0) { + return i; + } + } + return buffer.length; + } + + var sp = context.createScriptProcessor(2048); + sourceSP.connect(sp); + + var spWrapped = SpecialPowers.wrap(sp); + ok("passThrough" in spWrapped, "ScriptProcessorNode should support the passThrough API"); + spWrapped.passThrough = true; + + sp.onaudioprocess = function() { + ok(false, "The audioprocess event must never be dispatched on the passthrough ScriptProcessorNode"); + }; + + var sp2 = context.createScriptProcessor(2048); + sp.connect(sp2); + sp2.connect(context.destination); + + var emptyBuffer = context.createBuffer(1, 2048, context.sampleRate); + + sp2.onaudioprocess = function(e) { + // Because of the initial latency added by the second script processor node, + // we will never see any generated audio frames in the first callback. + compareChannels(e.inputBuffer.getChannelData(0), emptyBuffer.getChannelData(0)); + compareChannels(e.inputBuffer.getChannelData(1), emptyBuffer.getChannelData(0)); + + sp2.onaudioprocess = function(e) { + var firstNonZero = findFirstNonZeroSample(e.inputBuffer); + ok(firstNonZero <= 2048, "First non-zero sample within range"); + + compareChannels(e.inputBuffer.getChannelData(0), emptyBuffer.getChannelData(0), firstNonZero); + compareChannels(e.inputBuffer.getChannelData(1), emptyBuffer.getChannelData(0), firstNonZero); + compareChannels(e.inputBuffer.getChannelData(0), buffer.getChannelData(0), 2048 - firstNonZero, firstNonZero, 0); + compareChannels(e.inputBuffer.getChannelData(1), buffer.getChannelData(1), 2048 - firstNonZero, firstNonZero, 0); + + if (firstNonZero == 0) { + // If we did not experience any delays, the test is done! + sp2.onaudioprocess = null; + + SimpleTest.finish(); + } else if (firstNonZero != 2048) { + // In case we just saw a zero buffer this time, wait one more round + sp2.onaudioprocess = function(e) { + compareChannels(e.inputBuffer.getChannelData(0), buffer.getChannelData(0), firstNonZero, 0, 2048 - firstNonZero); + compareChannels(e.inputBuffer.getChannelData(1), buffer.getChannelData(1), firstNonZero, 0, 2048 - firstNonZero); + compareChannels(e.inputBuffer.getChannelData(0), emptyBuffer.getChannelData(0), undefined, firstNonZero); + compareChannels(e.inputBuffer.getChannelData(1), emptyBuffer.getChannelData(0), undefined, firstNonZero); + + sp2.onaudioprocess = null; + + SimpleTest.finish(); + }; + } + }; + }; +}); + +</script> +</pre> +</body> +</html> |