content/media/webaudio/test/test_delayNodeChannelChanges.html

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>test DelayNode channel count changes</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="webaudio.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 8 </head>
michael@0 9 <body>
michael@0 10 <pre id="test">
michael@0 11 <script class="testbody" type="text/javascript">
michael@0 12
michael@0 13 SimpleTest.waitForExplicitFinish();
michael@0 14
michael@0 15 const bufferSize = 4096;
michael@0 16
michael@0 17 var ctx;
michael@0 18 var testDelay;
michael@0 19 var stereoDelay;
michael@0 20 var invertor;
michael@0 21
michael@0 22 function compareOutputs(callback) {
michael@0 23 var processor = ctx.createScriptProcessor(bufferSize, 2, 0);
michael@0 24 testDelay.connect(processor);
michael@0 25 invertor.connect(processor);
michael@0 26 processor.onaudioprocess =
michael@0 27 function(e) {
michael@0 28 compareBuffers(e.inputBuffer,
michael@0 29 ctx.createBuffer(2, bufferSize, ctx.sampleRate));
michael@0 30 e.target.onaudioprocess = null;
michael@0 31 callback();
michael@0 32 }
michael@0 33 }
michael@0 34
michael@0 35 function startTest() {
michael@0 36 // And a two-channel signal
michael@0 37 var merger = ctx.createChannelMerger();
michael@0 38 merger.connect(testDelay);
michael@0 39 merger.connect(stereoDelay);
michael@0 40 var oscL = ctx.createOscillator();
michael@0 41 oscL.connect(merger, 0, 0);
michael@0 42 oscL.start(0);
michael@0 43 var oscR = ctx.createOscillator();
michael@0 44 oscR.type = "sawtooth";
michael@0 45 oscR.connect(merger, 0, 1);
michael@0 46 oscR.start(0);
michael@0 47
michael@0 48 compareOutputs(
michael@0 49 function () {
michael@0 50 // Disconnect the two-channel signal and test again
michael@0 51 merger.disconnect();
michael@0 52 compareOutputs(SimpleTest.finish);
michael@0 53 });
michael@0 54 }
michael@0 55
michael@0 56 function prepareTest() {
michael@0 57 ctx = new AudioContext();
michael@0 58
michael@0 59 // The output of a test delay node with mono and stereo input will be
michael@0 60 // compared with that of separate mono and stereo delay nodes.
michael@0 61 const delayTime = 0.3 * bufferSize / ctx.sampleRate;
michael@0 62 testDelay = ctx.createDelay(delayTime);
michael@0 63 testDelay.delayTime.value = delayTime;
michael@0 64 monoDelay = ctx.createDelay(delayTime);
michael@0 65 monoDelay.delayTime.value = delayTime;
michael@0 66 stereoDelay = ctx.createDelay(delayTime);
michael@0 67 stereoDelay.delayTime.value = delayTime;
michael@0 68
michael@0 69 // Create a one-channel signal and connect to the delay nodes
michael@0 70 var monoOsc = ctx.createOscillator();
michael@0 71 monoOsc.frequency.value = 110;
michael@0 72 monoOsc.connect(testDelay);
michael@0 73 monoOsc.connect(monoDelay);
michael@0 74 monoOsc.start(0);
michael@0 75
michael@0 76 // Invert the expected so that mixing with the test will find the difference.
michael@0 77 invertor = ctx.createGain();
michael@0 78 invertor.gain.value = -1.0;
michael@0 79 monoDelay.connect(invertor);
michael@0 80 stereoDelay.connect(invertor);
michael@0 81
michael@0 82 // Start the test after the delay nodes have begun processing.
michael@0 83 var processor = ctx.createScriptProcessor(bufferSize, 1, 0);
michael@0 84 processor.connect(ctx.destination);
michael@0 85
michael@0 86 processor.onaudioprocess =
michael@0 87 function(e) {
michael@0 88 e.target.onaudioprocess = null;
michael@0 89 processor.disconnect();
michael@0 90 startTest();
michael@0 91 };
michael@0 92 }
michael@0 93 prepareTest();
michael@0 94 </script>
michael@0 95 </pre>
michael@0 96 </body>
michael@0 97 </html>

mercurial