1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/webaudio/test/test_analyserNode.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <title>Test AnalyserNode</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <script type="text/javascript" src="webaudio.js"></script> 1.10 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.11 +</head> 1.12 +<body> 1.13 +<pre id="test"> 1.14 +<script class="testbody" type="text/javascript"> 1.15 + 1.16 +SimpleTest.waitForExplicitFinish(); 1.17 +addLoadEvent(function() { 1.18 + 1.19 + var context = new AudioContext(); 1.20 + var buffer = context.createBuffer(1, 2048, context.sampleRate); 1.21 + for (var i = 0; i < 2048; ++i) { 1.22 + buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate); 1.23 + } 1.24 + 1.25 + var destination = context.destination; 1.26 + 1.27 + var source = context.createBufferSource(); 1.28 + 1.29 + var analyser = context.createAnalyser(); 1.30 + 1.31 + source.buffer = buffer; 1.32 + 1.33 + source.connect(analyser); 1.34 + analyser.connect(destination); 1.35 + 1.36 + is(analyser.channelCount, 1, "analyser node has 2 input channels by default"); 1.37 + is(analyser.channelCountMode, "explicit", "Correct channelCountMode for the analyser node"); 1.38 + is(analyser.channelInterpretation, "speakers", "Correct channelCountInterpretation for the analyser node"); 1.39 + 1.40 + is(analyser.fftSize, 2048, "Correct default value for fftSize"); 1.41 + is(analyser.frequencyBinCount, 1024, "Correct default value for frequencyBinCount"); 1.42 + expectException(function() { 1.43 + analyser.fftSize = 0; 1.44 + }, DOMException.INDEX_SIZE_ERR); 1.45 + expectException(function() { 1.46 + analyser.fftSize = 1; 1.47 + }, DOMException.INDEX_SIZE_ERR); 1.48 + expectException(function() { 1.49 + analyser.fftSize = 8; 1.50 + }, DOMException.INDEX_SIZE_ERR); 1.51 + expectException(function() { 1.52 + analyser.fftSize = 100; // non-power of two 1.53 + }, DOMException.INDEX_SIZE_ERR); 1.54 + expectException(function() { 1.55 + analyser.fftSize = 2049; 1.56 + }, DOMException.INDEX_SIZE_ERR); 1.57 + expectException(function() { 1.58 + analyser.fftSize = 4096; 1.59 + }, DOMException.INDEX_SIZE_ERR); 1.60 + analyser.fftSize = 1024; 1.61 + is(analyser.frequencyBinCount, 512, "Correct new value for frequencyBinCount"); 1.62 + 1.63 + is(analyser.minDecibels, -100, "Correct default value for minDecibels"); 1.64 + is(analyser.maxDecibels, -30, "Correct default value for maxDecibels"); 1.65 + expectException(function() { 1.66 + analyser.minDecibels = -30; 1.67 + }, DOMException.INDEX_SIZE_ERR); 1.68 + expectException(function() { 1.69 + analyser.minDecibels = -29; 1.70 + }, DOMException.INDEX_SIZE_ERR); 1.71 + expectException(function() { 1.72 + analyser.maxDecibels = -100; 1.73 + }, DOMException.INDEX_SIZE_ERR); 1.74 + expectException(function() { 1.75 + analyser.maxDecibels = -101; 1.76 + }, DOMException.INDEX_SIZE_ERR); 1.77 + 1.78 + is(analyser.smoothingTimeConstant, 0.8, "Correct default value for smoothingTimeConstant"); 1.79 + expectException(function() { 1.80 + analyser.smoothingTimeConstant = -0.1; 1.81 + }, DOMException.INDEX_SIZE_ERR); 1.82 + expectException(function() { 1.83 + analyser.smoothingTimeConstant = 1.1; 1.84 + }, DOMException.INDEX_SIZE_ERR); 1.85 + analyser.smoothingTimeConstant = 0; 1.86 + analyser.smoothingTimeConstant = 1; 1.87 + 1.88 + SimpleTest.finish(); 1.89 +}); 1.90 + 1.91 +</script> 1.92 +</pre> 1.93 +</body> 1.94 +</html>