Fri, 16 Jan 2015 04:50:19 +0100
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 AudioBufferSourceNode</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 | // We do not use our generic graph test framework here because |
michael@0 | 14 | // the testing logic here is sort of complicated, and would |
michael@0 | 15 | // not be easy to map to OfflineAudioContext, as ScriptProcessorNodes |
michael@0 | 16 | // can experience delays. |
michael@0 | 17 | |
michael@0 | 18 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 19 | addLoadEvent(function() { |
michael@0 | 20 | var context = new AudioContext(); |
michael@0 | 21 | var buffer = context.createBuffer(6, 2048, context.sampleRate); |
michael@0 | 22 | for (var i = 0; i < 2048; ++i) { |
michael@0 | 23 | for (var j = 0; j < 6; ++j) { |
michael@0 | 24 | buffer.getChannelData(0)[i] = Math.sin(440 * j * Math.PI * i / context.sampleRate); |
michael@0 | 25 | } |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | var monoBuffer = context.createBuffer(1, 2048, context.sampleRate); |
michael@0 | 29 | for (var i = 0; i < 2048; ++i) { |
michael@0 | 30 | monoBuffer.getChannelData(0)[i] = 1; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | var source = context.createBufferSource(); |
michael@0 | 34 | |
michael@0 | 35 | var sp = context.createScriptProcessor(2048, 3); |
michael@0 | 36 | expectException(function() { sp.channelCount = 2; }, |
michael@0 | 37 | DOMException.NOT_SUPPORTED_ERR); |
michael@0 | 38 | sp.channelCountMode = "explicit"; |
michael@0 | 39 | expectException(function() { sp.channelCountMode = "max"; }, |
michael@0 | 40 | DOMException.NOT_SUPPORTED_ERR); |
michael@0 | 41 | expectException(function() { sp.channelCountMode = "clamped-max"; }, |
michael@0 | 42 | DOMException.NOT_SUPPORTED_ERR); |
michael@0 | 43 | sp.channelInterpretation = "discrete"; |
michael@0 | 44 | source.start(0); |
michael@0 | 45 | source.buffer = buffer; |
michael@0 | 46 | source.connect(sp); |
michael@0 | 47 | sp.connect(context.destination); |
michael@0 | 48 | |
michael@0 | 49 | var monoSource = context.createBufferSource(); |
michael@0 | 50 | monoSource.buffer = monoBuffer; |
michael@0 | 51 | monoSource.connect(sp); |
michael@0 | 52 | monoSource.start(2048 / context.sampleRate); |
michael@0 | 53 | |
michael@0 | 54 | sp.onaudioprocess = function(e) { |
michael@0 | 55 | is(e.inputBuffer.numberOfChannels, 3, "Should be correctly down-mixed to three channels"); |
michael@0 | 56 | for (var i = 0; i < 3; ++i) { |
michael@0 | 57 | compareChannels(e.inputBuffer.getChannelData(i), buffer.getChannelData(i)); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | // On the next iteration, we'll get a silence buffer |
michael@0 | 61 | sp.onaudioprocess = function(e) { |
michael@0 | 62 | var emptyBuffer = context.createBuffer(1, 2048, context.sampleRate); |
michael@0 | 63 | is(e.inputBuffer.numberOfChannels, 3, "Should be correctly up-mixed to three channels"); |
michael@0 | 64 | compareChannels(e.inputBuffer.getChannelData(0), monoBuffer.getChannelData(0)); |
michael@0 | 65 | for (var i = 1; i < 3; ++i) { |
michael@0 | 66 | compareChannels(e.inputBuffer.getChannelData(i), emptyBuffer.getChannelData(0)); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | sp.onaudioprocess = null; |
michael@0 | 70 | sp.disconnect(context.destination); |
michael@0 | 71 | |
michael@0 | 72 | SimpleTest.finish(); |
michael@0 | 73 | }; |
michael@0 | 74 | }; |
michael@0 | 75 | }); |
michael@0 | 76 | |
michael@0 | 77 | </script> |
michael@0 | 78 | </pre> |
michael@0 | 79 | </body> |
michael@0 | 80 | </html> |