Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test increasing delay of DelayNode after input finishes</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 signalLength = 100; |
michael@0 | 16 | const bufferSize = 1024; |
michael@0 | 17 | // Delay should be long enough to allow CC to run |
michael@0 | 18 | const delayBufferCount = 50; |
michael@0 | 19 | const delayLength = delayBufferCount * bufferSize + 700; |
michael@0 | 20 | |
michael@0 | 21 | var count = 0; |
michael@0 | 22 | |
michael@0 | 23 | function applySignal(buffer, offset) { |
michael@0 | 24 | for (var i = 0; i < signalLength; ++i) { |
michael@0 | 25 | buffer.getChannelData(0)[offset + i] = Math.cos(Math.PI * i / signalLength); |
michael@0 | 26 | } |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function onAudioProcess(e) { |
michael@0 | 30 | switch(count) { |
michael@0 | 31 | case 5: |
michael@0 | 32 | SpecialPowers.forceGC(); |
michael@0 | 33 | SpecialPowers.forceCC(); |
michael@0 | 34 | break; |
michael@0 | 35 | case delayBufferCount: |
michael@0 | 36 | var offset = delayLength - count * bufferSize; |
michael@0 | 37 | var ctx = e.target.context; |
michael@0 | 38 | var expected = ctx.createBuffer(1, bufferSize, ctx.sampleRate); |
michael@0 | 39 | applySignal(expected, offset); |
michael@0 | 40 | compareBuffers(e.inputBuffer, expected); |
michael@0 | 41 | SimpleTest.finish(); |
michael@0 | 42 | } |
michael@0 | 43 | count++; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | function startTest() { |
michael@0 | 47 | var ctx = new AudioContext(); |
michael@0 | 48 | var processor = ctx.createScriptProcessor(bufferSize, 1, 0); |
michael@0 | 49 | processor.onaudioprocess = onAudioProcess; |
michael@0 | 50 | |
michael@0 | 51 | // Switch on delay at a time in the future. |
michael@0 | 52 | var delayDuration = delayLength / ctx.sampleRate; |
michael@0 | 53 | var delayStartTime = (delayLength - bufferSize) / ctx.sampleRate; |
michael@0 | 54 | var delay = ctx.createDelay(delayDuration); |
michael@0 | 55 | delay.delayTime.setValueAtTime(delayDuration, delayStartTime); |
michael@0 | 56 | delay.connect(processor); |
michael@0 | 57 | |
michael@0 | 58 | // Short signal that finishes before switching to long delay |
michael@0 | 59 | var buffer = ctx.createBuffer(1, signalLength, ctx.sampleRate); |
michael@0 | 60 | applySignal(buffer, 0); |
michael@0 | 61 | var source = ctx.createBufferSource(); |
michael@0 | 62 | source.buffer = buffer; |
michael@0 | 63 | source.start(); |
michael@0 | 64 | source.connect(delay); |
michael@0 | 65 | }; |
michael@0 | 66 | |
michael@0 | 67 | startTest(); |
michael@0 | 68 | </script> |
michael@0 | 69 | </pre> |
michael@0 | 70 | </body> |
michael@0 | 71 | </html> |