test_pannerNode.html (2524B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test PannerNode</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 </head> 8 <body> 9 <pre id="test"> 10 <script class="testbody" type="text/javascript"> 11 12 function near(a, b, msg) { 13 ok(Math.abs(a - b) < 1e-4, msg); 14 } 15 16 SimpleTest.waitForExplicitFinish(); 17 addLoadEvent(function() { 18 var context = new AudioContext(); 19 var buffer = context.createBuffer(1, 2048, context.sampleRate); 20 for (var i = 0; i < 2048; ++i) { 21 buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate); 22 } 23 24 var destination = context.destination; 25 26 var source = context.createBufferSource(); 27 28 var panner = new PannerNode(context); 29 30 source.buffer = buffer; 31 32 source.connect(panner); 33 panner.connect(destination); 34 35 // Verify default values 36 is(panner.panningModel, "equalpower", "Correct default value for panning model"); 37 is(panner.distanceModel, "inverse", "Correct default value for distance model"); 38 near(panner.refDistance, 1, "Correct default value for ref distance"); 39 near(panner.maxDistance, 10000, "Correct default value for max distance"); 40 near(panner.rolloffFactor, 1, "Correct default value for rolloff factor"); 41 near(panner.coneInnerAngle, 360, "Correct default value for cone inner angle"); 42 near(panner.coneOuterAngle, 360, "Correct default value for cone outer angle"); 43 near(panner.coneOuterGain, 0, "Correct default value for cone outer gain"); 44 is(panner.channelCount, 2, "panner node has 2 input channels by default"); 45 is(panner.channelCountMode, "clamped-max", "Correct channelCountMode for the panner node"); 46 is(panner.channelInterpretation, "speakers", "Correct channelCountInterpretation for the panner node"); 47 48 panner.setPosition(1, 1, 1); 49 near(panner.positionX.value, 1, "setPosition sets AudioParam properly"); 50 near(panner.positionY.value, 1, "setPosition sets AudioParam properly"); 51 near(panner.positionZ.value, 1, "setPosition sets AudioParam properly"); 52 53 panner.setOrientation(0, 1, 0); 54 near(panner.orientationX.value, 0, "setOrientation sets AudioParam properly"); 55 near(panner.orientationY.value, 1, "setOrientation sets AudioParam properly"); 56 near(panner.orientationZ.value, 0, "setOrientation sets AudioParam properly"); 57 58 source.start(0); 59 SimpleTest.executeSoon(function() { 60 source.stop(0); 61 source.disconnect(); 62 panner.disconnect(); 63 64 SimpleTest.finish(); 65 }); 66 }); 67 68 </script> 69 </pre> 70 </body> 71 </html>