test_dynamicsCompressorNode.html (2353B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test DynamicsCompressorNode</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 20 var osc = context.createOscillator(); 21 var sp = context.createScriptProcessor(); 22 23 var compressor = new DynamicsCompressorNode(context); 24 25 osc.connect(compressor); 26 osc.connect(sp); 27 compressor.connect(context.destination); 28 29 is(compressor.channelCount, 2, "compressor node has 2 input channels by default"); 30 is(compressor.channelCountMode, "clamped-max", "Correct channelCountMode for the compressor node"); 31 is(compressor.channelInterpretation, "speakers", "Correct channelCountInterpretation for the compressor node"); 32 33 // Verify default values 34 ok(compressor.threshold instanceof AudioParam, "treshold is an AudioParam"); 35 near(compressor.threshold.defaultValue, -24, "Correct default value for threshold"); 36 ok(compressor.knee instanceof AudioParam, "knee is an AudioParam"); 37 near(compressor.knee.defaultValue, 30, "Correct default value for knee"); 38 ok(compressor.ratio instanceof AudioParam, "knee is an AudioParam"); 39 near(compressor.ratio.defaultValue, 12, "Correct default value for ratio"); 40 is(typeof compressor.reduction, "number", "reduction is a number"); 41 near(compressor.reduction, 0, "Correct default value for reduction"); 42 ok(compressor.attack instanceof AudioParam, "attack is an AudioParam"); 43 near(compressor.attack.defaultValue, 0.003, "Correct default value for attack"); 44 ok(compressor.release instanceof AudioParam, "release is an AudioParam"); 45 near(compressor.release.defaultValue, 0.25, "Correct default value for release"); 46 47 compressor.threshold.value = -80; 48 49 osc.start(); 50 var iteration = 0; 51 sp.onaudioprocess = function() { 52 if (iteration > 10) { 53 ok(compressor.reduction < 0, 54 "Feeding a full-scale sine to a compressor should result in an db" + 55 "reduction."); 56 sp.onaudioprocess = null; 57 osc.stop(0); 58 59 SimpleTest.finish(); 60 } 61 iteration++; 62 } 63 }); 64 65 </script> 66 </pre> 67 </body> 68 </html>