Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test tail time lifetime of DelayNode indirectly connected to source</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 = 130; |
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 | var delayDuration = delayLength / ctx.sampleRate; |
michael@0 | 52 | var delay = ctx.createDelay(delayDuration); |
michael@0 | 53 | delay.delayTime.value = delayDuration; |
michael@0 | 54 | delay.connect(processor); |
michael@0 | 55 | |
michael@0 | 56 | var gain = ctx.createGain(); |
michael@0 | 57 | gain.connect(delay); |
michael@0 | 58 | |
michael@0 | 59 | // Short signal that finishes before garbage collection |
michael@0 | 60 | var buffer = ctx.createBuffer(1, signalLength, ctx.sampleRate); |
michael@0 | 61 | applySignal(buffer, 0); |
michael@0 | 62 | var source = ctx.createBufferSource(); |
michael@0 | 63 | source.buffer = buffer; |
michael@0 | 64 | source.start(); |
michael@0 | 65 | source.connect(gain); |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | startTest(); |
michael@0 | 69 | </script> |
michael@0 | 70 | </pre> |
michael@0 | 71 | </body> |
michael@0 | 72 | </html> |