|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <title>Test AnalyserNode</title> |
|
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
6 <script type="text/javascript" src="webaudio.js"></script> |
|
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
8 </head> |
|
9 <body> |
|
10 <pre id="test"> |
|
11 <script class="testbody" type="text/javascript"> |
|
12 |
|
13 SimpleTest.waitForExplicitFinish(); |
|
14 addLoadEvent(function() { |
|
15 |
|
16 var context = new AudioContext(); |
|
17 var buffer = context.createBuffer(1, 2048, context.sampleRate); |
|
18 for (var i = 0; i < 2048; ++i) { |
|
19 buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate); |
|
20 } |
|
21 |
|
22 var destination = context.destination; |
|
23 |
|
24 var source = context.createBufferSource(); |
|
25 |
|
26 var analyser = context.createAnalyser(); |
|
27 |
|
28 source.buffer = buffer; |
|
29 |
|
30 source.connect(analyser); |
|
31 analyser.connect(destination); |
|
32 |
|
33 is(analyser.channelCount, 1, "analyser node has 2 input channels by default"); |
|
34 is(analyser.channelCountMode, "explicit", "Correct channelCountMode for the analyser node"); |
|
35 is(analyser.channelInterpretation, "speakers", "Correct channelCountInterpretation for the analyser node"); |
|
36 |
|
37 is(analyser.fftSize, 2048, "Correct default value for fftSize"); |
|
38 is(analyser.frequencyBinCount, 1024, "Correct default value for frequencyBinCount"); |
|
39 expectException(function() { |
|
40 analyser.fftSize = 0; |
|
41 }, DOMException.INDEX_SIZE_ERR); |
|
42 expectException(function() { |
|
43 analyser.fftSize = 1; |
|
44 }, DOMException.INDEX_SIZE_ERR); |
|
45 expectException(function() { |
|
46 analyser.fftSize = 8; |
|
47 }, DOMException.INDEX_SIZE_ERR); |
|
48 expectException(function() { |
|
49 analyser.fftSize = 100; // non-power of two |
|
50 }, DOMException.INDEX_SIZE_ERR); |
|
51 expectException(function() { |
|
52 analyser.fftSize = 2049; |
|
53 }, DOMException.INDEX_SIZE_ERR); |
|
54 expectException(function() { |
|
55 analyser.fftSize = 4096; |
|
56 }, DOMException.INDEX_SIZE_ERR); |
|
57 analyser.fftSize = 1024; |
|
58 is(analyser.frequencyBinCount, 512, "Correct new value for frequencyBinCount"); |
|
59 |
|
60 is(analyser.minDecibels, -100, "Correct default value for minDecibels"); |
|
61 is(analyser.maxDecibels, -30, "Correct default value for maxDecibels"); |
|
62 expectException(function() { |
|
63 analyser.minDecibels = -30; |
|
64 }, DOMException.INDEX_SIZE_ERR); |
|
65 expectException(function() { |
|
66 analyser.minDecibels = -29; |
|
67 }, DOMException.INDEX_SIZE_ERR); |
|
68 expectException(function() { |
|
69 analyser.maxDecibels = -100; |
|
70 }, DOMException.INDEX_SIZE_ERR); |
|
71 expectException(function() { |
|
72 analyser.maxDecibels = -101; |
|
73 }, DOMException.INDEX_SIZE_ERR); |
|
74 |
|
75 is(analyser.smoothingTimeConstant, 0.8, "Correct default value for smoothingTimeConstant"); |
|
76 expectException(function() { |
|
77 analyser.smoothingTimeConstant = -0.1; |
|
78 }, DOMException.INDEX_SIZE_ERR); |
|
79 expectException(function() { |
|
80 analyser.smoothingTimeConstant = 1.1; |
|
81 }, DOMException.INDEX_SIZE_ERR); |
|
82 analyser.smoothingTimeConstant = 0; |
|
83 analyser.smoothingTimeConstant = 1; |
|
84 |
|
85 SimpleTest.finish(); |
|
86 }); |
|
87 |
|
88 </script> |
|
89 </pre> |
|
90 </body> |
|
91 </html> |